基础知识

Android应用生死轮回的那些事儿(6) - 武器库完结篇

2016-08-17  本文已影响0人  Jtag特工

Android应用生死轮回的那些事儿(6) - 武器库完结篇

PackageManager武器库的完结篇,让我们梳理一下从Android 1.0到Android 7.0的发展过程吧。

资源相关API

这些API虽然数量众多,但是功能相对简单,都是根据包头或者是ApplicationInfo或Activity信息去获取一些资源,如图标,文本等。

Android 1.0创始API

Android 2.3新增API

Android 2.3新增两个API,都是跟Logo相关。

Android 4.4手表版新增API

手表上新增了Banner.

Android 5.0新增API

Android 5.0新增了UserBadged UI,所以新增了三个方法:

禁掉或者解禁相关API

Android中可以支持将应用或者组件禁掉或者解禁。
ComponentEnableSetting是通过组件名来设置,ApplicationEnableSetting是通过包名。

setApplicationEnabledSetting

原型:

void setApplicationEnabledSetting (String packageName, int newState, int flags)

参数:

状态可以为:

例程:禁掉微信:

    public void testSetApplicationEnableSetting() {
        mPm.setApplicationEnabledSetting("com.tencent.mm", PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

setComponentEnabledSetting

将包中的四大组件之一禁掉或解禁。

原型:

void setComponentEnabledSetting (ComponentName componentName, int newState, int flags);

参数与上面的针对整个应用的一致。

检查签名

Android 1.0时,只能检查两个包名的签名是否一致。

原型:

int checkSignatures (String pkg1, String pkg2);

到了Android 2.0,也可以支持对两个uid之间判断签名。
问题是,从包名获取uid的API,要到Android 7.0才有呢。。。

原型:

int checkSignatures (int uid1, int uid2);

Prefer相关

addPackageToPreferred API已经在Android 2.1被除名,所以Prefer相关的API,只剩下下面三个:

至此,Android 1.0的PackageManager提供的46个API全部讲完了。

feature相关API

Android 2.0开始引入feature的概念。我们可以通过getSystemAvailableFeatures方法获取系统支持哪些feature. 或者是通过hasSystemFeature(name)方法判断是否支持一个feature.
不过,Android 2.0的时候,feature是不分版本号的。支持版本号的或者是通过hasSystemFeature方法要到Android 7.0才会出品。

FeatureInfo类

属性:

方法:

getSystemAvailableFeatures

原型:

FeatureInfo[] getSystemAvailableFeatures ();

例程:

    public void testGetSystemAvailableFeatures(){
        final FeatureInfo[] fis = mPm.getSystemAvailableFeatures();
        if(fis!=null){
            for(FeatureInfo fi:fis){
                Log.d(TAG,"Feature Info:"+fi.toString());
            }
        }
    }

输出结果:

08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{385e67d android.hardware.sensor.proximity fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{deb6972 android.hardware.sensor.accelerometer fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{788d1c3 android.hardware.faketouch fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{4fcea40 android.hardware.usb.accessory fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{c8f6d79 android.software.backup fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{102aabe android.hardware.touchscreen fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{b1cc71f android.hardware.touchscreen.multitouch fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{e66a6c android.software.print fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{2106835 android.software.voice_recognizers fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{ebab4ca android.hardware.sensor.gyroscope fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{6d0b63b android.hardware.bluetooth fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{b05c158 android.hardware.camera.autofocus fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{46c52b1 android.hardware.telephony.gsm fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{9375396 android.hardware.usb.host fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{40a7b17 android.hardware.audio.output fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{4c19b04 android.hardware.camera.flash fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{cc268ed android.hardware.camera.front fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{f0d1322 android.hardware.screen.portrait fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{2b1b1b3 android.software.home_screen fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{d3f6370 android.hardware.microphone fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{ce9a6e9 android.hardware.bluetooth_le fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{18d3f6e android.hardware.touchscreen.multitouch.jazzhand fl=0x0}
08-17 11:40:49.889 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{f8bb60f android.software.app_widgets fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{e8f469c android.software.input_methods fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{32cc8a5 android.hardware.sensor.light fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{3d1e47a android.software.device_admin fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{457a42b android.hardware.camera fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{1983088 android.hardware.screen.landscape fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{dc64a21 android.software.managed_users fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{e89ce46 android.software.webview fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{daa5807 android.hardware.camera.any fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{4c3cd34 android.software.connectionservice fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{a1c675d android.hardware.touchscreen.multitouch.distinct fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{48488d2 android.hardware.location.network fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{28a6da3 android.hardware.wifi.direct fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{16a88a0 android.software.live_wallpaper fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{bbd1c59 android.hardware.location.gps fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{3fe601e android.hardware.wifi fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{9cc40ff android.hardware.location fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{bff8ecc android.hardware.telephony fl=0x0}
08-17 11:40:49.890 17111-17111/com.yunos.xulun.testcppjni2 D/TestPackageManager: Feature Info:FeatureInfo{71a2515 glEsVers=3.0 fl=0x0}

上面都是feature,最后一条是openGLES的版本号:3.0

hasSystemFeature

原型:

boolean hasSystemFeature (String name);

feature的取值可以是下面的字符串:

包名转换API - Android 2.2新增

原型:

String[] currentToCanonicalPackageNames (String[] names);
String[] canonicalToCurrentPackageNames (String[] names)

例程:

    public void testCurrentToCanonicalPackageNames(){
        String[] canonicalNames = mPm.currentToCanonicalPackageNames(new String[]{
                "com.yunos.xulun.testcppjni2","com.tencent.mm","com.taobao.taobao"});

        if(canonicalNames!=null) {
            for (String name : canonicalNames) {
                Log.d(TAG, "CanonicalName is:"+name);
            }
        }
    }

Android 1.0 PackageManager API总结

我们小结一下Android 1.0的46个PackageManager API:

Android 1.5新增Package API总结

API 3 (Android 1.5)新增了3个API:

isSafeMode

是否处于安全模式。

getSystemSharedLibraryNames

返回so库的路径

Android 2.0新增API总结

API 5 (Android 2.0)新增4个API,前面已经都讲过了。

Android 2.2新增API总结

API 8 (Android 2.2)新增3个API,2个名义包名转换的,还有一个权限管理的,前面都已经讲过了。

Android 2.3新增API总结

API 9 (Android 2.3)新增3个API,一个是getProviderInfo,终于把四大组件的getAPI凑齐了。另外从本版开始有了Logo的概念。

Android 3.0新增API总结

API 11 (Android 3.0)只增加一个API,为2.0的getInstallerPackageName提供一个setter接口。

Android 4.0新增API总结

API 14 (Android 4.0)也只增加一个API,用于安装时校验。

Android 4.2新增API总结

API 17 (Android 4.2)只增加一个API,其实是对于上一个API的补足。

Android 4.3新增API总结

API 18 (Android 4.3)新增一个权限相关API

Android 4.4新增API总结

API 19 (Android 4.4)只新增一个API,终于可以通过Intent查询ContentProvider了

Android 4.4手表版新增API总结

API 20 (KITKAT_WATCH)新增两个Banner相关API.

Android 5.0新增API总结

API 21 (Android 5.0)新增5个API,前三个是UserBadged界面相关。
第4个提供了PackageInstaller的接口。
最后一个是Leanback界面下获取Launch intent的API

Android 6.0新增API总结

API 23 (Android 6.0)只增加一个权限相关API

Android 7.0新增API总结

API 24 (Android 7.0)新增3个API。
systemm feature开始支持版本号。
终于可以获取package的uid了。

上一篇 下一篇

猜你喜欢

热点阅读