Remove InputMethodManagerService#mCaller
Having both HandlerCaller and Handler in InputMethodManagerService has confused us especially about which one should be used to obtain a Message object. This is really confusing when a Message can be removed with .removeMessages() because it behaves like each Handler has its own namespace. Let's unify our usages into Handler in favor of simplicity. This CL changes nothing in terms of how InputMethodManagerService behaves unless there was any misuse of removeMessages() and we had relied on such a bug. Bug: 192412909 Test: presubmit Change-Id: I63a3d0015ddc937f5f6928cebcad893c75e7863c
This commit is contained in:
@@ -160,7 +160,6 @@ import com.android.internal.inputmethod.StartInputReason;
|
||||
import com.android.internal.inputmethod.UnbindReason;
|
||||
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
|
||||
import com.android.internal.notification.SystemNotificationChannels;
|
||||
import com.android.internal.os.HandlerCaller;
|
||||
import com.android.internal.os.SomeArgs;
|
||||
import com.android.internal.os.TransferPipe;
|
||||
import com.android.internal.util.DumpUtils;
|
||||
@@ -270,7 +269,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
final WindowManagerInternal mWindowManagerInternal;
|
||||
final PackageManagerInternal mPackageManagerInternal;
|
||||
final InputManagerInternal mInputManagerInternal;
|
||||
private final HandlerCaller mCaller;
|
||||
final boolean mHasFeature;
|
||||
private final ArrayMap<String, List<InputMethodSubtype>> mAdditionalSubtypeMap =
|
||||
new ArrayMap<>();
|
||||
@@ -1587,8 +1585,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
|
||||
mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
|
||||
mImeDisplayValidator = mWindowManagerInternal::getDisplayImePolicy;
|
||||
mCaller = new HandlerCaller(context, thread.getLooper(), this::handleMessage,
|
||||
true /*asyncHandler*/);
|
||||
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
|
||||
mUserManager = mContext.getSystemService(UserManager.class);
|
||||
mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
|
||||
@@ -2199,6 +2195,24 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Message obtainMessageOO(int what, Object arg1, Object arg2) {
|
||||
final SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = arg1;
|
||||
args.arg2 = arg2;
|
||||
return mHandler.obtainMessage(what, 0, 0, args);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Message obtainMessageIIIO(int what, int argi1, int argi2, int argi3, Object arg1) {
|
||||
final SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = arg1;
|
||||
args.argi1 = argi1;
|
||||
args.argi2 = argi2;
|
||||
args.argi3 = argi3;
|
||||
return mHandler.obtainMessage(what, 0, 0, args);
|
||||
}
|
||||
|
||||
private void executeOrSendMessage(IInputMethodClient target, Message msg) {
|
||||
if (target.asBinder() instanceof Binder) {
|
||||
// This is supposed to be emulating the one-way semantics when the IME client is
|
||||
@@ -2207,7 +2221,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
// We probably should create a simple wrapper of IInputMethodClient as the first step
|
||||
// to get rid of executeOrSendMessage() then should prohibit system_server to be the
|
||||
// IME client for long term.
|
||||
mCaller.sendMessage(msg);
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
handleMessage(msg);
|
||||
msg.recycle();
|
||||
@@ -2229,7 +2243,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
|
||||
scheduleSetActiveToClient(mCurClient, false /* active */, false /* fullscreen */,
|
||||
false /* reportToImeController */);
|
||||
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO(
|
||||
executeOrSendMessage(mCurClient.client, mHandler.obtainMessage(
|
||||
MSG_UNBIND_CLIENT, getSequenceNumberLocked(), unbindClientReason,
|
||||
mCurClient.client));
|
||||
mCurClient.sessionRequested = false;
|
||||
@@ -2506,8 +2520,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
|
||||
@AnyThread
|
||||
void scheduleNotifyImeUidToAudioService(int uid) {
|
||||
mCaller.removeMessages(MSG_NOTIFY_IME_UID_TO_AUDIO_SERVICE);
|
||||
mCaller.obtainMessageI(MSG_NOTIFY_IME_UID_TO_AUDIO_SERVICE, uid).sendToTarget();
|
||||
mHandler.removeMessages(MSG_NOTIFY_IME_UID_TO_AUDIO_SERVICE);
|
||||
mHandler.obtainMessage(MSG_NOTIFY_IME_UID_TO_AUDIO_SERVICE, uid, 0 /* unused */)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@BinderThread
|
||||
@@ -2532,7 +2547,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
InputBindResult res = attachNewInputLocked(
|
||||
StartInputReason.SESSION_CREATED_BY_IME, true);
|
||||
if (res.method != null) {
|
||||
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
|
||||
executeOrSendMessage(mCurClient.client, obtainMessageOO(
|
||||
MSG_BIND_CLIENT, mCurClient.client, res));
|
||||
}
|
||||
return;
|
||||
@@ -3637,7 +3652,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
|
||||
// Always call subtype picker, because subtype picker is a superset of input method
|
||||
// picker.
|
||||
mHandler.sendMessage(mCaller.obtainMessageII(
|
||||
mHandler.sendMessage(mHandler.obtainMessage(
|
||||
MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode,
|
||||
(mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY));
|
||||
}
|
||||
@@ -3654,7 +3669,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
}
|
||||
// Always call subtype picker, because subtype picker is a superset of input method
|
||||
// picker.
|
||||
mHandler.sendMessage(mCaller.obtainMessageII(
|
||||
mHandler.sendMessage(mHandler.obtainMessage(
|
||||
MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId));
|
||||
}
|
||||
|
||||
@@ -4380,8 +4395,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
|
||||
private void scheduleSetActiveToClient(ClientState state, boolean active, boolean fullscreen,
|
||||
boolean reportToImeController) {
|
||||
executeOrSendMessage(state.client, mCaller.obtainMessageIIIIO(MSG_SET_ACTIVE,
|
||||
active ? 1 : 0, fullscreen ? 1 : 0, reportToImeController ? 1 : 0, 0, state));
|
||||
executeOrSendMessage(state.client, obtainMessageIIIO(MSG_SET_ACTIVE,
|
||||
active ? 1 : 0, fullscreen ? 1 : 0, reportToImeController ? 1 : 0, state));
|
||||
}
|
||||
|
||||
@GuardedBy("ImfLock.class")
|
||||
@@ -5017,8 +5032,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
}
|
||||
if (mCurClient != null && mCurClient.client != null) {
|
||||
mInFullscreenMode = fullscreen;
|
||||
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
|
||||
MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient));
|
||||
executeOrSendMessage(mCurClient.client, mHandler.obtainMessage(
|
||||
MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, 0 /* unused */,
|
||||
mCurClient));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user