Class: AppInfo::APK

Inherits:
Android show all
Defined in:
lib/app_info/apk.rb

Overview

Parse APK file parser, wrapper for android_parser.

Constant Summary

Constants included from Helper::HumanFileSize

Helper::HumanFileSize::FILE_SIZE_UNITS

Instance Attribute Summary

Attributes inherited from File

#file, #logger

Instance Method Summary collapse

Methods inherited from Android

#automotive?, #certificates, #contents, #device, #manufacturer, #platform, #signatures, #signs, #size, #tablet?, #television?, #watch?

Methods included from Helper::HumanFileSize

#file_to_human_size, #number_to_human_size

Methods inherited from File

#device, #format, #initialize, #manufacturer, #not_implemented_error!, #platform, #size

Constructor Details

This class inherits a constructor from AppInfo::File

Instance Method Details

#activitiesString

Returns:

  • (String)


58
59
60
# File 'lib/app_info/apk.rb', line 58

def activities
  components.select { |c| c.type == 'activity' }
end

#apk::Android::Apk

Returns:

  • (::Android::Apk)


63
64
65
# File 'lib/app_info/apk.rb', line 63

def apk
  @apk ||= ::Android::Apk.new(@file)
end

#clear!Object



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/app_info/apk.rb', line 126

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

  @apk = nil
  @contents = nil
  @icons = nil
  @app_path = nil
  @info = nil
end

#componentsObject



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes


34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#dexObject

See Also:



14
# File 'lib/app_info/apk.rb', line 14

def_delegators :apk, :manifest, :resource, :dex

#icons(exclude: nil) ⇒ Array<Hash{Symbol => String, Array<Integer>}>

Full icons metadata

Examples:

full icons

apk.icons
# => [
#   {
#     name: 'ic_launcher.png',
#     file: '/path/to/ic_launcher.png',
#     dimensions: [29, 29]
#   },
#   {
#     name: 'ic_launcher.png',
#     file: '/path/to/ic_launcher.png',
#     dimensions: [120, 120]
#   },
#   {
#     name: 'ic_launcher.xml',
#     file: '/path/to/ic_launcher.xml',
#     dimensions: [nil, nil]
#   },
# ]

exclude xml icons

apk.icons(exclude: :xml)
# => [
#   {
#     name: 'ic_launcher.png',
#     file: '/path/to/ic_launcher.png',
#     dimensions: [29, 29]
#   },
#   {
#     name: 'ic_launcher.png',
#     file: '/path/to/ic_launcher.png',
#     dimensions: [120, 120]
#   }
# ]

Parameters:

  • xml (Boolean)

    return xml icons

Returns:

  • (Array<Hash{Symbol => String, Array<Integer>}>)

    icons paths of icons



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/app_info/apk.rb', line 108

def icons(exclude: nil)
  @icons ||= apk.icon.each_with_object([]) do |(path, data), obj|
    icon_name = ::File.basename(path)
    icon_path = ::File.join(contents, ::File.dirname(path))
    icon_file = ::File.join(icon_path, icon_name)
    FileUtils.mkdir_p icon_path
    ::File.write(icon_file, data, encoding: Encoding::BINARY)

    obj << {
      name: icon_name,
      file: icon_file,
      dimensions: ImageSize.path(icon_file).size
    }
  end

  extract_icon(@icons, exclude: exclude)
end

#manifestObject



14
# File 'lib/app_info/apk.rb', line 14

def_delegators :apk, :manifest, :resource, :dex

#min_sdk_versionString Also known as: min_os_version

Returns:

  • (String)


52
53
54
# File 'lib/app_info/apk.rb', line 52

def min_sdk_version
  manifest.min_sdk_ver
end

#nameObject



47
48
49
# File 'lib/app_info/apk.rb', line 47

def name
  manifest.label || resource.find('@string/app_name')
end

#package_nameObject Also known as: identifier, bundle_id



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#resourceObject



14
# File 'lib/app_info/apk.rb', line 14

def_delegators :apk, :manifest, :resource, :dex

#schemesObject



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#servicesObject



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#target_sdk_versionxObject



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#use_featuresObject



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#use_permissionsObject



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#version_codeObject Also known as: build_version



42
43
44
# File 'lib/app_info/apk.rb', line 42

def version_code
  manifest.version_code.to_s
end

#version_nameObject Also known as: release_version



34
35
36
# File 'lib/app_info/apk.rb', line 34

def_delegators :manifest, :version_name, :package_name, :target_sdk_version,
:components, :services, :use_permissions, :use_features,
:deep_links, :schemes

#zipZip::File

Returns:

  • (Zip::File)


68
69
70
# File 'lib/app_info/apk.rb', line 68

def zip
  @zip ||= apk.instance_variable_get(:@zip)
end