|
102 | 102 | import android.util.Printer; |
103 | 103 | import android.util.Slog; |
104 | 104 | import android.util.SparseArray; |
| 105 | +import android.util.SparseBooleanArray; |
105 | 106 | import android.view.ContextThemeWrapper; |
106 | 107 | import android.view.DisplayInfo; |
107 | 108 | import android.view.IWindowManager; |
@@ -314,6 +315,8 @@ private static final class DebugFlags { |
314 | 315 | final InputMethodSettings mSettings; |
315 | 316 | final SettingsObserver mSettingsObserver; |
316 | 317 | final IWindowManager mIWindowManager; |
| 318 | + private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid = |
| 319 | + new SparseBooleanArray(0); |
317 | 320 | final WindowManagerInternal mWindowManagerInternal; |
318 | 321 | final PackageManagerInternal mPackageManagerInternal; |
319 | 322 | final InputManagerInternal mInputManagerInternal; |
@@ -1386,6 +1389,13 @@ public void onFinishPackageChanges() { |
1386 | 1389 | clearPackageChangeState(); |
1387 | 1390 | } |
1388 | 1391 |
|
| 1392 | + @Override |
| 1393 | + public void onUidRemoved(int uid) { |
| 1394 | + synchronized (mMethodMap) { |
| 1395 | + mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.delete(uid); |
| 1396 | + } |
| 1397 | + } |
| 1398 | + |
1389 | 1399 | private void clearPackageChangeState() { |
1390 | 1400 | // No need to lock them because we access these fields only on getRegisteredHandler(). |
1391 | 1401 | mChangedPackages.clear(); |
@@ -3134,20 +3144,8 @@ public boolean showSoftInput(IInputMethodClient client, IBinder windowToken, int |
3134 | 3144 | } |
3135 | 3145 | final long ident = Binder.clearCallingIdentity(); |
3136 | 3146 | try { |
3137 | | - if (mCurClient == null || client == null |
3138 | | - || mCurClient.client.asBinder() != client.asBinder()) { |
3139 | | - // We need to check if this is the current client with |
3140 | | - // focus in the window manager, to allow this call to |
3141 | | - // be made before input is started in it. |
3142 | | - final ClientState cs = mClients.get(client.asBinder()); |
3143 | | - if (cs == null) { |
3144 | | - throw new IllegalArgumentException("unknown client " + client.asBinder()); |
3145 | | - } |
3146 | | - if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
3147 | | - cs.selfReportedDisplayId)) { |
3148 | | - Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
3149 | | - return false; |
3150 | | - } |
| 3147 | + if (!canInteractWithImeLocked(uid, client, "showSoftInput")) { |
| 3148 | + return false; |
3151 | 3149 | } |
3152 | 3150 | if (DEBUG) Slog.v(TAG, "Client requesting input be shown"); |
3153 | 3151 | return showCurrentInputLocked(windowToken, flags, resultReceiver, |
@@ -3928,9 +3926,46 @@ public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] |
3928 | 3926 | * @return {@link WindowManagerInternal#getInputMethodWindowVisibleHeight()} |
3929 | 3927 | */ |
3930 | 3928 | @Override |
3931 | | - public int getInputMethodWindowVisibleHeight() { |
3932 | | - // TODO(yukawa): Should we verify the display ID? |
3933 | | - return mWindowManagerInternal.getInputMethodWindowVisibleHeight(mCurTokenDisplayId); |
| 3929 | + @Deprecated |
| 3930 | + public int getInputMethodWindowVisibleHeight(@NonNull IInputMethodClient client) { |
| 3931 | + int callingUid = Binder.getCallingUid(); |
| 3932 | + return Binder.withCleanCallingIdentity(() -> { |
| 3933 | + final int curTokenDisplayId; |
| 3934 | + synchronized (mMethodMap) { |
| 3935 | + if (!canInteractWithImeLocked(callingUid, client, |
| 3936 | + "getInputMethodWindowVisibleHeight")) { |
| 3937 | + if (!mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.get(callingUid)) { |
| 3938 | + EventLog.writeEvent(0x534e4554, "204906124", callingUid, ""); |
| 3939 | + mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.put(callingUid, true); |
| 3940 | + } |
| 3941 | + return 0; |
| 3942 | + } |
| 3943 | + // This should probably use the caller's display id, but because this is unsupported |
| 3944 | + // and maintained only for compatibility, there's no point in fixing it. |
| 3945 | + curTokenDisplayId = mCurTokenDisplayId; |
| 3946 | + } |
| 3947 | + return mWindowManagerInternal.getInputMethodWindowVisibleHeight(curTokenDisplayId); |
| 3948 | + }); |
| 3949 | + } |
| 3950 | + |
| 3951 | + private boolean canInteractWithImeLocked(int callingUid, IInputMethodClient client, |
| 3952 | + String method) { |
| 3953 | + if (mCurClient == null || client == null |
| 3954 | + || mCurClient.client.asBinder() != client.asBinder()) { |
| 3955 | + // We need to check if this is the current client with |
| 3956 | + // focus in the window manager, to allow this call to |
| 3957 | + // be made before input is started in it. |
| 3958 | + final ClientState cs = mClients.get(client.asBinder()); |
| 3959 | + if (cs == null) { |
| 3960 | + throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 3961 | + } |
| 3962 | + if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 3963 | + cs.selfReportedDisplayId)) { |
| 3964 | + Slog.w(TAG, "Ignoring " + method + " of uid " + callingUid + ": " + client); |
| 3965 | + return false; |
| 3966 | + } |
| 3967 | + } |
| 3968 | + return true; |
3934 | 3969 | } |
3935 | 3970 |
|
3936 | 3971 | @Override |
|
0 commit comments