From aa29be8dda97b0159a7805363dd28a0467a2bd5b Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 3 Oct 2022 15:54:37 -0700 Subject: [PATCH] Use @EnforcePermission for IIMM#isInputMethodPickerShownForTest() This is a follow up CL to my previous CL [1], which locked down IInputMethodManager#isInputMethodPickerShownForTest() with android.Manifest.permission.TEST_INPUT_METHOD permission. After the original CL was committed the severity assessment was performed again and in the updated assessment it was concluded that denial logging was not necessary. With that, this CL simplifies the logic by using @EnforcePermission annotation in the ADIL method definition. Note that there must be no developer-observable behavior change in this CL, and the security test that was added as part of the original effort [2] still verifies that the method in question is indeed guarded with "TEST_INPUT_METHOD" permission. [1]: Ie79a3e9d41ce22605ae083594d639c37d08b7def b869c783808c4d4937727a1672b2fac81bace368 [2]: Idf907e3b762307696a3a7ca11470b0c44b9b7aa4 3e1dd9d2797f818766105247e3634da525fec8e8 Bug: 237317525 Test: atest CtsInputMethodTestCases:InputMethodManagerTest#testIsInputMethodPickerShownProtection Change-Id: Ib3f56b1ab1538742a2bf64fec435ced5b8f90bc2 --- .../internal/view/IInputMethodManager.aidl | 1 + .../inputmethod/InputMethodManagerService.java | 16 +--------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index 9f15469f4046d..f4c3928ac72f6 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -84,6 +84,7 @@ interface IInputMethodManager { void showInputMethodPickerFromSystem(in IInputMethodClient client, int auxiliarySubtypeMode, int displayId); + @EnforcePermission("TEST_INPUT_METHOD") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = " + "android.Manifest.permission.TEST_INPUT_METHOD)") boolean isInputMethodPickerShownForTest(); diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 31e0693ed47c9..0bd8603fda8fb 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -298,8 +298,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final IWindowManager mIWindowManager; private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid = new SparseBooleanArray(0); - private final SparseBooleanArray mLoggedDeniedIsInputMethodPickerShownForTestForUid = - new SparseBooleanArray(0); final WindowManagerInternal mWindowManagerInternal; final PackageManagerInternal mPackageManagerInternal; final InputManagerInternal mInputManagerInternal; @@ -1479,7 +1477,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub public void onUidRemoved(int uid) { synchronized (ImfLock.class) { mLoggedDeniedGetInputMethodWindowVisibleHeightForUid.delete(uid); - mLoggedDeniedIsInputMethodPickerShownForTestForUid.delete(uid); } } @@ -4002,19 +3999,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub /** * A test API for CTS to make sure that the input method menu is showing. */ + @EnforcePermission(Manifest.permission.TEST_INPUT_METHOD) public boolean isInputMethodPickerShownForTest() { - if (mContext.checkCallingPermission(android.Manifest.permission.TEST_INPUT_METHOD) - != PackageManager.PERMISSION_GRANTED) { - final int callingUid = Binder.getCallingUid(); - synchronized (ImfLock.class) { - if (!mLoggedDeniedIsInputMethodPickerShownForTestForUid.get(callingUid)) { - EventLog.writeEvent(0x534e4554, "237317525", callingUid, ""); - mLoggedDeniedIsInputMethodPickerShownForTestForUid.put(callingUid, true); - } - } - throw new SecurityException( - "isInputMethodPickerShownForTest requires TEST_INPUT_METHOD permission"); - } synchronized (ImfLock.class) { return mMenuController.isisInputMethodPickerShownForTestLocked(); }