GTS 测试GtsUnofficialApisUsageTestCases失败如下:
junit.framework.AssertionFailedError: There are 102 violation(s)
com.google.android.gm / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.gm / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.gm / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.gm / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.dialer / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.dialer / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.dialer / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.apps.photos / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.apps.safetyhub / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.tachyon / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.tachyon / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.apps.tachyon / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.apps.tachyon / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.apps.youtube.music / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.gms / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.gms / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.gms / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.gms / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.gms / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.gms / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.gms / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.gms / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.tts / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.tts / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.tts / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.tts / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.as / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.as / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.as / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.as / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.keep / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.keep / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.keep / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.keep / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.apps.docs / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.docs / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.apps.docs / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.apps.docs / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.calendar / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.calendar / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.calendar / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.calendar / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.inputmethod.latin / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.inputmethod.latin / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.inputmethod.latin / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.inputmethod.latin / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.apps.messaging / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.messaging / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.apps.messaging / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.apps.messaging / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.apps.maps / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.deskclock / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.deskclock / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.contacts / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.contacts / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.contacts / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.contacts / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.googlequicksearchbox / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.youtube / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.youtube / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.youtube / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.youtube / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.youtube / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.youtube / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.youtube / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.youtube / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
com.google.android.videos / Landroid/media/MediaRoute2Info$Builder;->setDeduplicationIds(Ljava/util/Set;)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.videos / Landroid/media/MediaRoute2Info$Builder;->setType(I)Landroid/media/MediaRoute2Info$Builder; / BLOCKED / LINKING
com.google.android.videos / Landroid/media/MediaRoute2Info;->getDeduplicationIds()Ljava/util/Set; / BLOCKED / LINKING
com.google.android.videos / Landroid/media/MediaRoute2Info;->getType()I / BLOCKED / LINKING
com.google.android.videos / Landroid/window/BackEvent;->getProgress()F / BLOCKED / LINKING
com.google.android.videos / Landroid/window/BackEvent;->getSwipeEdge()I / BLOCKED / LINKING
com.google.android.videos / Landroid/window/BackEvent;->getTouchX()F / BLOCKED / LINKING
com.google.android.videos / Landroid/window/BackEvent;->getTouchY()F / BLOCKED / LINKING
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:223)
at com.android.gts.api.UnofficialApisUsageTest.testNonApiReferencesInProduct(UnofficialApisUsageTest.java:211)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at junit.framework.TestCase.runTest(TestCase.java:177)
at junit.framework.TestCase.runBare(TestCase.java:142)
at com.android.tradefed.testtype.DeviceTestResult$1.protect(DeviceTestResult.java:99)
at com.android.tradefed.testtype.DeviceTestResult.runProtected(DeviceTestResult.java:73)
at com.android.tradefed.testtype.DeviceTestResult.run(DeviceTestResult.java:104)
at junit.framework.TestCase.run(TestCase.java:130)
at com.android.tradefed.testtype.DeviceTestCase.run(DeviceTestCase.java:170)
at com.android.tradefed.testtype.JUnitRunUtil.runTest(JUnitRunUtil.java:65)
at com.android.tradefed.testtype.JUnitRunUtil.runTest(JUnitRunUtil.java:44)
at com.android.tradefed.testtype.JUnitRunUtil.runTest(JUnitRunUtil.java:39)
at com.android.tradefed.testtype.DeviceTestCase.run(DeviceTestCase.java:146)
at com.android.tradefed.testtype.HostTest.runRemoteTest(HostTest.java:673)
at com.android.tradefed.testtype.HostTest.runTestClasses(HostTest.java:581)
at com.android.tradefed.testtype.HostTest.run(HostTest.java:564)
at com.android.compatibility.common.tradefed.testtype.JarHostTest.run(JarHostTest.java:56)
at com.android.tradefed.testtype.suite.GranularRetriableTestWrapper.intraModuleRun(GranularRetriableTestWrapper.java:366)
at com.android.tradefed.testtype.suite.GranularRetriableTestWrapper.run(GranularRetriableTestWrapper.java:277)
at com.android.tradefed.testtype.suite.ModuleDefinition.run(ModuleDefinition.java:581)
at com.android.tradefed.testtype.suite.ITestSuite.runSingleModule(ITestSuite.java:912)
at com.android.tradefed.testtype.suite.ITestSuite.run(ITestSuite.java:792)
at com.android.tradefed.invoker.InvocationExecution.runTest(InvocationExecution.java:1335)
at com.android.tradefed.invoker.InvocationExecution.runTests(InvocationExecution.java:1114)
at com.android.tradefed.invoker.TestInvocation.prepareAndRun(TestInvocation.java:604)
at com.android.tradefed.invoker.TestInvocation.performInvocation(TestInvocation.java:274)
at com.android.tradefed.invoker.TestInvocation.invoke(TestInvocation.java:1322)
at com.android.tradefed.command.CommandScheduler$InvocationThread.run(CommandScheduler.java:629)
上述失败提示的app都是google的原生应用,例如com.google.android.youtube(YouTube)并且这些app都位于product目录下,我们可以反编译看下此测试项:
可以看到此测试项主要测试product目录下的app是否调用黑名单或者灰名单中的api,也就是非SDK接口管控名单内的api,名单如下:
Android P以后调用非 SDK(包括深灰名单、黑名单)接口的所有应用都将受到影响,Google提供的工具veridex 可以检测app是否调用了这些api,其内含有一个appcompat.sh ,我们可以看GTS也是使用该脚本
1:源码包含此工具,目录在:QSSI.13\art\tools\veridex\appcompat.sh
2:我们可以在QSSI.13 目录下编译此工具:make appcompat
3:我们就可以使用下面的命令行将其扫描内容输出到文件中
./appcompat.sh --dex-file=my_game.apk.apk >> out_put.txt
当然也可以加一个--imprecise参数,加这个参数是为了让输出内容更加详细
./appcompat.sh --dex-file=my_game.apk --imprecise >> out_put.txt
截图所示为扫描出来的非SDK API,扫描出92个隐藏api,52个反射api,还有一些其他的,例如7个api的最大只支持到q的,当然不是说这些api都不能调用,GTS测试失败的过滤条件为:
也就是下图只有红款内的api会被视为不规范,下面的Linking unsupported 亦或者Reflection unsupported 都可以算正常。
当然还有一个判断:该项是读取GTS配置文件:GtsUnofficialApisUsageTestCases.dynamic内是否配置了额外的api, 如果没有配置,则该方法始终为false,则GTS的此项过滤条件可以不考虑该条件
但是我们发现这些原生的应用肯定是调用了这些api,并且我们没有源码,所以修改不了。也就是按照这个测试工具的判断方法,我们只有一个方法可以测过该项,那就是把这些应用移到别的目录,例如system_ext/app 或者system/app目录下。这个也是可以的,只不过工作量比较大。举例YuTuBe修改如下:
# YouTube
LOCAL_PATH := $(my-dir)
....
#LOCAL_PRIVILEGED_MODULE := true
#phoebe add for move YuTuBe to system/app
#LOCAL_PRODUCT_MODULE := true
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DPI_VARIANTS := xxhdpi xhdpi hdpi mdpi
LOCAL_DPI_FILE_STEM := YouTube_$(my_src_arch)_%.apk
LOCAL_SRC_FILES := YouTube_$(my_src_arch)_xxhdpi.apk
...
...
当然网上也有人说,在google play store里面更新这些app,是一样的效果,更新这些app以后,这些app的目录变为了data/data/xxx 这样,所以也算跳过此项了。
当然最终问题的原因为:
GTS 工具版本更新,从R4更新为R1,这个时候我们再测试,就会PASS了。主要原因是因为第三个判断方法返回true,则此GTS会跳过此项。