Class: AppInfo::APK
Overview
Defined Under Namespace
Modules: Device
Classes: Certificate, Sign
Constant Summary
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) ⇒ APK
Returns a new instance of APK.
24
25
26
|
# File 'lib/app_info/apk.rb', line 24
def initialize(file)
@file = file
end
|
Instance Attribute Details
Returns the value of attribute file.
13
14
15
|
# File 'lib/app_info/apk.rb', line 13
def file
@file
end
|
Instance Method Details
#activities ⇒ Object
113
114
115
|
# File 'lib/app_info/apk.rb', line 113
def activities
components.select { |c| c.type == 'activity' }
end
|
117
118
119
|
# File 'lib/app_info/apk.rb', line 117
def apk
@apk ||= ::Android::Apk.new(@file)
end
|
#automotive? ⇒ Boolean
80
81
82
|
# File 'lib/app_info/apk.rb', line 80
def automotive?
use_features.include?('android.hardware.type.automotive')
end
|
#certificates ⇒ Object
107
108
109
110
111
|
# File 'lib/app_info/apk.rb', line 107
def certificates
apk.certificates.each_with_object([]) do |(path, certificate), obj|
obj << Certificate.new(path, certificate)
end
end
|
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/app_info/apk.rb', line 137
def clear!
return unless @contents
FileUtils.rm_rf(@contents)
@apk = nil
@contents = nil
@icons = nil
@app_path = nil
@info = nil
end
|
149
150
151
|
# File 'lib/app_info/apk.rb', line 149
def contents
@contents ||= File.join(Dir.mktmpdir, "AppInfo-android-#{SecureRandom.hex}")
end
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/app_info/apk.rb', line 121
def icons
@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
end
|
#min_sdk_version ⇒ Object
Also known as:
min_os_version
84
85
86
|
# File 'lib/app_info/apk.rb', line 84
def min_sdk_version
manifest.min_sdk_ver
end
|
52
53
54
|
# File 'lib/app_info/apk.rb', line 52
def name
manifest.label || resource.find('@string/app_name')
end
|
#os ⇒ Object
Also known as:
file_type
32
33
34
|
# File 'lib/app_info/apk.rb', line 32
def os
Platform::ANDROID
end
|
#sign_version ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/app_info/apk.rb', line 89
def sign_version
return 'v1' unless signs.empty?
'unknown'
end
|
101
102
103
104
105
|
# File 'lib/app_info/apk.rb', line 101
def signs
apk.signs.each_with_object([]) do |(path, sign), obj|
obj << Sign.new(path, sign)
end
end
|
#size(human_size: false) ⇒ Object
28
29
30
|
# File 'lib/app_info/apk.rb', line 28
def size(human_size: false)
file_to_human_size(@file, human_size: human_size)
end
|
#tv? ⇒ Boolean
76
77
78
|
# File 'lib/app_info/apk.rb', line 76
def tv?
use_features.include?('android.software.leanback')
end
|
#version_code ⇒ Object
Also known as:
build_version
47
48
49
|
# File 'lib/app_info/apk.rb', line 47
def version_code
manifest.version_code.to_s
end
|
#wear? ⇒ Boolean
TODO: find a way to detect, no way! def tablet? end
72
73
74
|
# File 'lib/app_info/apk.rb', line 72
def wear?
use_features.include?('android.hardware.type.watch')
end
|