---- by Shengwen.Wei
一、 概述
随着移动互联网的发展,用户对于自身的信息安全越来越重视,基于此,android系统对于用户自身的信息安全特别是android M(6.0)以后,对于权限的管理尤为严格。
二、 高级权限的使用限制及解限
目前,android系统按照安全级别大致将权限分两种:一般权限、危险权限。
对于一般权限,该类权限基本不会涉及用户的使用信息,如蓝牙、NFC等权限;对于这类权限,开发者只需在AndroidMenifest.xml中注册即可;
而对于危险权限,如读写联系人、读写短信等等涉及到用户隐私信息的开发者不仅仅要在AndroidMenifest.xml中注册,还需要在代码中动态注册然后由用户决定是否允许进程是否能支持该种权限的使用甚至很多权限需要拿到系统权限才能使用,这里不做累述,下面介绍的是有部分高级权限即使apk有系统权限,google依然会将其列入黑名单中,影响的系统版本从android M以后开始;
比如<uses-permission android:name="android.permission.INSTALL_PACKAGES"/> ,这类权限即使App得到了系统级的管理权限,若apk预置于/system/app或/system/pri-app/目录下,还是会有其他问题的存在,如CTS、GTS通不过,那这类情况该如何解决呢?
这里就以笔者项目中用到的INSTALL_PACKAGES自动安装的权限来说明。
由于项目需求,在无忧换机app中使用了INSTALL_PACKAGES自动安装App的权限,起初并没有觉得什么不对,因为权限可以正常使用,APP也可以正常自动安装,但是随着项目的进行,当进行CTS、GTS的时候发现GTS并不能通过,log如下:
GtsInstallPackagesWhitelistDeviceTestCases
- com.google.android.installpackageswhitelist.gts.GtsInstallPackagesWhitelistDeviceTest#testInstallerPackagesAgainstWhitelist
com.google.android.installpackageswhitelist.gts.GtsInstallPackagesWhitelistDeviceTest#testInstallerPackagesAgainstWhitelistfail: junit.framework.AssertionFailedError: Packageshave INSTALL_PACKAGES permission not on whitelist:
com.tpv.transfer0bb9346f747777bb613560a9a4d7d5c6b2dab5601b6640ca71e2cf9fa25b6918
atjunit.framework.Assert.fail(Assert.java:50)
at junit.framework.Assert.assertTrue(Assert.java:20)
atcom.google.android.installpackageswhitelist.gts.GtsInstallPackagesWhitelistDeviceTest.checkInstallerPackageApps(GtsInstallPackagesWhitelistDeviceTest.java:159)
at com.google.android.installpackageswhitelist.gts.GtsInstallPackagesWhitelistDeviceTest.testInstallerPackagesAgainstWhitelist(GtsInstallPackagesWhitelistDeviceTest.java:165)
at java.lang.reflect.Method.invoke(NativeMethod)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:220)
atandroid.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:205)
atjunit.framework.TestCase.runBare(TestCase.java:134)
atjunit.framework.TestResult$1.protect(TestResult.java:115)
at android.support.test.internal.runner.junit3.AndroidTestResult.runProtected(AndroidTestResult.java:77)
atjunit.framework.TestResult.run(TestResult.java:118)
atandroid.support.test.internal.runner.junit3.AndroidTestResult.run(AndroidTestResult.java:55)
at junit.framework.TestCase.run(TestCase.java:124)
atandroid.support.test.internal.runner.junit3.NonLeakyTestSuite$NonLeakyTest.run(NonLeakyTestSuite.java:63)
atandroid.support.test.internal.runner.junit3.AndroidTestSuite$1.run(AndroidTestSuite.java:97)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
atjava.util.concurrent.FutureTask.run(FutureTask.java:237)
atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
atjava.lang.Thread.run(Thread.java:761)
看log大致的意思就是INSTALL_PACKAGES并没有在google白名单中注册,当时笔者觉得很不解,按照往常的逻辑,将APP放在/system/app下或者/system/pri-app目录下应该这些权限的使用应该是没问题了,于是尝试将apk置于/system/prio-app/目录下之后,问题依然存在,
没办法了,多跑几次看下log还有没有什么有用的信息吧。通过几次的gts测试都看到有这么一条log:
DOWNLOAD: https://androidpartner.googleapis.com/v1/dynamicconfig/suites/GTS/modules/GtsInstallPackagesWhitelistDeviceTestCases/version/1.0?key=AIzaSyAbwX5JRlmsLeygY2WWihpIJPXFLueOQ3U
由于运行GTS测试的电脑不能访问google的缘故,会自动尝试download了三次(估计没有这三次的尝试,我也不会注意这个),于是想办法科学上网访问该网址,显示如下:
{
"dynamicConfigEntries": {
"specific_pairs": {
"configValues": [
"com.google.android.packageinstaller197f667ae126af53a8a891b5d5c81d7c0e48223b3e828e51870a4aeadd9e8d9d",
"com.android.vendingf0fd6c5b410f25cb25c3b53346c8972fae30f8ee7411df910480ad6b2d60db83",
"com.qiku.android.clone36001ae96ce24dd446df20f6fd60eb60ce1e53ca13fb0d5dd1c946af8309aeb8a9b",
"com.kidoz.acer033457d5fa83daafe39103158447aaf39a5d96455435f63a84e283892b482a79",
"com.rock.gota 03bad484485761ec066909dcd6e1dff2db81aee11e604dc5f6562a2b7f2c6260",
"com.zui.factorymode04785ca9b6927b557aa779e5b68991c1510921d5f59404f84d436e5e3afdbc62",
"com.zui.auservice04785ca9b6927b557aa779e5b68991c1510921d5f59404f84d436e5e3afdbc62",
"com.mobilturk.scocuk 04c26c690897c90ca87c54a7ddf5649d8a49c39947496dff3c54148411dc8956",
......
"com.huawei.android.launcher 30cd8d5918af4263e7b3b908ab691cee03814e8d683b09c0c62baf9c1d302014",
"com.huawei.android.thememanager 30cd8d5918af4263e7b3b908ab691cee03814e8d683b09c0c62baf9c1d302014",
]
},
"any": {
"configValues": [
"android",
"com.android.packageinstaller",
"com.android.shell",
"com.android.managedprovisioning",
"com.customermobile.preload.vzw",
"com.google.android.retaildemo",
"com.mediatek.datatransfer",
"com.motorola.autopackageinstaller",
"com.google.android.tungsten.setupwraith",
"com.coloros.speechassist",
"com.nearme.deamon"
]
}
}
}
前半部分看着像是包名,后面一串字符看着眼熟,感觉问题的答案很接近但是却又触碰不到,没有更多想法情况下,看google官网文档吧,发现如下这段文字:
Adding the whitelists
Permissionwhitelists for applications can be listed in a single or multiple XML fileslocated in the frameworks/base/etc/permissions directory, asfollows:
· /etc/permissions/privapp-permissions-
· /etc/permissions/privapp-permissions-
There is nostrict rule for organizing content, it can be decided by the device implementeras long as all applications from /system/priv-app arewhitelisted. For example, Google has a single whitelist for all privilegedapplications developed by Google.
The followingorganization is recommended:
· Permissions for apps that are alreadyincluded in AOSP tree are listed in this file: /etc/permissions/privapp-permissions-platform.xml
· Permissions for Google applications arelisted in this file: /etc/permissions/privapp-permissions-google.xml
· For other applications, use files of theform: /etc/permissions/privapp-permissions-
然而这些方法我都已经试过了无效,最终了解到需要向google申请将该app的权限需求注册到他们的白名单列表中(就是上一个表),需要提供包名、签名sh256,原来如此,那个表格的后半部分就是apk签名的sh256水印,
查看方法:keytool -list -v-keystore 签名文件;需要注意的是提供给google的sh256数字信息是将查看到的内容去掉“:”的小写字串。
待申请通过后,再跑GTS即可顺利通过。