Class: AppInfo::AAB
Overview
Defined Under Namespace
Modules: Device
Constant Summary
collapse
- BASE_PATH =
'base'
- BASE_MANIFEST =
"#{BASE_PATH}/manifest/AndroidManifest.xml"
- BASE_RESOURCES =
"#{BASE_PATH}/resources.pb"
Helper::HumanFileSize::FILE_SIZE_UNITS
Instance Attribute Summary collapse
Instance Method Summary
collapse
#file_to_human_size, #number_to_human_size
Constructor Details
#initialize(file) ⇒ AAB
Returns a new instance of AAB.
28
29
30
|
# File 'lib/app_info/aab.rb', line 28
def initialize(file)
@file = file
end
|
Instance Attribute Details
Returns the value of attribute file.
13
14
15
|
# File 'lib/app_info/aab.rb', line 13
def file
@file
end
|
Instance Method Details
#activities ⇒ Object
114
115
116
|
# File 'lib/app_info/aab.rb', line 114
def activities
@activities ||= manifest.activities
end
|
#automotive? ⇒ Boolean
89
90
91
|
# File 'lib/app_info/aab.rb', line 89
def automotive?
use_features&.include?('android.hardware.type.automotive')
end
|
#certificates ⇒ Object
152
153
154
155
156
|
# File 'lib/app_info/aab.rb', line 152
def certificates
@certificates ||= signs.each_with_object([]) do |sign, obj|
obj << APK::Certificate.new(sign.path, sign.sign.certificates[0])
end
end
|
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/app_info/aab.rb', line 213
def clear!
return unless @contents
FileUtils.rm_rf(@contents)
@aab = nil
@contents = nil
@icons = nil
@app_path = nil
@info = nil
end
|
#components ⇒ Object
122
123
124
|
# File 'lib/app_info/aab.rb', line 122
def components
@components ||= manifest.components.transform_values
end
|
225
226
227
|
# File 'lib/app_info/aab.rb', line 225
def contents
@contents ||= File.join(Dir.mktmpdir, "AppInfo-android-#{SecureRandom.hex}")
end
|
#device_type ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/app_info/aab.rb', line 60
def device_type
if wear?
Device::WATCH
elsif tv?
Device::TV
elsif automotive?
Device::AUTOMOTIVE
else
Device::PHONE
end
end
|
#each_file ⇒ Object
158
159
160
161
162
163
164
|
# File 'lib/app_info/aab.rb', line 158
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
173
174
175
176
177
178
|
# File 'lib/app_info/aab.rb', line 173
def entry(name, base_path: BASE_PATH)
entry = @zip.find_entry(File.join(base_path, name))
raise NotFoundError, "'#{name}'" if entry.nil?
entry
end
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/app_info/aab.rb', line 194
def icons
@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
end
|
180
181
182
183
|
# File 'lib/app_info/aab.rb', line 180
def manifest
io = zip.read(zip.find_entry(BASE_MANIFEST))
@manifest ||= Protobuf::Manifest.parse(io, resource)
end
|
#min_sdk_version ⇒ Object
Also known as:
min_os_version
93
94
95
|
# File 'lib/app_info/aab.rb', line 93
def min_sdk_version
manifest.uses_sdk.min_sdk_version
end
|
56
57
58
|
# File 'lib/app_info/aab.rb', line 56
def name
manifest.label
end
|
#os ⇒ Object
Also known as:
file_type
36
37
38
|
# File 'lib/app_info/aab.rb', line 36
def os
Platform::ANDROID
end
|
#package_name ⇒ Object
Also known as:
identifier, bundle_id
45
46
47
|
# File 'lib/app_info/aab.rb', line 45
def package_name
manifest.package
end
|
#read_file(name, base_path: BASE_PATH) ⇒ Object
166
167
168
169
170
171
|
# File 'lib/app_info/aab.rb', line 166
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
|
185
186
187
188
|
# File 'lib/app_info/aab.rb', line 185
def resource
io = zip.read(zip.find_entry(BASE_RESOURCES))
@resource ||= Protobuf::Resources.parse(io)
end
|
118
119
120
|
# File 'lib/app_info/aab.rb', line 118
def services
@services ||= manifest.services
end
|
#sign_version ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/app_info/aab.rb', line 126
def sign_version
return 'v1' unless signs.empty?
'unknown'
end
|
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/app_info/aab.rb', line 138
def signs
return @signs if @signs
@signs = []
each_file do |path, data|
next unless path =~ %r{^META-INF/} && data.unpack('CC') == [0x30, 0x82]
@signs << APK::Sign.new(path, OpenSSL::PKCS7.new(data))
end
@signs
end
|
#size(human_size: false) ⇒ Object
32
33
34
|
# File 'lib/app_info/aab.rb', line 32
def size(human_size: false)
file_to_human_size(@file, human_size: human_size)
end
|
#target_sdk_version ⇒ Object
98
99
100
|
# File 'lib/app_info/aab.rb', line 98
def target_sdk_version
manifest.uses_sdk.target_sdk_version
end
|
#tv? ⇒ Boolean
85
86
87
|
# File 'lib/app_info/aab.rb', line 85
def tv?
use_features&.include?('android.software.leanback')
end
|
#use_features ⇒ Object
102
103
104
105
106
|
# File 'lib/app_info/aab.rb', line 102
def use_features
return [] unless manifest.respond_to?(:uses_feature)
@use_features ||= manifest&.uses_feature&.map(&:name)
end
|
#use_permissions ⇒ Object
108
109
110
111
112
|
# File 'lib/app_info/aab.rb', line 108
def use_permissions
return [] unless manifest.respond_to?(:uses_permission)
@use_permissions ||= manifest&.uses_permission&.map(&:name)
end
|
#version_code ⇒ Object
Also known as:
build_version
51
52
53
|
# File 'lib/app_info/aab.rb', line 51
def version_code
manifest.version_code.to_s
end
|
#wear? ⇒ Boolean
81
82
83
|
# File 'lib/app_info/aab.rb', line 81
def wear?
use_features&.include?('android.hardware.type.watch')
end
|
190
191
192
|
# File 'lib/app_info/aab.rb', line 190
def zip
@zip ||= Zip::File.open(@file)
end
|