[Google CTS]android.app.usage.cts.UsageReportingTest#testSplitscreenSameTokenTwoMissedStop test fail

testSplitscreenSameTokenTwoMissedStop

Today, the emergence of a CTS fail, never appeared before, reproducible steps must set the screen lock to none, can set the swipe ran, more strange that there have been no previous versions, test and asked his colleagues found that this time we run time is running separately using multiple machines, so want to see, before the whole running time should have run the other case the lock screen to swipe before this case, this time due to run separately, this case and set the swipe of separate case that led to look at the cause of this case fail:

android.app.usage.cts.UsageReportingTest#testSplitscreenSameTokenTwoMissedStop
junit.framework.AssertionFailedError: Timeout: android.app.usage.cts/SuperSecretToken found in list of active activities and tokens
	at junit.framework.Assert.fail(Assert.java:50)
	at com.android.compatibility.common.util.TestUtils.failWithLog(TestUtils.java:36)
	at com.android.compatibility.common.util.TestUtils.waitUntil(TestUtils.java:76)
	at android.app.usage.cts.UsageReportingTest.assertAppOrTokenUsed(UsageReportingTest.java:361)
	at android.app.usage.cts.UsageReportingTest.testSplitscreenSameTokenTwoMissedStop(UsageReportingTest.java:350)
	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:919)

/cts/tests/tests/app.usage/src/android/app/usage/cts/UsageReportingTest.java
class method in which testSplitscreenSameTokenTwoMissedStop call assertAppOrTokenUsed assertion failure cause, this method was transferred twice this method, according to the row number is assertion is false failure

 public void testSplitscreenSameTokenTwoMissedStop() throws Exception {
         //开启两个Activity进入分屏模式
         launchActivitiesInSplitScreen(
                  getLaunchActivityBuilder().setTargetActivity(
                          new ComponentName(mTargetPackage,
                                  Activities.ActivityOne.class.getName())),
                  getLaunchActivityBuilder().setTargetActivity(
                          new ComponentName(mTargetPackage,
                                  Activities.ActivityTwo.class.getName())));
          assertAppOrTokenUsed(mFullToken0, true);
          // 让设备进去睡眠,即灭屏
          mUiDevice.sleep();
          // 灭屏后再等待1s
          Thread.sleep(1000);
          assertAppOrTokenUsed(mFullToken0, false);
}

assertAppOrTokenUsed

private void assertAppOrTokenUsed(String entity, boolean expected) throws Exception {
          final String failMessage;
          if (expected) {
              failMessage = entity + " not found in list of active activities and tokens";
          } else {
              failMessage = entity + " found in list of active activities and tokens";
          }
  
          TestUtils.waitUntil(failMessage, ASSERT_TIMEOUT_SECONDS, () -> {
              final String activeUsages =
                      mUiDevice.executeShellCommand("dumpsys usagestats apptimelimit actives");
              final String[] actives = activeUsages.split("\n");
              boolean found = false;
  
              for (String active: actives) {
                  if (active.equals(entity)) {
                      found = true;
                      break;
                  }
              }
              return found == expected;
          });
      }

mFullToken0 value of a splicing application package name TOKEN_0

private static final String TOKEN_0 = "SuperSecretToken";
public void setUp() throws Exception {
          super.setUp();
          .......
          mTargetPackage = InstrumentationRegistry.getTargetContext().getPackageName();
          mFullToken0 = mTargetPackage + "/" + TOKEN_0;

      }

Back before the code
by executing dumpsys usagestats apptimelimit actives command to get the string, then "\ n" newline application package name is actually cutting the resulting string, so this provision is a test case into the split-screen mode, off screen, see if you can find also active in the Activity, find that is fail, did not find the pass, why the company's machines have this problem, google reference machine is able to pass, then after an investigation of our machines are not configured DozeService, add the following code to pass, but the company machine configuration is low, add DozeService increases power consumption so the case can only apply waive this provision

    <string name="config_dozeComponent" translatable="false">com.android.systemui/com.android.systemui.doze.DozeService</string>
Published 28 original articles · won praise 40 · views 4816

Guess you like

Origin blog.csdn.net/qq_34211365/article/details/103423888