Android 13 GTS GtsPermissionControllerHostTestCases Test Failed

Android13 tablet project test GtsPermissionControllerHostTestCases Failed, the failure log is as follows:

java.lang.AssertionError: on-device tests failed:
com.android.gts.permissioncontroller.PermissionControllerTest29#testGranted:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.test.uiautomator.UiObject2.isChecked()' on a null object reference
at com.android.gts.permissioncontroller.BasePermissionsTest.setPermissionGrantState(BasePermissionsTest.java:527)
at com.android.gts.permissioncontroller.BasePermissionsTest.setPermissionGrantState(BasePermissionsTest.java:502)
at com.android.gts.permissioncontroller.BasePermissionsTest.grantPermissions(BasePermissionsTest.java:393)
at com.android.gts.permissioncontroller.BasePermissionsTest.grantPermission(BasePermissionsTest.java:389)
at com.android.gts.permissioncontroller.PermissionControllerTest29.testGranted(PermissionControllerTest29.java:103)

    at android.permissioncontroller.gts.Utils.runDeviceTests(Utils.java:130)
    at android.permissioncontroller.gts.Utils.runDeviceTests(Utils.java:80)
    at android.permissioncontroller.gts.Utils.runDeviceTestsAsCurrentUser(Utils.java:44)
    at android.permissioncontroller.gts.PermissionControllerHostTest.testGrantAppPermissionFragment(PermissionControllerHostTest.java:229)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:61)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at com.android.tradefed.testtype.DeviceJUnit4ClassRunner.runChild(DeviceJUnit4ClassRunner.java:111)
    at com.android.tradefed.testtype.DeviceJUnit4ClassRunner.runChild(DeviceJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at com.android.tradefed.testtype.DeviceJUnit4ClassRunner.run(DeviceJUnit4ClassRunner.java:147)
    at com.android.tradefed.testtype.junit4.ExceptionThrowingRunnerWrapper.run(ExceptionThrowingRunnerWrapper.java:43)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.android.tradefed.testtype.HostTest.runJUnit4Tests(HostTest.java:736)
    at com.android.tradefed.testtype.HostTest.runTestClasses(HostTest.java:616)
    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:379)
    at com.android.tradefed.testtype.suite.GranularRetriableTestWrapper.run(GranularRetriableTestWrapper.java:289)
    at com.android.tradefed.testtype.suite.ModuleDefinition.run(ModuleDefinition.java:595)
    at com.android.tradefed.testtype.suite.ITestSuite.runSingleModule(ITestSuite.java:951)
    at com.android.tradefed.testtype.suite.ITestSuite.run(ITestSuite.java:828)
    at com.android.tradefed.invoker.InvocationExecution.runTest(InvocationExecution.java:1359)
    at com.android.tradefed.invoker.InvocationExecution.runTests(InvocationExecution.java:1138)
    at com.android.tradefed.invoker.TestInvocation.prepareAndRun(TestInvocation.java:626)
    at com.android.tradefed.invoker.TestInvocation.performInvocation(TestInvocation.java:278)
    at com.android.tradefed.invoker.TestInvocation.invoke(TestInvocation.java:1357)
    at com.android.tradefed.command.CommandScheduler$InvocationThread.run(CommandScheduler.java:686)

Observing the log, it probably means that a certain view is empty, causing the test item to not be changed. Decompile the test apk and view the source code as follows:

The code is very simple. When testing the app, it will apply for the CALENDAR permission. After having the permission, a piece of data is queried from the calendar database. If the query is successful, the test item is regarded as PASS.

To apply for permission, you will actually be redirected to the permission management interface, which is the APP details interface–“Permissions–>Permission list, find the CALENDAR permission, and then click to allow it. .

The reason why we failed was that the permissions of the last interface were not obtained and the corresponding controls were not obtained. Take a closer look at the code for finding the control. In fact, it is based on permissions–“label–>then find the view–“click in

Here we are

android.permission.READ_CALENDAR–》CALENDAR finds the view based on this label..

In fact, we can find the problem here. If there are two TextViews on an interface whose names are both CALENDAR, then this will not necessarily be the TexviewView in the permission list, and then it will not enter the third interface, and it will As a result, the test error is reported, getDenyButton()isChecked cannot be found, and the test is terminated.

Because ours is a tablet project, and for large-screen or tablet projects after Android 12, the navigation bar at the bottom will change to display a taskbar, from NavigationBar to Taskbar. Taskbar allows some apps to reside here;

You can see that no matter which app you click on, there is a TaskBar at the bottom, and the app where our TaskBar is resident happens to have an app called CALENDAR. This will cause us to click on the bottom TaskBar on the second interface when testing. CALENDAR

This is why our test fails. The modification method is also very simple. For the permissions involved in the PermissionControllerTest29 APP, the bottom does not contain the APP corresponding to the Label with the same name as these permissions.

That is to say, our TASKBAR at the bottom cannot contain the APP name: Contacts, Calendar, Location, Camera. After removal, retest PASS