Class: AppInfo::AAB

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

Overview

Parse APK file parser

Constant Summary collapse

BASE_PATH =
'base'
BASE_MANIFEST =
"#{BASE_PATH}/manifest/AndroidManifest.xml"
BASE_RESOURCES =
"#{BASE_PATH}/resources.pb"

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

#activitiesProtobuf::Node

Returns:



69
70
71
# File 'lib/app_info/aab.rb', line 69

def activities
  @activities ||= manifest.activities
end

#clear!Object



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/app_info/aab.rb', line 174

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

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

#componentsProtobuf::Node

Returns:



79
80
81
# File 'lib/app_info/aab.rb', line 79

def components
  @components ||= manifest.components.transform_values
end

Returns:

  • (String)

See Also:



21
# File 'lib/app_info/aab.rb', line 21

def_delegators :manifest, :version_name, :deep_links, :schemes

#each_fileObject



83
84
85
86
87
88
89
# File 'lib/app_info/aab.rb', line 83

def each_file
  zip.each do |entry|
    next unless entry.file?

    yield entry.name, @zip.read(entry)
  end
end

#entry(name, base_path: BASE_PATH) ⇒ Object

Raises:



98
99
100
101
102
103
# File 'lib/app_info/aab.rb', line 98

def entry(name, base_path: BASE_PATH)
  entry = @zip.find_entry(::File.join(base_path, name))
  raise NotFoundError, "'#{name}'" if entry.nil?

  entry
end

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

Full icons metadata

Examples:

full icons

aab.icons
# => [
#   {
#     name: 'ic_launcher.png',
#     file: '/path/to/ic_launcher.webp',
#     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

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

Parameters:

  • filter (String, Symbol, Array<Symbol, Array>)

    filter file extension name

Returns:

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

    icons paths of icons



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/app_info/aab.rb', line 153

def icons(exclude: nil)
  @icons ||= manifest.icons.each_with_object([]) do |res, obj|
    path = res.value
    filename = ::File.basename(path)
    filepath = ::File.join(contents, ::File.dirname(path))
    file = ::File.join(filepath, filename)
    FileUtils.mkdir_p(filepath)

    binary_data = read_file(path)
    ::File.write(file, binary_data, encoding: Encoding::BINARY)

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

  extract_icon(@icons, exclude: exclude)
end

#manifestProtobuf::Manifest

Returns:



106
107
108
109
# File 'lib/app_info/aab.rb', line 106

def manifest
  io = zip.read(zip.find_entry(BASE_MANIFEST))
  @manifest ||= Protobuf::Manifest.parse(io, resource)
end

#min_sdk_versionString Also known as: min_os_version

Returns:

  • (String)


44
45
46
# File 'lib/app_info/aab.rb', line 44

def min_sdk_version
  manifest.uses_sdk.min_sdk_version
end

#nameString

Returns:

  • (String)


39
40
41
# File 'lib/app_info/aab.rb', line 39

def name
  manifest.label
end

#package_nameString Also known as: identifier, bundle_id

Returns:

  • (String)


26
27
28
# File 'lib/app_info/aab.rb', line 26

def package_name
  manifest.package
end

#read_file(name, base_path: BASE_PATH) ⇒ Object



91
92
93
94
95
96
# File 'lib/app_info/aab.rb', line 91

def read_file(name, base_path: BASE_PATH)
  content = @zip.read(entry(name, base_path: base_path))
  return parse_binary_xml(content) if xml_file?(name)

  content
end

#resourceProtobuf::Resources

Returns:



112
113
114
115
# File 'lib/app_info/aab.rb', line 112

def resource
  io = zip.read(zip.find_entry(BASE_RESOURCES))
  @resource ||= Protobuf::Resources.parse(io)
end

#schemesString

Returns:

  • (String)

See Also:



21
# File 'lib/app_info/aab.rb', line 21

def_delegators :manifest, :version_name, :deep_links, :schemes

#servicesProtobuf::Node

Returns:



74
75
76
# File 'lib/app_info/aab.rb', line 74

def services
  @services ||= manifest.services
end

#target_sdk_versionString

Returns:

  • (String)


50
51
52
# File 'lib/app_info/aab.rb', line 50

def target_sdk_version
  manifest.uses_sdk.target_sdk_version
end

#use_featuresArray<String>

Returns:

  • (Array<String>)


55
56
57
58
59
# File 'lib/app_info/aab.rb', line 55

def use_features
  return [] unless manifest.respond_to?(:uses_feature)

  @use_features ||= manifest&.uses_feature&.map(&:name)
end

#use_permissionsArray<String>

Returns:

  • (Array<String>)


62
63
64
65
66
# File 'lib/app_info/aab.rb', line 62

def use_permissions
  return [] unless manifest.respond_to?(:uses_permission)

  @use_permissions ||= manifest&.uses_permission&.map(&:name)
end

#version_codeString Also known as: build_version

Returns:

  • (String)


33
34
35
# File 'lib/app_info/aab.rb', line 33

def version_code
  manifest.version_code.to_s
end

#version_nameString Also known as: release_version

Returns:

  • (String)

See Also:

  • Protobuf::Manifest#version_name


21
# File 'lib/app_info/aab.rb', line 21

def_delegators :manifest, :version_name, :deep_links, :schemes

#zipZip::File

Returns:

  • (Zip::File)


187
188
189
# File 'lib/app_info/aab.rb', line 187

def zip
  @zip ||= Zip::File.open(@file)
end