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

Commit dbb36a15 authored by Arpit Singh's avatar Arpit Singh
Browse files

Throw SecurityException in sanitizeInputFeatures

In this CL existing log and IllegalArgumentException is replaced by the
more relevant SecurityException when sanitising input features in
WindowManaager. This is a followup based on feedback in ag/32693480

Bug: 245989146
Flag: EXEMPT refector
Test: presubmit
Change-Id: I41768220ea487e95d681efa5ccff5dd2950ba1ab
parent c4c56b9a
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -9429,7 +9429,7 @@ public class WindowManagerService extends IWindowManager.Stub
            final int permissionResult = mContext.checkPermission(
                    permission.MONITOR_INPUT, callingPid, callingUid);
            if (permissionResult != PackageManager.PERMISSION_GRANTED) {
                throw new IllegalArgumentException(
                throw new SecurityException(
                        "Cannot use INPUT_FEATURE_SPY from '" + windowName
                                + "' because it doesn't the have MONITOR_INPUT permission");
            }
@@ -9437,9 +9437,8 @@ public class WindowManagerService extends IWindowManager.Stub

        // You can only use INPUT_FEATURE_SENSITIVE_FOR_PRIVACY on a trusted overlay.
        if ((inputFeatures & INPUT_FEATURE_SENSITIVE_FOR_PRIVACY) != 0 && !isTrustedOverlay) {
            Slog.w(TAG, "Removing INPUT_FEATURE_SENSITIVE_FOR_PRIVACY from '" + windowName
                    + "' because it isn't a trusted overlay");
            return inputFeatures & ~INPUT_FEATURE_SENSITIVE_FOR_PRIVACY;
            throw new SecurityException("Cannot use INPUT_FEATURE_SENSITIVE_FOR_PRIVACY from '"
                    + windowName + "' because it isn't a trusted overlay");
        }

        if ((inputFeatures & INPUT_FEATURE_DISPLAY_TOPOLOGY_AWARE) != 0) {
+9 −6
Original line number Diff line number Diff line
@@ -1100,7 +1100,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
        final IBinder window = new Binder();
        final InputTransferToken inputTransferToken = mock(InputTransferToken.class);

        assertThrows(IllegalArgumentException.class, () ->
        assertThrows(SecurityException.class, () ->
                mWm.grantInputChannel(session, callingUid, callingPid, DEFAULT_DISPLAY,
                        surfaceControl, window, null /* hostInputToken */, FLAG_NOT_FOCUSABLE,
                        PRIVATE_FLAG_TRUSTED_OVERLAY, INPUT_FEATURE_SPY, TYPE_APPLICATION,
@@ -1162,7 +1162,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
                eq(surfaceControl),
                argThat(h -> (h.inputConfig & InputConfig.SPY) == 0));

        assertThrows(IllegalArgumentException.class, () ->
        assertThrows(SecurityException.class, () ->
                mWm.updateInputChannel(inputChannel.getToken(), null /* hostInputToken */,
                        DEFAULT_DISPLAY, surfaceControl,
                        FLAG_NOT_FOCUSABLE, PRIVATE_FLAG_TRUSTED_OVERLAY, INPUT_FEATURE_SPY,
@@ -1205,14 +1205,17 @@ public class WindowManagerServiceTests extends WindowTestsBase {
        final IBinder window = new Binder();
        final InputTransferToken inputTransferToken = mock(InputTransferToken.class);

        assertThrows(SecurityException.class, () -> mWm.grantInputChannel(session, callingUid,
                callingPid, DEFAULT_DISPLAY, surfaceControl,
                window, null /* hostInputToken */, FLAG_NOT_FOCUSABLE, 0 /* privateFlags */,
                INPUT_FEATURE_SENSITIVE_FOR_PRIVACY, TYPE_APPLICATION, null /* windowToken */,
                inputTransferToken, "TestInputChannel"));

        final InputChannel inputChannel = mWm.grantInputChannel(session, callingUid, callingPid,
                DEFAULT_DISPLAY, surfaceControl,
                window, null /* hostInputToken */, FLAG_NOT_FOCUSABLE, 0 /* privateFlags */,
                INPUT_FEATURE_SENSITIVE_FOR_PRIVACY, TYPE_APPLICATION, null /* windowToken */,
                0 /* inputFeatures */, TYPE_APPLICATION, null /* windowToken */,
                inputTransferToken, "TestInputChannel");
        verify(mTransaction).setInputWindowInfo(
                eq(surfaceControl),
                argThat(h -> (h.inputConfig & InputConfig.SENSITIVE_FOR_PRIVACY) == 0));

        mWm.updateInputChannel(inputChannel.getToken(), null /* hostInputToken */,
                DEFAULT_DISPLAY, surfaceControl,