Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6d6411e authored by Daniel Norman's avatar Daniel Norman
Browse files

Fixes canEnableDisableInputMethod to use correct user handle.

The old logic was grabbing the user handle while inside a block that
cleared user identity, so the user handle always returned 0 instead of
the correct user handle.

Fix: 375119534
Test: follow steps in the bug on an HSUM device
Test: atest --user-type secondary_user AccessibilityServiceConnectionTest
Flag: EXEMPT minor bugfix
Change-Id: Id86264284bdfec0b436c01335d979087a8fd099a
parent e0519f2f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -405,10 +405,9 @@ public class AccessibilitySecurityPolicy {
     * @throws SecurityException if the input method is not in the same package as the service.
     */
    @AccessibilityService.SoftKeyboardController.EnableImeResult
    int canEnableDisableInputMethod(String imeId, AbstractAccessibilityServiceConnection service)
            throws SecurityException {
    int canEnableDisableInputMethod(String imeId, AbstractAccessibilityServiceConnection service,
            int callingUserId) throws SecurityException {
        final String servicePackageName = service.getComponentName().getPackageName();
        final int callingUserId = UserHandle.getCallingUserId();

        InputMethodInfo inputMethodInfo = null;
        List<InputMethodInfo> inputMethodInfoList =
+1 −3
Original line number Diff line number Diff line
@@ -410,9 +410,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
        final @AccessibilityService.SoftKeyboardController.EnableImeResult int checkResult;
        final long identity = Binder.clearCallingIdentity();
        try {
            synchronized (mLock) {
                checkResult = mSecurityPolicy.canEnableDisableInputMethod(imeId, this);
            }
            checkResult = mSecurityPolicy.canEnableDisableInputMethod(imeId, this, callingUserId);
            if (checkResult != ENABLE_IME_SUCCESS) {
                return checkResult;
            }
+10 −0
Original line number Diff line number Diff line
@@ -448,4 +448,14 @@ public class AccessibilityServiceConnectionTest {
        mConnection.binderDied();
        assertThat(mConnection.getServiceInfo().flags & flag).isEqualTo(0);
    }

    @Test
    public void setInputMethodEnabled_checksAccessWithProvidedImeIdAndUserId() {
        final String imeId = "test_ime_id";
        final int callingUserId = UserHandle.getCallingUserId();
        mConnection.setInputMethodEnabled(imeId, true);

        verify(mMockSecurityPolicy).canEnableDisableInputMethod(
                eq(imeId), any(), eq(callingUserId));
    }
}