Attempt to reduce flakiness of testTaskChangeCallBacks
The test requires the device to be in a non-sleep state. Such as notifyTaskRemovalStarted is only called when a resumed activity is finishing. Sometimes SystemUI was crashed on other test module, then keyguard is shown after SystemUI is restarted. That causes the test activities to be unable to keep resumed state so the expected callback is missed. Bug: 291149606 Test: atest TaskStackChangedListenerTest#testTaskChangeCallBacks Change-Id: I5f512c548f0bf28a344e8cfab4e08c9fee5e7221
This commit is contained in:
@@ -58,7 +58,9 @@
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityA" />
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityB" />
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityRequestedOrientationChange" />
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityTaskChangeCallbacks" />
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityTaskChangeCallbacks"
|
||||
android:showWhenLocked="true"
|
||||
android:turnScreenOn="true" />
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityTaskDescriptionChange" />
|
||||
<activity android:name="com.android.server.wm.TaskStackChangedListenerTest$ActivityInVirtualDisplay"
|
||||
android:resizeableActivity="true" />
|
||||
|
||||
@@ -54,7 +54,10 @@ import android.widget.LinearLayout;
|
||||
|
||||
import androidx.test.filters.MediumTest;
|
||||
|
||||
import com.android.server.wm.utils.CommonUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -77,6 +80,11 @@ public class TaskStackChangedListenerTest {
|
||||
private static final int WAIT_TIMEOUT_MS = 5000;
|
||||
private static final Object sLock = new Object();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
CommonUtils.dismissKeyguard();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (mTaskStackListener != null) {
|
||||
|
||||
@@ -18,7 +18,11 @@ package com.android.server.wm.utils;
|
||||
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.UiAutomation;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.test.uiautomator.UiDevice;
|
||||
|
||||
/** Provides common utility functions. */
|
||||
public class CommonUtils {
|
||||
@@ -34,4 +38,16 @@ public class CommonUtils {
|
||||
getUiAutomation().dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/** Dismisses the Keyguard if it is locked. */
|
||||
public static void dismissKeyguard() {
|
||||
final KeyguardManager keyguardManager = getInstrumentation().getContext().getSystemService(
|
||||
KeyguardManager.class);
|
||||
if (keyguardManager == null || !keyguardManager.isKeyguardLocked()) {
|
||||
return;
|
||||
}
|
||||
final UiDevice device = UiDevice.getInstance(getInstrumentation());
|
||||
device.pressKeyCode(KeyEvent.KEYCODE_WAKEUP);
|
||||
device.pressKeyCode(KeyEvent.KEYCODE_MENU);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user