class Android::Manifest

parsed AndroidManifest.xml class @see developer.android.com/guide/topics/manifest/manifest-intro.html

Constants

APPLICATION_TAG

Attributes

doc[R]

Manifest class definitions

@return [REXML::Document] manifest xml

Public Class Methods

new(data, rsc=nil) click to toggle source

@param [String] data binary data of AndroidManifest.xml

# File lib/android/manifest.rb, line 333
def initialize(data, rsc=nil)
  parser = AXMLParser.new(data)
  @doc = parser.parse
  @rsc = rsc
end

Public Instance Methods

activities() click to toggle source

@return [Array<Android::Manifest::Activity&ActivityAlias>] all activities in the apk @note return empty array when the manifest include no activities

# File lib/android/manifest.rb, line 375
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() click to toggle source

Returns the manifest’s application element or nil, if there isn’t any. @return [Android::Manifest::Application] the manifest’s application element

# File lib/android/manifest.rb, line 356
def application
  element = @doc.elements['//application']
  Application.new(element) if Application.valid?(element)
end
components() click to toggle source

@return [Array<Android::Manifest::Component>] all components in apk @note return empty array when the manifest include no components

# File lib/android/manifest.rb, line 363
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
label(lang=nil) click to toggle source

application label @param [String] lang language code like ‘ja’, ‘cn’, … @return [String] application label string(if resouce is provided), or label resource id @return [nil] when label is not found @since 0.5.1

# File lib/android/manifest.rb, line 478
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() click to toggle source

@return [Array<Android::Manifest::Activity&ActivityAlias>] all activities that are launchers in the apk @note return empty array when the manifest include no activities

# File lib/android/manifest.rb, line 428
def launcher_activities
  activities.select(&:launcher_activity?)
end
min_sdk_ver() click to toggle source

@return [Integer] minSdkVersion in uses element

# File lib/android/manifest.rb, line 459
def min_sdk_ver
  @doc.elements['/manifest/uses-sdk']
      .attributes['minSdkVersion']
      .to_i
end
package_name() click to toggle source

application package name @return [String]

# File lib/android/manifest.rb, line 434
def package_name
  @doc.root.attributes['package']
end
schemes() click to toggle source

@return [Array<String>] all schemes in intent filters @note return empty array when the manifest not include http or https scheme(s) of data @since 2.5.0

# File lib/android/manifest.rb, line 413
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() click to toggle source

@return [Array<Android::Manifest::Component>] all services in the apk @note return empty array when the manifest include no services @since 2.5.0

# File lib/android/manifest.rb, line 390
def services
  components.select { |c| c.type == 'service' }
end
target_sdk_version() click to toggle source

@return [Integer] targetSdkVersion in uses element @since 2.5.0

# File lib/android/manifest.rb, line 467
def target_sdk_version
  @doc.elements['/manifest/uses-sdk']
      .attributes['targetSdkVersion']
      .to_i
end
to_xml(indent=4) click to toggle source

return xml as string format @param [Integer] indent size(bytes) @return [String] raw xml string

# File lib/android/manifest.rb, line 499
def to_xml(indent=4)
  xml =''
  formatter = REXML::Formatters::Pretty.new(indent)
  formatter.write(@doc.root, xml)
  xml
end
use_features() click to toggle source

used features array @return [Array<String>] features names @note return empty array when the manifest includes no use-features element @since 2.5.0

# File lib/android/manifest.rb, line 350
def use_features
  manifest_values('/manifest/uses-feature')
end
use_permissions() click to toggle source

used permission array @return [Array<String>] permission names @note return empty array when the manifest includes no use-parmission element

# File lib/android/manifest.rb, line 342
def use_permissions
  manifest_values('/manifest/uses-permission')
end
version_code() click to toggle source

application version code @return [Integer]

# File lib/android/manifest.rb, line 440
def version_code
  @doc.root.attributes['versionCode'].to_i
end
version_name(lang=nil) click to toggle source

application version name @return [String]

# File lib/android/manifest.rb, line 446
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

Private Instance Methods

manifest_values(path, key = 'name') click to toggle source
# File lib/android/manifest.rb, line 508
def manifest_values(path, key = 'name')
  values = []
  @doc.each_element(path) do |elem|
    values << elem.attributes[key]
  end
  values.uniq
end