Class: Android::Manifest
- Inherits:
-
Object
- Object
- Android::Manifest
- Defined in:
- lib/android/manifest.rb
Overview
parsed AndroidManifest.xml class
Defined Under Namespace
Classes: Activity, ActivityAlias, Application, Component, IntentFilter, Meta, Provider, Queries, QueriesComponent, Receiver, Service
Constant Summary collapse
- APPLICATION_TAG =
'/manifest/application'
Instance Attribute Summary collapse
-
#doc ⇒ REXML::Document
readonly
Manifest xml.
Instance Method Summary collapse
-
#activities ⇒ Array<Android::Manifest::Activity&ActivityAlias>
All activities in the apk.
-
#application ⇒ Android::Manifest::Application
Returns the manifest’s application element or nil, if there isn’t any.
-
#components ⇒ Array<Android::Manifest::Component>
All components in apk.
-
#deep_links ⇒ Array<String>
All deep link host and schemes in intent filters.
-
#initialize(data, rsc = nil) ⇒ Manifest
constructor
A new instance of Manifest.
-
#label(lang = nil) ⇒ String?
application label.
-
#launcher_activities ⇒ Array<Android::Manifest::Activity&ActivityAlias>
All activities that are launchers in the apk.
-
#min_sdk_ver ⇒ Integer
MinSdkVersion in uses element.
-
#package_name ⇒ String
application package name.
-
#queries ⇒ Android::Manifest::Queries
Returns the manifest’s queries element or nil, if there isn’t any.
-
#schemes ⇒ Array<String>
All schemes in intent filters.
-
#services ⇒ Array<Android::Manifest::Component>
All services in the apk.
-
#target_sdk_version ⇒ Integer
TargetSdkVersion in uses element.
-
#to_xml(indent = 4) ⇒ String
return xml as string format.
-
#use_features ⇒ Array<String>
used features array.
-
#use_permissions ⇒ Array<String>
used permission array.
-
#version_code ⇒ Integer
application version code.
-
#version_name(lang = nil) ⇒ String
application version name.
Constructor Details
#initialize(data, rsc = nil) ⇒ Manifest
Returns a new instance of Manifest.
426 427 428 429 430 |
# File 'lib/android/manifest.rb', line 426 def initialize(data, rsc=nil) parser = AXMLParser.new(data) @doc = parser.parse @rsc = rsc end |
Instance Attribute Details
#doc ⇒ REXML::Document (readonly)
Returns manifest xml.
423 424 425 |
# File 'lib/android/manifest.rb', line 423 def doc @doc end |
Instance Method Details
#activities ⇒ Array<Android::Manifest::Activity&ActivityAlias>
return empty array when the manifest include no activities
Returns all activities in the apk.
475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/android/manifest.rb', line 475 def activities activities = [] unless @doc.elements['/manifest/application'].nil? @doc.elements['/manifest/application'].each do |elem| next unless Activity.valid?(elem) activities << (elem.name == 'activity-alias' ? ActivityAlias.new(elem) : Activity.new(elem)) end end activities end |
#application ⇒ Android::Manifest::Application
Returns the manifest’s application element or nil, if there isn’t any.
449 450 451 452 |
# File 'lib/android/manifest.rb', line 449 def application element = @doc.elements['//application'] Application.new(element) if Application.valid?(element) end |
#components ⇒ Array<Android::Manifest::Component>
return empty array when the manifest include no components
Returns all components in apk.
456 457 458 459 460 461 462 463 464 |
# File 'lib/android/manifest.rb', line 456 def components components = [] unless @doc.elements['/manifest/application'].nil? @doc.elements['/manifest/application'].each do |elem| components << Component.new(elem) if Component.valid?(elem) end end components end |
#deep_links ⇒ Array<String>
return empty array when the manifest include no http or https scheme of data
Returns all deep link host and schemes in intent filters.
497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/android/manifest.rb', line 497 def deep_links activities.each_with_object([]) do |activity, obj| intent_filters = activity.intent_filters next if intent_filters.empty? intent_filters.each do |filter| next unless filter.deep_links? obj << filter.deep_links end end.flatten.uniq end |
#label(lang = nil) ⇒ String?
application label
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/android/manifest.rb', line 578 def label(lang=nil) label = @doc.elements['/manifest/application'].attributes['label'] if label.nil? # application element has no label attributes. # so looking for activites that has label attribute. activities = @doc.elements['/manifest/application'].find{ |e| e.name == 'activity' && !e.attributes['label'].nil? } label = activities.nil? ? nil : activities.first.attributes['label'] end unless @rsc.nil? if /^@(\w+\/\w+)|(0x[0-9a-fA-F]{8})$/ =~ label opts = {} opts[:lang] = lang unless lang.nil? label = @rsc.find(label, opts) end end label end |
#launcher_activities ⇒ Array<Android::Manifest::Activity&ActivityAlias>
return empty array when the manifest include no activities
Returns all activities that are launchers in the apk.
528 529 530 |
# File 'lib/android/manifest.rb', line 528 def launcher_activities activities.select(&:launcher_activity?) end |
#min_sdk_ver ⇒ Integer
Returns minSdkVersion in uses element.
559 560 561 562 563 |
# File 'lib/android/manifest.rb', line 559 def min_sdk_ver @doc.elements['/manifest/uses-sdk'] .attributes['minSdkVersion'] .to_i end |
#package_name ⇒ String
application package name
534 535 536 |
# File 'lib/android/manifest.rb', line 534 def package_name @doc.root.attributes['package'] end |
#queries ⇒ Android::Manifest::Queries
Returns the manifest’s queries element or nil, if there isn’t any.
468 469 470 471 |
# File 'lib/android/manifest.rb', line 468 def queries element = @doc.elements['/manifest/queries'] Queries.new(element) if Queries.valid?(element) end |
#schemes ⇒ Array<String>
return empty array when the manifest not include http or https scheme(s) of data
Returns all schemes in intent filters.
513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/android/manifest.rb', line 513 def schemes activities.each_with_object([]) do |activity, obj| intent_filters = activity.intent_filters next if intent_filters.empty? intent_filters.each do |filter| next unless filter.schemes? obj << filter.schemes end end.flatten.uniq end |
#services ⇒ Array<Android::Manifest::Component>
return empty array when the manifest include no services
Returns all services in the apk.
490 491 492 |
# File 'lib/android/manifest.rb', line 490 def services components.select { |c| c.type == 'service' } end |
#target_sdk_version ⇒ Integer
Returns targetSdkVersion in uses element.
567 568 569 570 571 |
# File 'lib/android/manifest.rb', line 567 def target_sdk_version @doc.elements['/manifest/uses-sdk'] .attributes['targetSdkVersion'] .to_i end |
#to_xml(indent = 4) ⇒ String
return xml as string format
599 600 601 602 603 604 |
# File 'lib/android/manifest.rb', line 599 def to_xml(indent=4) xml ='' formatter = REXML::Formatters::Pretty.new(indent) formatter.write(@doc.root, xml) xml end |
#use_features ⇒ Array<String>
return empty array when the manifest includes no use-features element
used features array
443 444 445 |
# File 'lib/android/manifest.rb', line 443 def use_features manifest_values('/manifest/uses-feature') end |
#use_permissions ⇒ Array<String>
return empty array when the manifest includes no use-parmission element
used permission array
435 436 437 |
# File 'lib/android/manifest.rb', line 435 def manifest_values('/manifest/uses-permission') end |
#version_code ⇒ Integer
application version code
540 541 542 |
# File 'lib/android/manifest.rb', line 540 def version_code @doc.root.attributes['versionCode'].to_i end |
#version_name(lang = nil) ⇒ String
application version name
546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/android/manifest.rb', line 546 def version_name(lang=nil) vername = @doc.root.attributes['versionName'] unless @rsc.nil? if /^@(\w+\/\w+)|(0x[0-9a-fA-F]{8})$/ =~ vername opts = {} opts[:lang] = lang unless lang.nil? vername = @rsc.find(vername, opts) end end vername end |