summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tadashi G. Takaoka <takaoka@google.com> 2018-12-19 14:11:30 +0900
committer Tadashi G. Takaoka <takaoka@google.com> 2019-01-08 10:54:18 +0900
commit809cbc53e01689872ade84262b581224c9fcbf08 (patch)
tree6c1c69875345203cb78f2843b53f0fda84818b18
parent85a834352c023a159b635789fa2b5ab091dc4e44 (diff)
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
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/RemoteAnimationControllerTest.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java31
2 files changed, 26 insertions, 7 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/RemoteAnimationControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/RemoteAnimationControllerTest.java
index ad2a708b88d9..413b6f4b3905 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RemoteAnimationControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RemoteAnimationControllerTest.java
@@ -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,
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java
index 04e433e98678..cba958682401 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java
@@ -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() {