Class: AppInfo::Parser::APK
Overview
Parse APK file
Defined Under Namespace
Modules: Device
Instance Attribute Summary collapse
-
#apk ⇒ Object
readonly
Returns the value of attribute apk.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #build_version ⇒ Object
- #bundle_id ⇒ Object (also: #identifier, #package_name)
- #icons ⇒ Object
-
#initialize(file) ⇒ APK
constructor
A new instance of APK.
- #manifest ⇒ Object
- #min_sdk_version ⇒ Object
- #name ⇒ Object
- #os ⇒ Object (also: #device_type)
- #release_version ⇒ Object
- #resource ⇒ Object
- #target_sdk_version ⇒ Object
- #tv? ⇒ Boolean
- #uses_features ⇒ Object
-
#wear? ⇒ Boolean
TODO: find a way to detect def tablet? resource end.
Constructor Details
#initialize(file) ⇒ APK
Returns a new instance of APK.
18 19 20 21 22 23 |
# File 'lib/app_info/parser/apk.rb', line 18 def initialize(file) @file = file Zip.warn_invalid_date = false # fix invaild date format warnings @apk = ::Android::Apk.new(file) end |
Instance Attribute Details
#apk ⇒ Object (readonly)
Returns the value of attribute apk.
8 9 10 |
# File 'lib/app_info/parser/apk.rb', line 8 def apk @apk end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/app_info/parser/apk.rb', line 8 def file @file end |
Instance Method Details
#build_version ⇒ Object
29 30 31 |
# File 'lib/app_info/parser/apk.rb', line 29 def build_version manifest.version_code.to_s end |
#bundle_id ⇒ Object Also known as: identifier, package_name
41 42 43 |
# File 'lib/app_info/parser/apk.rb', line 41 def bundle_id manifest.package_name end |
#icons ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/app_info/parser/apk.rb', line 92 def icons unless @icons tmp_path = File.join(Dir.mktmpdir, "AppInfo-android-#{SecureRandom.hex}") @icons = @apk.icon.each_with_object([]) do |(path, data), obj| icon_name = File.basename(path) icon_path = File.join(tmp_path, File.path(path)) icon_file = File.join(icon_path, icon_name) FileUtils.mkdir_p icon_path File.open(icon_file, 'w') do |f| f.write data end obj << { name: icon_name, file: icon_file, dimensions: ImageSize.path(icon_file).size } end end @icons end |
#manifest ⇒ Object
84 85 86 |
# File 'lib/app_info/parser/apk.rb', line 84 def manifest @apk.manifest end |
#min_sdk_version ⇒ Object
68 69 70 |
# File 'lib/app_info/parser/apk.rb', line 68 def min_sdk_version manifest.min_sdk_ver end |
#name ⇒ Object
37 38 39 |
# File 'lib/app_info/parser/apk.rb', line 37 def name resource.find('@string/app_name') end |
#os ⇒ Object Also known as: device_type
25 26 27 |
# File 'lib/app_info/parser/apk.rb', line 25 def os Parser::Platform::ANDROID end |
#release_version ⇒ Object
33 34 35 |
# File 'lib/app_info/parser/apk.rb', line 33 def release_version manifest.version_name end |
#resource ⇒ Object
88 89 90 |
# File 'lib/app_info/parser/apk.rb', line 88 def resource @apk.resource end |
#target_sdk_version ⇒ Object
72 73 74 |
# File 'lib/app_info/parser/apk.rb', line 72 def target_sdk_version manifest.doc.elements['/manifest/uses-sdk'].attributes['targetSdkVersion'].to_i end |
#tv? ⇒ Boolean
64 65 66 |
# File 'lib/app_info/parser/apk.rb', line 64 def tv? uses_features.include?('android.software.leanback') end |
#uses_features ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/app_info/parser/apk.rb', line 76 def uses_features uses_features = [] manifest.doc.each_element('/manifest/uses-feature') do |elem| uses_features << elem.attributes['name'] end uses_features.uniq end |
#wear? ⇒ Boolean
TODO: find a way to detect def tablet?
resource
end
60 61 62 |
# File 'lib/app_info/parser/apk.rb', line 60 def wear? uses_features.include?('android.hardware.type.watch') end |