Fix restoring animator_duration_scale back to default
WindowManagerService.setAnimationScale() sends an asynchronous message to Handler to persist a setting value, but WindowManagerServiceRule cleans up all remaining messages from Handler when a test finishes. Thus there may be a chance that global animator_duration_scale setting is left unchanged. This CL eliminates removing pending messages and makes them finish instead. Fixes: 121229219 Test: Pass all presubmit tests for Window manager. $ atest --test-mapping frameworks/base/services/core/java/com/android/server/wm $ adb shell settings get global animator_duration_scale 1.0 Change-Id: I97a920cd221d9e0ed3f5cbf2172d9188b39d0ca6
This commit is contained in:
@@ -143,8 +143,8 @@ public class RemoteAnimationControllerTest extends WindowTestsBase {
|
||||
|
||||
@Test
|
||||
public void testTimeout_scaled() throws Exception {
|
||||
mWm.setAnimationScale(2, 5.0f);
|
||||
try {
|
||||
mWm.setAnimationScale(2, 5.0f);
|
||||
final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION,
|
||||
"testWin");
|
||||
final AnimationAdapter adapter = mController.createAnimationAdapter(win.mAppToken,
|
||||
|
||||
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.content.Context;
|
||||
import android.hardware.display.DisplayManagerInternal;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManagerInternal;
|
||||
import android.os.PowerSaveState;
|
||||
import android.view.Display;
|
||||
@@ -54,6 +55,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* A test rule that sets up a fresh WindowManagerService instance before each test and makes sure
|
||||
@@ -193,12 +195,29 @@ public class WindowManagerServiceRule implements TestRule {
|
||||
if (wm == null) {
|
||||
return;
|
||||
}
|
||||
wm.mH.removeCallbacksAndMessages(null);
|
||||
wm.mAnimationHandler.removeCallbacksAndMessages(null);
|
||||
SurfaceAnimationThread.getHandler().removeCallbacksAndMessages(null);
|
||||
wm.mH.runWithScissors(() -> { }, 0);
|
||||
wm.mAnimationHandler.runWithScissors(() -> { }, 0);
|
||||
SurfaceAnimationThread.getHandler().runWithScissors(() -> { }, 0);
|
||||
// Removing delayed FORCE_GC message decreases time for waiting idle.
|
||||
wm.mH.removeMessages(WindowManagerService.H.FORCE_GC);
|
||||
waitHandlerIdle(wm.mH);
|
||||
waitHandlerIdle(wm.mAnimationHandler);
|
||||
waitHandlerIdle(SurfaceAnimationThread.getHandler());
|
||||
}
|
||||
|
||||
private static void waitHandlerIdle(Handler handler) {
|
||||
if (handler.hasMessagesOrCallbacks()) {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
// Wait for delayed messages are processed.
|
||||
handler.getLooper().getQueue().addIdleHandler(() -> {
|
||||
if (handler.hasMessagesOrCallbacks()) {
|
||||
return true; // keep idle handler.
|
||||
}
|
||||
latch.countDown();
|
||||
return false; // remove idle handler.
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void destroyAllSurfaceTransactions() {
|
||||
|
||||
Reference in New Issue
Block a user