https://blog.csdn.net/shift_wwx/article/details/81304574
GTS 中 测试case armeabi-v7a GtsPlacementTestCases 的时候会出现下面的异常,本文总结一下。
com.google.android.placement.gts.CoreGmsAppsPrivappPermissionsTest#testCoreGmsAppsPermissionsWhitelisted
本文主要分析第 1 个case,第 2 个case详情看:GTS 中 testNumberOfHeadedApplications fail 详解
这个case 本来应该是测试Privileged permission 的白名单,但是其中也出现了其他的异常。
来看下log:
07-30 23:29:59 I/ModuleListener: [1/20] com.google.android.placement.gts.CoreGmsAppsPrivappPermissionsTest#testCoreGmsAppsPermissionsWhitelisted fail:
android.content.pm.PackageManager$NameNotFoundException: com.google.android.apps.docs
at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:178)
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:149)
at com.google.android.placement.gts.CoreGmsAppsPrivappPermissionsTest.testCoreGmsAppsPermissionsWhitelisted(CoreGmsAppsPrivappPermissionsTest.java:81)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:52)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:148)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:142)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:764)
来看下code:
@Test
public void testCoreGmsAppsPermissionsWhitelisted() throws Exception {
if (ApiLevelUtil.isBefore(26)) {
String str = TAG;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Skipping test because privileged permissions whitelist was introduced in Android 8.0. Current API Level ");
stringBuilder.append(ApiLevelUtil.getApiLevel());
Log.i(str, stringBuilder.toString());
return;
}
boolean atLeastP = ApiLevelUtil.isAtLeast((int) true);
PackageManager packageManager = BusinessLogicTestCase.getContext().getPackageManager();
Set platformPrivilegedPermissions = getPlatformPrivilegedPermissions();
for (String pkgName : getCoreGmsPackages()) {
int flags = 12288;
if (atLeastP) {
flags = 12288 | 2097152;
}
PackageInfo pkg = packageManager.getPackageInfo(pkgName, flags);
String str2;
StringBuilder stringBuilder2;
if (!pkg.applicationInfo.isPrivilegedApp()) {
str2 = TAG;
stringBuilder2 = new StringBuilder();
stringBuilder2.append("Skipping check for non-privileged package ");
stringBuilder2.append(pkgName);
Log.i(str2, stringBuilder2.toString());
} else if (atLeastP || (pkg.applicationInfo.flags & 128) == 0) {
Set deniedPrivPermissions = new TreeSet();
int i = 0;
while (i < pkg.requestedPermissions.length) {
String permission = pkg.requestedPermissions[i];
if (platformPrivilegedPermissions.contains(permission) && (pkg.requestedPermissionsFlags[i] & 2) == 0) {
deniedPrivPermissions.add(permission);
}
i++;
}
stringBuilder2 = new StringBuilder();
stringBuilder2.append("All privileged permissions should be granted to ");
stringBuilder2.append(pkgName);
stringBuilder2.append(", but the following permissions were not granted: ");
stringBuilder2.append(deniedPrivPermissions);
Assert.assertTrue(stringBuilder2.toString(), deniedPrivPermissions.isEmpty());
} else {
str2 = TAG;
stringBuilder2 = new StringBuilder();
stringBuilder2.append("Skipping whitelist checks for ");
stringBuilder2.append(pkgName);
stringBuilder2.append(" - application was updated");
Log.w(str2, stringBuilder2.toString());
}
}
}
在code 执行到:
PackageInfo pkg = packageManager.getPackageInfo(pkgName, flags);
系统中并没有这样的package,那这里的pkgName 是怎么来的呢?详细看getCoreGmsPackages():
private List getCoreGmsPackages() throws IOException, XmlPullParserException {
DynamicConfigDeviceSide dcds = new DynamicConfigDeviceSide("GtsPlacementTestCases");
if (isAutomotiveDevice()) {
return dcds.getValues("core_gas_packages");
}
return dcds.getValues("general_core_gms_packages");
}
code 可以看出应该是一个配置文件中不同的key-values,如果是Automotive 设备应该获取core_gas_packages,如果不是该设备,应该获取general_core_gms_packages,来看下这两个key-values:
com.google.android.gms
com.google.android.webview
com.google.android.configupdater
com.google.android.syncadapters.contacts
com.google.android.backuptransport
com.google.android.onetimeinitializer
com.google.android.partnersetup
com.google.android.gsf
com.android.vending
com.android.chrome
com.android.providers.partnerbookmarks
com.google.android.apps.docs
com.google.android.apps.maps
com.google.android.backuptransport
com.google.android.configupdater
com.google.android.feedback
com.google.android.gm
com.google.android.gms
com.google.android.googlequicksearchbox
com.google.android.gsf
com.google.android.music
com.google.android.onetimeinitializer
com.google.android.partnersetup
com.google.android.setupwizard
com.google.android.syncadapters.contacts
com.google.android.tts
com.google.android.videos
com.google.android.youtube
这里显然获取的是general_core_gms_packages(有没有发现这里有一个bug,code 中是core_gas_packages,实际上配置文件中是cn_core_gms_packages,显然code 是写错了,所以google 的bug 也不少啊)。而最终原因应该是这里动态添加的package name ,并不是安装到系统中的。
结合这里的log 看,应该是包 com.google.android.apps.docs 并没有安装。
结论:
出现这个case 一般是Privileged permission 的问题,也有例外,需要结合dynamic 文件分析,是否是本地或是google 自身的问题。这里主要是com.google.android.apps.docs 没有安装,需要确认GMS 包里面是否存在。
更新下,google 后来已经豁免:
https://partnerissuetracker.corp.google.com/u/1/issues/111093792
更多GTS 测试的case 见:
CTS/GTS 常见问题汇总