diff options
10 files changed, 97 insertions, 66 deletions
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl index 3977666627b7..fc60f065a965 100644 --- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl +++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl @@ -90,7 +90,7 @@ interface IStatusBarService void onNotificationSettingsViewed(String key); void onNotificationBubbleChanged(String key, boolean isBubble, int flags); void onBubbleMetadataFlagChanged(String key, int flags); - void hideCurrentInputMethodForBubbles(); + void hideCurrentInputMethodForBubbles(int displayId); void grantInlineReplyUriPermission(String key, in Uri uri, in UserHandle user, String packageName); oneway void clearInlineReplyUriPermissions(String key); void onNotificationFeedbackReceived(String key, in Bundle feedback); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java index f0da35df39ee..3e113276027e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java @@ -553,8 +553,9 @@ public class BubbleController implements ConfigurationChangeListener, * Hides the current input method, wherever it may be focused, via InputMethodManagerInternal. */ void hideCurrentInputMethod() { + int displayId = mWindowManager.getDefaultDisplay().getDisplayId(); try { - mBarService.hideCurrentInputMethodForBubbles(); + mBarService.hideCurrentInputMethodForBubbles(displayId); } catch (RemoteException e) { e.printStackTrace(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java index aa5f987b22a8..df7609c544a4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -78,6 +78,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.util.Pair; import android.util.SparseArray; +import android.view.Display; import android.view.IWindowManager; import android.view.View; import android.view.ViewTreeObserver; @@ -337,6 +338,8 @@ public class BubblesTest extends SysuiTestCase { private NotifPipelineFlags mNotifPipelineFlags; @Mock private Icon mAppBubbleIcon; + @Mock + private Display mDefaultDisplay; private final SceneTestUtils mUtils = new SceneTestUtils(this); private final TestScope mTestScope = mUtils.getTestScope(); @@ -378,6 +381,7 @@ public class BubblesTest extends SysuiTestCase { when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors); when(mNotificationShadeWindowView.getViewTreeObserver()) .thenReturn(mock(ViewTreeObserver.class)); + when(mWindowManager.getDefaultDisplay()).thenReturn(mDefaultDisplay); FakeDeviceProvisioningRepository deviceProvisioningRepository = diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java index a46d7197100f..14daf62a9ed2 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java @@ -56,9 +56,13 @@ public abstract class InputMethodManagerInternal { public abstract void setInteractive(boolean interactive); /** - * Hides the current input method, if visible. + * Hides the input methods for all the users, if visible. + * + * @param reason the reason for hiding the current input method + * @param originatingDisplayId the display ID the request is originated */ - public abstract void hideCurrentInputMethod(@SoftInputShowHideReason int reason); + public abstract void hideAllInputMethods(@SoftInputShowHideReason int reason, + int originatingDisplayId); /** * Returns the list of installed input methods for the specified user. @@ -210,7 +214,8 @@ public abstract class InputMethodManagerInternal { } @Override - public void hideCurrentInputMethod(@SoftInputShowHideReason int reason) { + public void hideAllInputMethods(@SoftInputShowHideReason int reason, + int originatingDisplayId) { } @Override diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 6cc069377bf2..ddb32fe09d6c 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -226,7 +226,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub private static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; - private static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; + private static final int MSG_HIDE_ALL_INPUT_METHODS = 1035; private static final int MSG_REMOVE_IME_SURFACE = 1060; private static final int MSG_REMOVE_IME_SURFACE_FROM_WINDOW = 1061; private static final int MSG_UPDATE_IME_WINDOW_STATUS = 1070; @@ -4835,7 +4835,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // --------------------------------------------------------- - case MSG_HIDE_CURRENT_INPUT_METHOD: + case MSG_HIDE_ALL_INPUT_METHODS: synchronized (ImfLock.class) { final @SoftInputShowHideReason int reason = (int) msg.obj; hideCurrentInputLocked(mCurFocusedWindow, null /* statsToken */, 0 /* flags */, @@ -5591,9 +5591,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } @Override - public void hideCurrentInputMethod(@SoftInputShowHideReason int reason) { - mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD); - mHandler.obtainMessage(MSG_HIDE_CURRENT_INPUT_METHOD, reason).sendToTarget(); + public void hideAllInputMethods(@SoftInputShowHideReason int reason, + int originatingDisplayId) { + mHandler.removeMessages(MSG_HIDE_ALL_INPUT_METHODS); + mHandler.obtainMessage(MSG_HIDE_ALL_INPUT_METHODS, reason).sendToTarget(); } @Override diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 72c10cc9a5e8..1cf82bde633d 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -1073,7 +1073,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } - private void powerPress(long eventTime, int count) { + private void powerPress(long eventTime, int count, int displayId) { // SideFPS still needs to know about suppressed power buttons, in case it needs to block // an auth attempt. if (count == 1) { @@ -1126,8 +1126,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { break; case SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME: { if (mDismissImeOnBackKeyPressed) { - InputMethodManagerInternal.get().hideCurrentInputMethod( - SoftInputShowHideReason.HIDE_POWER_BUTTON_GO_HOME); + // TODO(b/308479256): Check if hiding "all" IMEs is OK or not. + InputMethodManagerInternal.get().hideAllInputMethods( + SoftInputShowHideReason.HIDE_POWER_BUTTON_GO_HOME, displayId); } else { shortPressPowerGoHome(); } @@ -2662,11 +2663,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { } @Override - void onPress(long downTime) { + void onPress(long downTime, int displayId) { if (mShouldEarlyShortPressOnPower) { return; } - powerPress(downTime, 1 /*count*/); + powerPress(downTime, 1 /*count*/, displayId); } @Override @@ -2696,14 +2697,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { } @Override - void onMultiPress(long downTime, int count) { - powerPress(downTime, count); + void onMultiPress(long downTime, int count, int displayId) { + powerPress(downTime, count, displayId); } @Override - void onKeyUp(long eventTime, int count) { + void onKeyUp(long eventTime, int count, int displayId) { if (mShouldEarlyShortPressOnPower && count == 1) { - powerPress(eventTime, 1 /*pressCount*/); + powerPress(eventTime, 1 /*pressCount*/, displayId); } } } @@ -2727,7 +2728,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } @Override - void onPress(long downTime) { + void onPress(long downTime, int unusedDisplayId) { mBackKeyHandled |= backKeyPress(); } @@ -2756,7 +2757,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } @Override - void onPress(long downTime) { + void onPress(long downTime, int unusedDisplayId) { if (mShouldEarlyShortPressOnStemPrimary) { return; } @@ -2769,12 +2770,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { } @Override - void onMultiPress(long downTime, int count) { + void onMultiPress(long downTime, int count, int unusedDisplayId) { stemPrimaryPress(count); } @Override - void onKeyUp(long eventTime, int count) { + void onKeyUp(long eventTime, int count, int unusedDisplayId) { if (count == 1) { // Save info about the most recent task on the first press of the stem key. This // may be used later to switch to the most recent app using double press gesture. diff --git a/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java b/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java index 047555ae491c..a060f504b809 100644 --- a/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java +++ b/services/core/java/com/android/server/policy/SingleKeyGestureDetector.java @@ -66,10 +66,12 @@ public final class SingleKeyGestureDetector { * SingleKeyRule rule = * new SingleKeyRule(KEYCODE_POWER, KEY_LONGPRESS|KEY_VERYLONGPRESS) { * int getMaxMultiPressCount() { // maximum multi press count. } - * void onPress(long downTime) { // short press behavior. } + * void onPress(long downTime, int displayId) { // short press behavior. } * void onLongPress(long eventTime) { // long press behavior. } * void onVeryLongPress(long eventTime) { // very long press behavior. } - * void onMultiPress(long downTime, int count) { // multi press behavior. } + * void onMultiPress(long downTime, int count, int displayId) { + * // multi press behavior. + * } * }; * </pre> */ @@ -114,11 +116,11 @@ public final class SingleKeyGestureDetector { /** * Called when short press has been detected. */ - abstract void onPress(long downTime); + abstract void onPress(long downTime, int displayId); /** * Callback when multi press (>= 2) has been detected. */ - void onMultiPress(long downTime, int count) {} + void onMultiPress(long downTime, int count, int displayId) {} /** * Returns the timeout in milliseconds for a long press. * @@ -148,10 +150,11 @@ public final class SingleKeyGestureDetector { /** * Callback executed upon each key up event that hasn't been processed by long press. * - * @param eventTime the timestamp of this event. - * @param pressCount the number of presses detected leading up to this key up event. + * @param eventTime the timestamp of this event + * @param pressCount the number of presses detected leading up to this key up event + * @param displayId the display ID of the event */ - void onKeyUp(long eventTime, int pressCount) {} + void onKeyUp(long eventTime, int pressCount, int displayId) {} @Override public String toString() { @@ -179,6 +182,10 @@ public final class SingleKeyGestureDetector { } } + private record MessageObject(SingleKeyRule activeRule, int keyCode, int pressCount, + int displayId) { + } + static SingleKeyGestureDetector get(Context context, Looper looper) { SingleKeyGestureDetector detector = new SingleKeyGestureDetector(looper); sDefaultLongPressTimeout = context.getResources().getInteger( @@ -228,8 +235,9 @@ public final class SingleKeyGestureDetector { mHandledByLongPress = true; mHandler.removeMessages(MSG_KEY_LONG_PRESS); mHandler.removeMessages(MSG_KEY_VERY_LONG_PRESS); - final Message msg = mHandler.obtainMessage(MSG_KEY_LONG_PRESS, keyCode, 0, - mActiveRule); + MessageObject object = new MessageObject(mActiveRule, keyCode, /* pressCount= */ 1, + event.getDisplayId()); + final Message msg = mHandler.obtainMessage(MSG_KEY_LONG_PRESS, object); msg.setAsynchronous(true); mHandler.sendMessage(msg); } @@ -275,15 +283,17 @@ public final class SingleKeyGestureDetector { if (mKeyPressCounter == 1) { if (mActiveRule.supportLongPress()) { - final Message msg = mHandler.obtainMessage(MSG_KEY_LONG_PRESS, keyCode, 0, - mActiveRule); + MessageObject object = new MessageObject(mActiveRule, keyCode, mKeyPressCounter, + event.getDisplayId()); + final Message msg = mHandler.obtainMessage(MSG_KEY_LONG_PRESS, object); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, mActiveRule.getLongPressTimeoutMs()); } if (mActiveRule.supportVeryLongPress()) { - final Message msg = mHandler.obtainMessage(MSG_KEY_VERY_LONG_PRESS, keyCode, 0, - mActiveRule); + MessageObject object = new MessageObject(mActiveRule, keyCode, mKeyPressCounter, + event.getDisplayId()); + final Message msg = mHandler.obtainMessage(MSG_KEY_VERY_LONG_PRESS, object); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, mActiveRule.getVeryLongPressTimeoutMs()); } @@ -299,8 +309,9 @@ public final class SingleKeyGestureDetector { Log.i(TAG, "Trigger multi press " + mActiveRule.toString() + " for it" + " reached the max count " + mKeyPressCounter); } - final Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, keyCode, - mKeyPressCounter, mActiveRule); + MessageObject object = new MessageObject(mActiveRule, keyCode, mKeyPressCounter, + event.getDisplayId()); + final Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, object); msg.setAsynchronous(true); mHandler.sendMessage(msg); } @@ -339,9 +350,9 @@ public final class SingleKeyGestureDetector { if (event.getKeyCode() == mActiveRule.mKeyCode) { // key-up action should always be triggered if not processed by long press. - Message msgKeyUp = - mHandler.obtainMessage( - MSG_KEY_UP, mActiveRule.mKeyCode, mKeyPressCounter, mActiveRule); + MessageObject object = new MessageObject(mActiveRule, mActiveRule.mKeyCode, + mKeyPressCounter, event.getDisplayId()); + Message msgKeyUp = mHandler.obtainMessage(MSG_KEY_UP, object); msgKeyUp.setAsynchronous(true); mHandler.sendMessage(msgKeyUp); @@ -350,8 +361,9 @@ public final class SingleKeyGestureDetector { if (DEBUG) { Log.i(TAG, "press key " + KeyEvent.keyCodeToString(event.getKeyCode())); } - Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, mActiveRule.mKeyCode, - 1, mActiveRule); + object = new MessageObject(mActiveRule, mActiveRule.mKeyCode, + /* pressCount= */ 1, event.getDisplayId()); + Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, object); msg.setAsynchronous(true); mHandler.sendMessage(msg); mActiveRule = null; @@ -360,8 +372,9 @@ public final class SingleKeyGestureDetector { // This could be a multi-press. Wait a little bit longer to confirm. if (mKeyPressCounter < mActiveRule.getMaxMultiPressCount()) { - Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, mActiveRule.mKeyCode, - mKeyPressCounter, mActiveRule); + object = new MessageObject(mActiveRule, mActiveRule.mKeyCode, + mKeyPressCounter, event.getDisplayId()); + Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, object); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, MULTI_PRESS_TIMEOUT); } @@ -423,20 +436,23 @@ public final class SingleKeyGestureDetector { @Override public void handleMessage(Message msg) { - final SingleKeyRule rule = (SingleKeyRule) msg.obj; + final MessageObject object = (MessageObject) msg.obj; + final SingleKeyRule rule = object.activeRule; if (rule == null) { Log.wtf(TAG, "No active rule."); return; } - final int keyCode = msg.arg1; - final int pressCount = msg.arg2; + final int keyCode = object.keyCode; + final int pressCount = object.pressCount; + final int displayId = object.displayId; switch(msg.what) { case MSG_KEY_UP: if (DEBUG) { - Log.i(TAG, "Detect key up " + KeyEvent.keyCodeToString(keyCode)); + Log.i(TAG, "Detect key up " + KeyEvent.keyCodeToString(keyCode) + + " on display " + displayId); } - rule.onKeyUp(mLastDownTime, pressCount); + rule.onKeyUp(mLastDownTime, pressCount, displayId); break; case MSG_KEY_LONG_PRESS: if (DEBUG) { @@ -454,12 +470,12 @@ public final class SingleKeyGestureDetector { case MSG_KEY_DELAYED_PRESS: if (DEBUG) { Log.i(TAG, "Detect press " + KeyEvent.keyCodeToString(keyCode) - + ", count " + pressCount); + + " on display " + displayId + ", count " + pressCount); } if (pressCount == 1) { - rule.onPress(mLastDownTime); + rule.onPress(mLastDownTime, displayId); } else { - rule.onMultiPress(mLastDownTime, pressCount); + rule.onMultiPress(mLastDownTime, pressCount, displayId); } break; } diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java index 3fd832376d2b..7c51e7b84132 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java @@ -1836,12 +1836,13 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D } @Override - public void hideCurrentInputMethodForBubbles() { + public void hideCurrentInputMethodForBubbles(int displayId) { enforceStatusBarService(); final long token = Binder.clearCallingIdentity(); try { - InputMethodManagerInternal.get().hideCurrentInputMethod( - SoftInputShowHideReason.HIDE_BUBBLES); + // TODO(b/308479256): Check if hiding "all" IMEs is OK or not. + InputMethodManagerInternal.get().hideAllInputMethods( + SoftInputShowHideReason.HIDE_BUBBLES, displayId); } finally { Binder.restoreCallingIdentity(token); } diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index 997b6084f6e2..14912d041127 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -439,8 +439,10 @@ final class InputMonitor { final InputMethodManagerInternal inputMethodManagerInternal = LocalServices.getService(InputMethodManagerInternal.class); if (inputMethodManagerInternal != null) { - inputMethodManagerInternal.hideCurrentInputMethod( - SoftInputShowHideReason.HIDE_RECENTS_ANIMATION); + // TODO(b/308479256): Check if hiding "all" IMEs is OK or not. + inputMethodManagerInternal.hideAllInputMethods( + SoftInputShowHideReason.HIDE_RECENTS_ANIMATION, + mDisplayContent.getDisplayId()); } // Ensure removing the IME snapshot when the app no longer to show on the // task snapshot (also taking the new task snaphot to update the overview). diff --git a/services/tests/wmtests/src/com/android/server/policy/SingleKeyGestureTests.java b/services/tests/wmtests/src/com/android/server/policy/SingleKeyGestureTests.java index f2721a556454..7ea5010976ee 100644 --- a/services/tests/wmtests/src/com/android/server/policy/SingleKeyGestureTests.java +++ b/services/tests/wmtests/src/com/android/server/policy/SingleKeyGestureTests.java @@ -30,9 +30,9 @@ import static org.junit.Assert.assertTrue; import android.app.Instrumentation; import android.content.Context; -import android.os.Looper; import android.os.Handler; import android.os.HandlerThread; +import android.os.Looper; import android.os.Process; import android.os.SystemClock; import android.view.KeyEvent; @@ -109,7 +109,7 @@ public class SingleKeyGestureTests { } @Override - public void onPress(long downTime) { + public void onPress(long downTime, int displayId) { if (mDetector.beganFromNonInteractive() && !mAllowNonInteractiveForPress) { return; } @@ -131,7 +131,7 @@ public class SingleKeyGestureTests { } @Override - void onMultiPress(long downTime, int count) { + void onMultiPress(long downTime, int count, int displayId) { if (mDetector.beganFromNonInteractive() && !mAllowNonInteractiveForPress) { return; } @@ -141,7 +141,7 @@ public class SingleKeyGestureTests { } @Override - void onKeyUp(long eventTime, int multiPressCount) { + void onKeyUp(long eventTime, int multiPressCount, int displayId) { mKeyUpQueue.add(new KeyUpData(KEYCODE_POWER, multiPressCount)); } }); @@ -159,7 +159,7 @@ public class SingleKeyGestureTests { } @Override - public void onPress(long downTime) { + public void onPress(long downTime, int displayId) { if (mDetector.beganFromNonInteractive() && !mAllowNonInteractiveForPress) { return; } @@ -167,7 +167,7 @@ public class SingleKeyGestureTests { } @Override - void onMultiPress(long downTime, int count) { + void onMultiPress(long downTime, int count, int displayId) { if (mDetector.beganFromNonInteractive() && !mAllowNonInteractiveForPress) { return; } @@ -177,7 +177,7 @@ public class SingleKeyGestureTests { } @Override - void onKeyUp(long eventTime, int multiPressCount) { + void onKeyUp(long eventTime, int multiPressCount, int displayId) { mKeyUpQueue.add(new KeyUpData(KEYCODE_BACK, multiPressCount)); } @@ -398,7 +398,7 @@ public class SingleKeyGestureTests { final SingleKeyGestureDetector.SingleKeyRule rule = new SingleKeyGestureDetector.SingleKeyRule(KEYCODE_POWER) { @Override - void onPress(long downTime) { + void onPress(long downTime, int displayId) { mShortPressed.countDown(); } }; |