summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-10-15 01:18:11 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-10-15 01:18:11 +0000
commit86682abf2a60b5878cf3e7e1263dc77ab1145057 (patch)
treec795f8ff79c37ec5d874bbddf5ec9d99768e8646
parent2b9d72d252ad9fee70b70284714b34fe0d411027 (diff)
parent17d9e2ceb5284bf5c5dab517dad4d1508331c465 (diff)
downloadcts-86682abf2a60b5878cf3e7e1263dc77ab1145057.tar.gz
Merge cherrypicks of [20168869] into tm-qpr1-release.
Change-Id: I20c2db0266b4e2b413155d7ec547f124f964c057
-rw-r--r--tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java30
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();