From 06c3998532734b58c0c32d1ae4d5786c764733d7 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 17 Jan 2022 09:34:05 -0800 Subject: [PATCH] Inline InputMethodMenuController.HardKeyboardListener This is a follow up CL to our previous CL [1], which introduced InputMethodManagerService.HardKeyboardListener, which was later moved to InputMethodMenuController.HardKeyboardListener as part of refactoring [2]. This CL mechanically inlines it to InputMethodManagerService as it allows us to achieve the same behavior with fewer lines of code. This is mechanical refactoring. There should be no observable behavior change. [1]: Ica768083f95c33dc1e494a28ba7d8b6eb989b0ef 01038492ff0317f0d3cff54d8a7ee36bb31ff175 [2]: Ief3c691029b14d848f6ad4a5ec8a8743760c7cda c88452c3ee33b8a517881bb2504f5e1c1126372f Bug: 192412909 Test: Manually verified by attaching/detaching a hardware keyboard. Change-Id: I9cce75011a8564c9da8307c5555d87bcba4db2cb --- .../InputMethodManagerService.java | 19 ++++------ .../InputMethodMenuController.java | 36 +++++-------------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 4d125c3ff9977..254fc0aad48e4 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -246,10 +246,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private static final int MSG_SET_INTERACTIVE = 3030; private static final int MSG_REPORT_FULLSCREEN_MODE = 3045; - /** - * package-private because this is also used by {@link InputMethodMenuController}. - */ - static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; + private static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; private static final int MSG_SYSTEM_UNLOCK_USER = 5000; private static final int MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED = 5010; @@ -284,7 +281,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final Context mContext; final Resources mRes; - final Handler mHandler; + private final Handler mHandler; final InputMethodSettings mSettings; final SettingsObserver mSettingsObserver; final IWindowManager mIWindowManager; @@ -1812,10 +1809,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mShowOngoingImeSwitcherForPhones = mRes.getBoolean( com.android.internal.R.bool.show_ongoing_ime_switcher); if (mShowOngoingImeSwitcherForPhones) { - final InputMethodMenuController.HardKeyboardListener hardKeyboardListener = - mMenuController.getHardKeyboardListener(); - mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( - hardKeyboardListener); + mWindowManagerInternal.setOnHardKeyboardStatusChangeListener(available -> { + mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0) + .sendToTarget(); + }); } mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); @@ -4422,9 +4419,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // -------------------------------------------------------------- case MSG_HARD_KEYBOARD_SWITCH_CHANGED: - final InputMethodMenuController.HardKeyboardListener hardKeyboardListener = - mMenuController.getHardKeyboardListener(); - hardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); + mMenuController.handleHardKeyboardStatusChange(msg.arg1 == 1); return true; case MSG_SYSTEM_UNLOCK_USER: { final int userId = msg.arg1; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java index 132be7d11ab1a..fcb1be0fc88ca 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java @@ -18,7 +18,6 @@ package com.android.server.inputmethod; import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; import static com.android.server.inputmethod.InputMethodManagerService.DEBUG; -import static com.android.server.inputmethod.InputMethodManagerService.MSG_HARD_KEYBOARD_SWITCH_CHANGED; import static com.android.server.inputmethod.InputMethodUtils.NOT_A_SUBTYPE_ID; import android.app.ActivityThread; @@ -28,7 +27,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import android.os.Handler; import android.os.IBinder; import android.text.TextUtils; import android.util.ArrayMap; @@ -62,10 +60,8 @@ public class InputMethodMenuController { private final InputMethodManagerService mService; private final InputMethodUtils.InputMethodSettings mSettings; private final InputMethodSubtypeSwitchingController mSwitchingController; - private final Handler mHandler; private final ArrayMap mMethodMap; private final KeyguardManager mKeyguardManager; - private final HardKeyboardListener mHardKeyboardListener; private final WindowManagerInternal mWindowManagerInternal; private Context mSettingsContext; @@ -83,10 +79,8 @@ public class InputMethodMenuController { mService = service; mSettings = mService.mSettings; mSwitchingController = mService.mSwitchingController; - mHandler = mService.mHandler; mMethodMap = mService.mMethodMap; mKeyguardManager = mService.mKeyguardManager; - mHardKeyboardListener = new HardKeyboardListener(); mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); } @@ -271,10 +265,6 @@ public class InputMethodMenuController { } } - HardKeyboardListener getHardKeyboardListener() { - return mHardKeyboardListener; - } - AlertDialog getSwitchingDialogLocked() { return mSwitchingDialog; } @@ -290,24 +280,16 @@ public class InputMethodMenuController { return mSwitchingDialog.isShowing(); } - class HardKeyboardListener implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { - @Override - public void onHardKeyboardStatusChange(boolean available) { - mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, - available ? 1 : 0)); + void handleHardKeyboardStatusChange(boolean available) { + if (DEBUG) { + Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); } - - public void handleHardKeyboardStatusChange(boolean available) { - if (DEBUG) { - Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); - } - synchronized (ImfLock.class) { - if (mSwitchingDialog != null && mSwitchingDialogTitleView != null - && mSwitchingDialog.isShowing()) { - mSwitchingDialogTitleView.findViewById( - com.android.internal.R.id.hard_keyboard_section).setVisibility( - available ? View.VISIBLE : View.GONE); - } + synchronized (ImfLock.class) { + if (mSwitchingDialog != null && mSwitchingDialogTitleView != null + && mSwitchingDialog.isShowing()) { + mSwitchingDialogTitleView.findViewById( + com.android.internal.R.id.hard_keyboard_section).setVisibility( + available ? View.VISIBLE : View.GONE); } } }