Class: AppInfo::APK
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/app_info/apk.rb
Overview
Defined Under Namespace
Modules: Device
Classes: Certificate, Sign
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file) ⇒ APK
Returns a new instance of APK.
22
23
24
|
# File 'lib/app_info/apk.rb', line 22
def initialize(file)
@file = file
end
|
Instance Attribute Details
Returns the value of attribute file.
12
13
14
|
# File 'lib/app_info/apk.rb', line 12
def file
@file
end
|
Instance Method Details
#activities ⇒ Object
104
105
106
|
# File 'lib/app_info/apk.rb', line 104
def activities
components.select { |c| c.type == 'activity' }
end
|
112
113
114
|
# File 'lib/app_info/apk.rb', line 112
def apk
@apk ||= ::Android::Apk.new(@file)
end
|
#certificates ⇒ Object
98
99
100
101
102
|
# File 'lib/app_info/apk.rb', line 98
def certificates
apk.certificates.each_with_object([]) do |(path, certificate), obj|
obj << Certificate.new(path, certificate)
end
end
|
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/app_info/apk.rb', line 132
def clear!
return unless @contents
FileUtils.rm_rf(@contents)
@apk = nil
@contents = nil
@icons = nil
@app_path = nil
@info = nil
end
|
144
145
146
|
# File 'lib/app_info/apk.rb', line 144
def contents
@contents ||= File.join(Dir.mktmpdir, "AppInfo-android-#{SecureRandom.hex}")
end
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/app_info/apk.rb', line 116
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
76
77
78
|
# File 'lib/app_info/apk.rb', line 76
def min_sdk_version
manifest.min_sdk_ver
end
|
49
50
51
|
# File 'lib/app_info/apk.rb', line 49
def name
manifest.label || resource.find('@string/app_name')
end
|
#os ⇒ Object
Also known as:
file_type
108
109
110
|
# File 'lib/app_info/apk.rb', line 108
def services
components.select { |c| c.type == 'service' }
end
|
92
93
94
95
96
|
# File 'lib/app_info/apk.rb', line 92
def signs
apk.signs.each_with_object([]) do |(path, sign), obj|
obj << Sign.new(path, sign)
end
end
|
#size(human_size: false) ⇒ Object
26
27
28
|
# File 'lib/app_info/apk.rb', line 26
def size(human_size: false)
AppInfo::Util.file_size(@file, human_size)
end
|
#target_sdk_version ⇒ Object
81
82
83
84
85
86
|
# File 'lib/app_info/apk.rb', line 81
def target_sdk_version
manifest.doc
.elements['/manifest/uses-sdk']
.attributes['targetSdkVersion']
.to_i
end
|
#tv? ⇒ Boolean
72
73
74
|
# File 'lib/app_info/apk.rb', line 72
def tv?
use_features.include?('android.software.leanback')
end
|
#use_features ⇒ Object
88
89
90
|
# File 'lib/app_info/apk.rb', line 88
def use_features
manifest_values('/manifest/uses-feature')
end
|
#version_code ⇒ Object
Also known as:
build_version
44
45
46
|
# File 'lib/app_info/apk.rb', line 44
def version_code
manifest.version_code.to_s
end
|
#wear? ⇒ Boolean
TODO: find a way to detect def tablet?
resource
end
68
69
70
|
# File 'lib/app_info/apk.rb', line 68
def wear?
use_features.include?('android.hardware.type.watch')
end
|