diff options
author | Riddle Hsu <riddlehsu@google.com> | 2022-10-12 13:17:30 +0800 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-15 01:17:45 +0000 |
commit | 17d9e2ceb5284bf5c5dab517dad4d1508331c465 (patch) | |
tree | c795f8ff79c37ec5d874bbddf5ec9d99768e8646 | |
parent | 2b9d72d252ad9fee70b70284714b34fe0d411027 (diff) | |
download | cts-17d9e2ceb5284bf5c5dab517dad4d1508331c465.tar.gz |
Wait for HeavyWeightSwitcherActivity to be shown
Because syncInputTransactions only takes effect if there is an
animation, if HeavyWeightSwitcherActivity is not drawn fast enough
to trigger the animation, it doesn't really wait for something.
Then the following maybeClick may still click on a temporal position
which isn't the actual position of the target button.
Fix: 239638704
Test: ActivityManagerProcessStateTest#testCantSaveStateLaunchAndSwitch
Change-Id: I7c48f4688a7e43e3d1c95292c318d9f9e7167bd4
(cherry picked from commit e7ed67acde7f98ef1de38977f3835c6bcf9704cb)
Merged-In: I7c48f4688a7e43e3d1c95292c318d9f9e7167bd4
-rw-r--r-- | tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java b/tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java index cd84840b78a..eaecc4e6fc6 100644 --- a/tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java +++ b/tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java @@ -65,12 +65,11 @@ import android.os.SystemClock; import android.os.UserHandle; import android.permission.cts.PermissionUtils; import android.platform.test.annotations.Presubmit; -import android.server.wm.WindowManagerState; +import android.server.wm.WindowManagerStateHelper; import android.support.test.uiautomator.BySelector; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.UiSelector; import android.util.Log; -import android.view.accessibility.AccessibilityEvent; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; @@ -239,9 +238,9 @@ public class ActivityManagerProcessStateTest { } private void waitForAppFocus(String waitForApp, long waitTime) { + final WindowManagerStateHelper wms = new WindowManagerStateHelper(); long waitUntil = SystemClock.elapsedRealtime() + waitTime; while (true) { - WindowManagerState wms = new WindowManagerState(); wms.computeState(); String appName = wms.getFocusedApp(); if (appName != null) { @@ -262,17 +261,11 @@ public class ActivityManagerProcessStateTest { } } - private void startActivityAndWaitForShow(final Intent intent) throws Exception { - mInstrumentation.getUiAutomation().executeAndWaitForEvent( - () -> { - try { - mTargetContext.startActivity(intent); - } catch (Exception e) { - fail("Cannot start activity: " + intent); - } - }, (AccessibilityEvent event) -> event.getEventType() - == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED - , WAIT_TIME); + private void startAndWaitForHeavyWeightSwitcherActivity(final Intent intent) { + mTargetContext.startActivity(intent); + // Assume there was another CANT_SAVE_STATE app, so it will redirect to the switch activity. + new WindowManagerStateHelper().waitAndAssertWindowSurfaceShown( + "android/com.android.internal.app.HeavyWeightSwitcherActivity", true); // Wait for the transition animation to complete. mInstrumentation.getUiAutomation().syncInputTransactions(); } @@ -1445,7 +1438,6 @@ public class ActivityManagerProcessStateTest { homeIntent.addCategory(Intent.CATEGORY_HOME); homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - ActivityManager am = mContext.getSystemService(ActivityManager.class); UiDevice device = UiDevice.getInstance(mInstrumentation); PermissionUtils.grantPermission( @@ -1486,7 +1478,7 @@ public class ActivityManagerProcessStateTest { uid1Watcher.expect(WatchUidRunner.CMD_PROCSTATE, WatchUidRunner.STATE_HEAVY_WEIGHT); // Start the second heavy-weight app, should ask us what to do with the two apps - startActivityAndWaitForShow(activity2Intent); + startAndWaitForHeavyWeightSwitcherActivity(activity2Intent); // First, let's try returning to the original app. maybeClick(device, new UiSelector().resourceId("android:id/switch_old")); @@ -1503,7 +1495,7 @@ public class ActivityManagerProcessStateTest { uid1Watcher.expect(WatchUidRunner.CMD_PROCSTATE, WatchUidRunner.STATE_HEAVY_WEIGHT); // Again try starting second heavy-weight app to get prompt. - startActivityAndWaitForShow(activity2Intent); + startAndWaitForHeavyWeightSwitcherActivity(activity2Intent); // Now we'll switch to the new app. maybeClick(device, new UiSelector().resourceId("android:id/switch_new")); @@ -1529,7 +1521,7 @@ public class ActivityManagerProcessStateTest { uid2Watcher.expect(WatchUidRunner.CMD_PROCSTATE, WatchUidRunner.STATE_HEAVY_WEIGHT); // Try starting the first heavy weight app, but return to the existing second. - startActivityAndWaitForShow(activity1Intent); + startAndWaitForHeavyWeightSwitcherActivity(activity1Intent); maybeClick(device, new UiSelector().resourceId("android:id/switch_old")); waitForAppFocus(CANT_SAVE_STATE_2_PACKAGE_NAME, WAIT_TIME); device.waitForIdle(); @@ -1542,7 +1534,7 @@ public class ActivityManagerProcessStateTest { uid2Watcher.expect(WatchUidRunner.CMD_PROCSTATE, WatchUidRunner.STATE_HEAVY_WEIGHT); // Again start the first heavy weight app, this time actually switching to it - startActivityAndWaitForShow(activity1Intent); + startAndWaitForHeavyWeightSwitcherActivity(activity1Intent); maybeClick(device, new UiSelector().resourceId("android:id/switch_new")); waitForAppFocus(CANT_SAVE_STATE_1_PACKAGE_NAME, WAIT_TIME); device.waitForIdle(); |