Merge "Remove unnecessary cleanup procedures of WmTests" into rvc-dev am: 009c800f55
Change-Id: I35c95bbe1637e28441be19bf37a1a91dfe898815
This commit is contained in:
@@ -335,7 +335,11 @@ public class SystemServicesTestRule implements TestRule {
|
|||||||
mWmService.mConstants.dispose();
|
mWmService.mConstants.dispose();
|
||||||
mWmService.mHighRefreshRateBlacklist.dispose();
|
mWmService.mHighRefreshRateBlacklist.dispose();
|
||||||
|
|
||||||
|
// This makes sure the posted messages without delay are processed, e.g.
|
||||||
|
// DisplayPolicy#release, WindowManagerService#setAnimationScale.
|
||||||
waitUntilWindowManagerHandlersIdle();
|
waitUntilWindowManagerHandlersIdle();
|
||||||
|
// Clear all posted messages with delay, so they don't be executed at unexpected times.
|
||||||
|
cleanupWindowManagerHandlers();
|
||||||
// Needs to explicitly dispose current static threads because there could be messages
|
// Needs to explicitly dispose current static threads because there could be messages
|
||||||
// scheduled at a later time, and all mocks are invalid when it's executed.
|
// scheduled at a later time, and all mocks are invalid when it's executed.
|
||||||
DisplayThread.dispose();
|
DisplayThread.dispose();
|
||||||
@@ -399,8 +403,6 @@ public class SystemServicesTestRule implements TestRule {
|
|||||||
if (wm == null) {
|
if (wm == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Removing delayed FORCE_GC message decreases time for waiting idle.
|
|
||||||
wm.mH.removeMessages(WindowManagerService.H.FORCE_GC);
|
|
||||||
waitHandlerIdle(wm.mH);
|
waitHandlerIdle(wm.mH);
|
||||||
waitHandlerIdle(wm.mAnimationHandler);
|
waitHandlerIdle(wm.mAnimationHandler);
|
||||||
// This is a different handler object than the wm.mAnimationHandler above.
|
// This is a different handler object than the wm.mAnimationHandler above.
|
||||||
@@ -408,25 +410,8 @@ public class SystemServicesTestRule implements TestRule {
|
|||||||
waitHandlerIdle(SurfaceAnimationThread.getHandler());
|
waitHandlerIdle(SurfaceAnimationThread.getHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitHandlerIdle(Handler handler) {
|
static void waitHandlerIdle(Handler handler) {
|
||||||
synchronized (mCurrentMessagesProcessed) {
|
handler.runWithScissors(() -> { }, 0 /* timeout */);
|
||||||
// Add a message to the handler queue and make sure it is fully processed before we move
|
|
||||||
// on. This makes sure all previous messages in the handler are fully processed vs. just
|
|
||||||
// popping them from the message queue.
|
|
||||||
mCurrentMessagesProcessed.set(false);
|
|
||||||
handler.post(() -> {
|
|
||||||
synchronized (mCurrentMessagesProcessed) {
|
|
||||||
mCurrentMessagesProcessed.set(true);
|
|
||||||
mCurrentMessagesProcessed.notifyAll();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
while (!mCurrentMessagesProcessed.get()) {
|
|
||||||
try {
|
|
||||||
mCurrentMessagesProcessed.wait();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitUntilWindowAnimatorIdle() {
|
void waitUntilWindowAnimatorIdle() {
|
||||||
|
|||||||
@@ -52,13 +52,9 @@ import android.view.WindowManager;
|
|||||||
|
|
||||||
import com.android.server.AttributeCache;
|
import com.android.server.AttributeCache;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common base class for window manager unit test classes.
|
* Common base class for window manager unit test classes.
|
||||||
*
|
*
|
||||||
@@ -85,7 +81,6 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
|||||||
WindowState mAppWindow;
|
WindowState mAppWindow;
|
||||||
WindowState mChildAppWindowAbove;
|
WindowState mChildAppWindowAbove;
|
||||||
WindowState mChildAppWindowBelow;
|
WindowState mChildAppWindowBelow;
|
||||||
HashSet<WindowState> mCommonWindows;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spied {@link Transaction} class than can be used to verify calls.
|
* Spied {@link Transaction} class than can be used to verify calls.
|
||||||
@@ -115,7 +110,6 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
|||||||
mDisplayContent = createNewDisplay(true /* supportIme */);
|
mDisplayContent = createNewDisplay(true /* supportIme */);
|
||||||
|
|
||||||
// Set-up some common windows.
|
// Set-up some common windows.
|
||||||
mCommonWindows = new HashSet<>();
|
|
||||||
synchronized (mWm.mGlobalLock) {
|
synchronized (mWm.mGlobalLock) {
|
||||||
mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
|
mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
|
||||||
mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
|
mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
|
||||||
@@ -151,48 +145,9 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
|||||||
// Called before display is created.
|
// Called before display is created.
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDownBase() {
|
|
||||||
// If @After throws an exception, the error isn't logged. This will make sure any failures
|
|
||||||
// in the tear down are clear. This can be removed when b/37850063 is fixed.
|
|
||||||
try {
|
|
||||||
// Test may schedule to perform surface placement or other messages. Wait until a
|
|
||||||
// stable state to clean up for consistency.
|
|
||||||
waitUntilHandlersIdle();
|
|
||||||
|
|
||||||
final LinkedList<WindowState> nonCommonWindows = new LinkedList<>();
|
|
||||||
|
|
||||||
synchronized (mWm.mGlobalLock) {
|
|
||||||
mWm.mRoot.forAllWindows(w -> {
|
|
||||||
if (!mCommonWindows.contains(w)) {
|
|
||||||
nonCommonWindows.addLast(w);
|
|
||||||
}
|
|
||||||
}, true /* traverseTopToBottom */);
|
|
||||||
|
|
||||||
while (!nonCommonWindows.isEmpty()) {
|
|
||||||
nonCommonWindows.pollLast().removeImmediately();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove app transition & window freeze timeout callbacks to prevent unnecessary
|
|
||||||
// actions after test.
|
|
||||||
mWm.getDefaultDisplayContentLocked().mAppTransition
|
|
||||||
.removeAppTransitionTimeoutCallbacks();
|
|
||||||
mWm.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
|
|
||||||
mDisplayContent.mInputMethodTarget = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleaned up everything in Handler.
|
|
||||||
cleanupWindowManagerHandlers();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "Failed to tear down test", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private WindowState createCommonWindow(WindowState parent, int type, String name) {
|
private WindowState createCommonWindow(WindowState parent, int type, String name) {
|
||||||
synchronized (mWm.mGlobalLock) {
|
synchronized (mWm.mGlobalLock) {
|
||||||
final WindowState win = createWindow(parent, type, name);
|
final WindowState win = createWindow(parent, type, name);
|
||||||
mCommonWindows.add(win);
|
|
||||||
// Prevent common windows from been IMe targets
|
// Prevent common windows from been IMe targets
|
||||||
win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
|
win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
|
||||||
return win;
|
return win;
|
||||||
|
|||||||
Reference in New Issue
Block a user