https://blog.csdn.net/shift_wwx/article/details/81240876
GTS 测试 armeabi-v7a GtsOsTestCases 的时候会出现两个fail:
com.google.android.os.gts.RequiredComponentsTest#testServicesLibHostAppSignedCorrectly
com.google.android.os.gts.RequiredComponentsTest#testSharedLibHostAppSignedCorrectly
如下图:
解决办法:
将ro.build.tags 改成release-keys 即可。
本文用其中的 testServicesLibHostAppSignedCorrectly 举例说明。
来看这个fail 项的Details:
org.junit.ComparisonFailure: Services lib host app signed with an invalid certificate expected:<[DC:76:26:3A:5A:12:73:F8:2F:BB:0E:37:5C:C3:BE:51:9A:1A:3D:4D:FD:73:15:96:C8:29:E2:32:F7:77:73:4C]> but was:<[3A:44:8F:6B:D4:16:FF:B5:E5:FA:C2:91:03:A8:C1:23:13:1B:A8:63:47:42:0C:88:1D:C3:2F:21:58:60:AD:53]>
从log 上很显然看出,给了个无效的证书,期望的是DC:76:26 给的却是3A:44:8F:6B。
结合code 就可以知道为什么了:
public void testServicesLibHostAppSignedCorrectly() throws Exception {
if (playStorePreloaded()) {
PackageManager packageManager = InstrumentationRegistry.getContext().getPackageManager();
Assert.assertEquals("Services lib host app signed with an invalid certificate", isDevKeysBuild() ? SERVICES_CERT_SHA256_DIGEST : SERVICES_CERT_SHA256_DIGEST_RELEASE, computePackageSignatureDigest(packageManager.getPackageInfo(packageManager.getServicesSystemSharedLibraryPackageName(), 64)));
return;
}
Log.d(TAG, "Bypass as no Play Store preloaded.");
}
选择的时候判断isDevKeyBuild() :
private static boolean isDevKeysBuild() {
for (String tag : Build.TAGS.split(",")) {
if (TAG_DEV_KEYS.equals(tag.trim())) {
return true;
}
}
return false;
}
其中的TAG_DEV_KEYS为:
private static final String TAG_DEV_KEYS = "dev-keys";
Build.TAGS :
public static final String TAGS = getString("ro.build.tags");
isDevKeysBuild() 函数的意思就是判断ro.build.tags 的值是否为dev-keys。
这样大概就知道了,如果是dev-keys 的话,最终选择的是 SERVICES_CERT_SHA256_DIGEST:
private static final String SERVICES_CERT_SHA256_DIGEST = "DC:76:26:3A:5A:12:73:F8:2F:BB:0E:37:5C:C3:BE:51:9A:1A:3D:4D:FD:73:15:96:C8:29:E2:32:F7:77:73:4C";
也就是log 上提示的部分,如果不是dev-keys 会选择 SERVICES_CERT_SHA256_DIGEST_RELEASE:
private static final String SERVICES_CERT_SHA256_DIGEST_RELEASE = "3A:44:8F:6B:D4:16:FF:B5:E5:FA:C2:91:03:A8:C1:23:13:1B:A8:63:47:42:0C:88:1D:C3:2F:21:58:60:AD:53";
分析log 与code:
之所以出现log 中expected 是SERVICES_CERT_SHA256_DIGEST,那是因为与后面PMS 获取的不一致。
所以,这里的ro.build.tags 不能为dev-keys,而应该改成release-keys,保持跟后面PMS 中获取的一致。
对于testSharedLibHostAppSignedCorrectly 也是同样的要求。
结论:
对于这两个case 只需要配置 ro.build.tags 这个值为release-keys 即可。
更多GTS 测试的case 见:
CTS/GTS 常见问题汇总