Loading core/java/android/view/inputmethod/InputMethodManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.graphics.Rect; import android.inputmethodservice.InputMethodService; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Handler; Loading Loading @@ -753,10 +754,20 @@ public final class InputMethodManager { throw new IllegalStateException(e); } final InputMethodManager imm = new InputMethodManager(service, displayId, looper); // InputMethodManagerService#addClient() relies on Binder.getCalling{Pid, Uid}() to // associate PID/UID with each IME client. This means: // A. if this method call will be handled as an IPC, there is no problem. // B. if this method call will be handled as an in-proc method call, we need to // ensure that Binder.getCalling{Pid, Uid}() return Process.my{Pid, Uid}() // Either ways we can always call Binder.{clear, restore}CallingIdentity() because // 1) doing so has no effect for A and 2) doing so is sufficient for B. final long identity = Binder.clearCallingIdentity(); try { service.addClient(imm.mClient, imm.mIInputContext, displayId); } catch (RemoteException e) { e.rethrowFromSystemServer(); } finally { Binder.restoreCallingIdentity(identity); } return imm; } Loading services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +7 −1 Original line number Diff line number Diff line Loading @@ -1770,6 +1770,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @Override public void addClient(IInputMethodClient client, IInputContext inputContext, int selfReportedDisplayId) { // Here there are two scenarios where this method is called: // A. IMM is being instantiated in a different process and this is an IPC from that process // B. IMM is being instantiated in the same process but Binder.clearCallingIdentity() is // called in the caller side if necessary. // In either case the following UID/PID should be the ones where InputMethodManager is // actually running. final int callerUid = Binder.getCallingUid(); final int callerPid = Binder.getCallingPid(); synchronized (mMethodMap) { Loading @@ -1778,7 +1784,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (state.uid == callerUid && state.pid == callerPid && state.selfReportedDisplayId == selfReportedDisplayId) { throw new SecurityException("uid=" + callerUid + "/pid=" + callerPid + " is already registered"); + "/displayId=" + selfReportedDisplayId + " is already registered."); } } final ClientDeathRecipient deathRecipient = new ClientDeathRecipient(this, client); Loading Loading
core/java/android/view/inputmethod/InputMethodManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.graphics.Rect; import android.inputmethodservice.InputMethodService; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Handler; Loading Loading @@ -753,10 +754,20 @@ public final class InputMethodManager { throw new IllegalStateException(e); } final InputMethodManager imm = new InputMethodManager(service, displayId, looper); // InputMethodManagerService#addClient() relies on Binder.getCalling{Pid, Uid}() to // associate PID/UID with each IME client. This means: // A. if this method call will be handled as an IPC, there is no problem. // B. if this method call will be handled as an in-proc method call, we need to // ensure that Binder.getCalling{Pid, Uid}() return Process.my{Pid, Uid}() // Either ways we can always call Binder.{clear, restore}CallingIdentity() because // 1) doing so has no effect for A and 2) doing so is sufficient for B. final long identity = Binder.clearCallingIdentity(); try { service.addClient(imm.mClient, imm.mIInputContext, displayId); } catch (RemoteException e) { e.rethrowFromSystemServer(); } finally { Binder.restoreCallingIdentity(identity); } return imm; } Loading
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +7 −1 Original line number Diff line number Diff line Loading @@ -1770,6 +1770,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @Override public void addClient(IInputMethodClient client, IInputContext inputContext, int selfReportedDisplayId) { // Here there are two scenarios where this method is called: // A. IMM is being instantiated in a different process and this is an IPC from that process // B. IMM is being instantiated in the same process but Binder.clearCallingIdentity() is // called in the caller side if necessary. // In either case the following UID/PID should be the ones where InputMethodManager is // actually running. final int callerUid = Binder.getCallingUid(); final int callerPid = Binder.getCallingPid(); synchronized (mMethodMap) { Loading @@ -1778,7 +1784,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (state.uid == callerUid && state.pid == callerPid && state.selfReportedDisplayId == selfReportedDisplayId) { throw new SecurityException("uid=" + callerUid + "/pid=" + callerPid + " is already registered"); + "/displayId=" + selfReportedDisplayId + " is already registered."); } } final ClientDeathRecipient deathRecipient = new ClientDeathRecipient(this, client); Loading