Restrict getInputMethodWindowVisibleHeight
Make sure only the app currently interacting with the IME can query this, and restrict the API to apps targeting SDKs before T Fixes: 204906124 Test: atest 'InputMethodManagerTest#getInputMethodWindowVisibleHeight_returnsZeroIfNotFocused' Change-Id: If1da19a3dd8c29542afc970b4b201d87547c27a9
This commit is contained in:
@@ -3220,10 +3220,11 @@ public final class InputMethodManager {
|
|||||||
* @return Something that is not well-defined.
|
* @return Something that is not well-defined.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage(trackingBug = 204906124, maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
|
publicAlternatives = "Use {@link android.view.WindowInsets} instead")
|
||||||
public int getInputMethodWindowVisibleHeight() {
|
public int getInputMethodWindowVisibleHeight() {
|
||||||
try {
|
try {
|
||||||
return mService.getInputMethodWindowVisibleHeight();
|
return mService.getInputMethodWindowVisibleHeight(mClient);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ interface IInputMethodManager {
|
|||||||
void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
|
void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
|
||||||
// This is kept due to @UnsupportedAppUsage.
|
// This is kept due to @UnsupportedAppUsage.
|
||||||
// TODO(Bug 113914148): Consider removing this.
|
// TODO(Bug 113914148): Consider removing this.
|
||||||
int getInputMethodWindowVisibleHeight();
|
int getInputMethodWindowVisibleHeight(in IInputMethodClient client);
|
||||||
|
|
||||||
oneway void reportPerceptibleAsync(in IBinder windowToken, boolean perceptible);
|
oneway void reportPerceptibleAsync(in IBinder windowToken, boolean perceptible);
|
||||||
/** Remove the IME surface. Requires INTERNAL_SYSTEM_WINDOW permission. */
|
/** Remove the IME surface. Requires INTERNAL_SYSTEM_WINDOW permission. */
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ import android.util.PrintWriterPrinter;
|
|||||||
import android.util.Printer;
|
import android.util.Printer;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
import android.util.SparseBooleanArray;
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
import android.view.InputChannel;
|
import android.view.InputChannel;
|
||||||
@@ -276,6 +277,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
|
|||||||
final InputMethodSettings mSettings;
|
final InputMethodSettings mSettings;
|
||||||
final SettingsObserver mSettingsObserver;
|
final SettingsObserver mSettingsObserver;
|
||||||
final IWindowManager mIWindowManager;
|
final IWindowManager mIWindowManager;
|
||||||
|
private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid =
|
||||||
|
new SparseBooleanArray(0);
|
||||||
final WindowManagerInternal mWindowManagerInternal;
|
final WindowManagerInternal mWindowManagerInternal;
|
||||||
final PackageManagerInternal mPackageManagerInternal;
|
final PackageManagerInternal mPackageManagerInternal;
|
||||||
final InputManagerInternal mInputManagerInternal;
|
final InputManagerInternal mInputManagerInternal;
|
||||||
@@ -1381,6 +1384,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
|
|||||||
clearPackageChangeState();
|
clearPackageChangeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUidRemoved(int uid) {
|
||||||
|
synchronized (ImfLock.class) {
|
||||||
|
mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.delete(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void clearPackageChangeState() {
|
private void clearPackageChangeState() {
|
||||||
// No need to lock them because we access these fields only on getRegisteredHandler().
|
// No need to lock them because we access these fields only on getRegisteredHandler().
|
||||||
mChangedPackages.clear();
|
mChangedPackages.clear();
|
||||||
@@ -4145,13 +4155,26 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
|
|||||||
* @return {@link WindowManagerInternal#getInputMethodWindowVisibleHeight(int)}
|
* @return {@link WindowManagerInternal#getInputMethodWindowVisibleHeight(int)}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getInputMethodWindowVisibleHeight() {
|
@Deprecated
|
||||||
// TODO(yukawa): Should we verify the display ID?
|
public int getInputMethodWindowVisibleHeight(@NonNull IInputMethodClient client) {
|
||||||
final int curTokenDisplayId;
|
int callingUid = Binder.getCallingUid();
|
||||||
synchronized (ImfLock.class) {
|
return Binder.withCleanCallingIdentity(() -> {
|
||||||
curTokenDisplayId = mCurTokenDisplayId;
|
final int curTokenDisplayId;
|
||||||
}
|
synchronized (ImfLock.class) {
|
||||||
return mWindowManagerInternal.getInputMethodWindowVisibleHeight(curTokenDisplayId);
|
if (!canInteractWithImeLocked(callingUid, client,
|
||||||
|
"getInputMethodWindowVisibleHeight")) {
|
||||||
|
if (!mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.get(callingUid)) {
|
||||||
|
EventLog.writeEvent(0x534e4554, "204906124", callingUid, "");
|
||||||
|
mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.put(callingUid, true);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// This should probably use the caller's display id, but because this is unsupported
|
||||||
|
// and maintained only for compatibility, there's no point in fixing it.
|
||||||
|
curTokenDisplayId = mCurTokenDisplayId;
|
||||||
|
}
|
||||||
|
return mWindowManagerInternal.getInputMethodWindowVisibleHeight(curTokenDisplayId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user