Replace mHandler.sendMessage() with sendToTarget()

This CL mechanically replace

  mHandler.sendMessage(msg)

with

  msg.sendToTarget().

This should be safe because we always use obtain Message objects from
the same Handler object in InputMethodManagerService.

There should be no observable behavior change.

Bug: 192412909
Test: presubmit
Change-Id: I9fa657cfff18c4111e0fad4d4e354c011c368772
This commit is contained in:
Yohei Yukawa
2022-01-24 19:00:36 -08:00
parent 7c46dc83ef
commit 2742a030a6

View File

@@ -1524,8 +1524,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
@Override
public void onUserUnlocking(@NonNull TargetUser user) {
// Called on ActivityManager thread.
mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER,
/* arg1= */ user.getUserIdentifier(), /* arg2= */ 0));
mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER, user.getUserIdentifier(), 0)
.sendToTarget();
}
}
@@ -2221,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.
mHandler.sendMessage(msg);
msg.sendToTarget();
} else {
handleMessage(msg);
msg.recycle();
@@ -3652,9 +3652,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
// Always call subtype picker, because subtype picker is a superset of input method
// picker.
mHandler.sendMessage(mHandler.obtainMessage(
MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode,
(mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY));
final int displayId =
(mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY;
mHandler.obtainMessage(MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId)
.sendToTarget();
}
}
@@ -3669,8 +3670,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
}
// Always call subtype picker, because subtype picker is a superset of input method
// picker.
mHandler.sendMessage(mHandler.obtainMessage(
MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId));
mHandler.obtainMessage(MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId)
.sendToTarget();
}
/**
@@ -3927,7 +3928,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
@Override
public void removeImeSurface() {
mContext.enforceCallingPermission(Manifest.permission.INTERNAL_SYSTEM_WINDOW, null);
mHandler.sendMessage(mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE));
mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE).sendToTarget();
}
@Override
@@ -4959,14 +4960,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
@Override
public void removeImeSurface() {
mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE));
mService.mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE).sendToTarget();
}
@Override
public void updateImeWindowStatus(boolean disableImeIcon) {
mService.mHandler.sendMessage(
mService.mHandler.obtainMessage(MSG_UPDATE_IME_WINDOW_STATUS,
disableImeIcon ? 1 : 0, 0));
mService.mHandler.obtainMessage(MSG_UPDATE_IME_WINDOW_STATUS, disableImeIcon ? 1 : 0, 0)
.sendToTarget();
}
}