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.
23
24
25
|
# File 'lib/app_info/apk.rb', line 23
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
104
105
106
|
# File 'lib/app_info/apk.rb', line 104
def activities
components.select { |c| c.type == 'activity' }
end
|
112
113
114
115
116
|
# File 'lib/app_info/apk.rb', line 112
def apk
Zip.warn_invalid_date = false
@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
|
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/app_info/apk.rb', line 138
def clear!
return unless @contents
FileUtils.rm_rf(@contents)
@apk = nil
@contents = nil
@icons = nil
@app_path = nil
@info = nil
end
|
150
151
152
|
# File 'lib/app_info/apk.rb', line 150
def contents
@contents ||= File.join(Dir.mktmpdir, "AppInfo-android-#{SecureRandom.hex}")
end
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/app_info/apk.rb', line 118
def icons
unless @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.open(icon_file, 'wb') { |f| f.write(data) }
obj << {
name: icon_name,
file: icon_file,
dimensions: ImageSize.path(icon_file).size
}
end
end
@icons
end
|
#min_sdk_version ⇒ Object
77
78
79
|
# File 'lib/app_info/apk.rb', line 77
def min_sdk_version
manifest.min_sdk_ver
end
|
50
51
52
|
# File 'lib/app_info/apk.rb', line 50
def name
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(humanable = false) ⇒ Object
27
28
29
|
# File 'lib/app_info/apk.rb', line 27
def size(humanable = false)
AppInfo::Util.file_size(@file, humanable)
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
73
74
75
|
# File 'lib/app_info/apk.rb', line 73
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
45
46
47
|
# File 'lib/app_info/apk.rb', line 45
def version_code
manifest.version_code.to_s
end
|
#wear? ⇒ Boolean
TODO: find a way to detect def tablet?
resource
end
69
70
71
|
# File 'lib/app_info/apk.rb', line 69
def wear?
use_features.include?('android.hardware.type.watch')
end
|