lib/app_info/parser/apk.rb in app-info-1.0.5 vs lib/app_info/parser/apk.rb in app-info-1.1.0

- old
+ new

@@ -20,10 +20,14 @@ Zip.warn_invalid_date = false # fix invaild date format warnings @apk = ::Android::Apk.new(file) end + def size(humanable = false) + AppInfo::Parser::Util.file_size(@file, humanable) + end + def os Parser::Platform::ANDROID end def build_version @@ -56,41 +60,69 @@ # def tablet? # resource # end def wear? - uses_features.include?('android.hardware.type.watch') + use_features.include?('android.hardware.type.watch') end def tv? - uses_features.include?('android.software.leanback') + use_features.include?('android.software.leanback') end def min_sdk_version manifest.min_sdk_ver end def target_sdk_version manifest.doc.elements['/manifest/uses-sdk'].attributes['targetSdkVersion'].to_i end - def uses_features - uses_features = [] - manifest.doc.each_element('/manifest/uses-feature') do |elem| - uses_features << elem.attributes['name'] + def use_permissions + manifest.use_permissions + end + + def use_features + manifest_values('/manifest/uses-feature') + end + + def signs + @apk.signs.each_with_object([]) do |(path, sign), obj| + obj << Sign.new(path, sign) end - uses_features.uniq end + def certificates + @apk.certificates.each_with_object([]) do |(path, certificate), obj| + obj << Certificate.new(path, certificate) + end + end + + def activities + components.select {|c| c.type == 'activity' } + end + + def services + components.select {|c| c.type == 'service' } + end + + def components + manifest.components + end + def manifest @apk.manifest end def resource @apk.resource end + def dex + @apk.dex + end + def icons unless @icons tmp_path = File.join(Dir.mktmpdir, "AppInfo-android-#{SecureRandom.hex}") @icons = @apk.icon.each_with_object([]) do |(path, data), obj| @@ -114,8 +146,34 @@ end alias identifier bundle_id alias package_name bundle_id alias device_type os + + private + + def manifest_values(path, key = 'name') + values = [] + manifest.doc.each_element(path) do |elem| + values << elem.attributes[key] + end + values.uniq + end + + class Certificate + attr_reader :path, :certificate + def initialize(path, certificate) + @path = path + @certificate = certificate + end + end # /Certificate + + class Sign + attr_reader :path, :sign + def initialize(path, sign) + @path = path + @sign = sign + end + end # /Certificate end # /APK end # /Parser end # /AppInfo