Fix CombinationKeyTests failure
The mock context would be reset after init, add more mock enviroment to
prevent tests access wrong state or the apis which need the specific
permission.
Bug: 279233062
Test: atest CombinationKeyTests PowerKeyGestureTests ModifierShortcutTests
Change-Id: I4da8afdb45cca83ce61b92909baf41b1b9e33387
diff --git a/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java b/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java
index 92f00113..9c3b38a 100644
--- a/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java
+++ b/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java
@@ -395,7 +395,7 @@
private class KeyHandler extends Handler {
KeyHandler() {
- super(Looper.getMainLooper());
+ super(Looper.myLooper());
}
@Override
diff --git a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
index 5636795..3513557 100644
--- a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
+++ b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
@@ -202,9 +202,11 @@
.canonicalToCurrentPackageNames(any());
} catch (PackageManager.NameNotFoundException ignored) { }
- doReturn(mTelecomManager).when(mContext).getSystemService(eq(Context.TELECOM_SERVICE));
- doReturn(mNotificationManager).when(mContext)
- .getSystemService(eq(NotificationManager.class));
+ doReturn(false).when(mTelecomManager).isInCall();
+ doReturn(false).when(mTelecomManager).isRinging();
+ doReturn(mTelecomManager).when(mPhoneWindowManager).getTelecommService();
+ doNothing().when(mNotificationManager).silenceNotificationSound();
+ doReturn(mNotificationManager).when(mPhoneWindowManager).getNotificationService();
doReturn(mVibrator).when(mContext).getSystemService(eq(Context.VIBRATOR_SERVICE));
final PowerManager.WakeLock wakeLock = mock(PowerManager.WakeLock.class);
@@ -235,6 +237,7 @@
doNothing().when(mPhoneWindowManager).screenTurnedOn(anyInt());
doNothing().when(mPhoneWindowManager).startedWakingUp(anyInt(), anyInt());
doNothing().when(mPhoneWindowManager).finishedWakingUp(anyInt(), anyInt());
+ doNothing().when(mPhoneWindowManager).lockNow(any());
mPhoneWindowManager.init(new TestInjector(mContext, mWindowManagerFuncsImpl));
mPhoneWindowManager.systemReady();
@@ -249,6 +252,7 @@
void tearDown() {
mHandlerThread.quitSafely();
LocalServices.removeServiceForTest(InputMethodManagerInternal.class);
+ Mockito.reset(mPhoneWindowManager);
mMockitoSession.finishMocking();
}
@@ -322,6 +326,7 @@
void overrideDisplayState(int state) {
doReturn(state).when(mDisplay).getState();
+ doReturn(state == STATE_ON).when(mDisplayPolicy).isAwake();
Mockito.reset(mPowerManager);
}
@@ -388,6 +393,7 @@
}
void assertDreamRequest() {
+ waitForIdle();
verify(mDreamManagerInternal).requestDream();
}