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

Commit 42e5b701 authored by Hani Kazmi's avatar Hani Kazmi
Browse files

Cleanup: Block untrusted touches in InputDispatcher

This change removes the BlockUntrustedTouchesMode enum, and related
code, as block_untrusted_touches is now always enforced. Removed code and policy to display a toast when an untrusted touch occurs, as it's no longer used.

Fix: 169067926
Test: atest WindowUntrustedTouchTest
Change-Id: I1f8407f523eb845a7c50a2788553bdb2616a394b
parent 6e27180d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -1252,12 +1252,10 @@ package android.hardware.input {

  public final class InputManager {
    method public void addUniqueIdAssociation(@NonNull String, @NonNull String);
    method public int getBlockUntrustedTouchesMode(@NonNull android.content.Context);
    method @Nullable public String getCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier);
    method @NonNull public java.util.List<java.lang.String> getKeyboardLayoutDescriptorsForInputDevice(@NonNull android.view.InputDevice);
    method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void removeKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
    method public void removeUniqueIdAssociation(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setBlockUntrustedTouchesMode(@NonNull android.content.Context, int);
    method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void setCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setMaximumObscuringOpacityForTouch(@FloatRange(from=0, to=1) float);
    field public static final long BLOCK_UNTRUSTED_TOUCHES = 158002302L; // 0x96aec7eL
+0 −61
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.hardware.lights.LightState;
import android.hardware.lights.LightsManager;
import android.hardware.lights.LightsRequest;
import android.os.Binder;
import android.os.BlockUntrustedTouchesMode;
import android.os.Build;
import android.os.CombinedVibration;
import android.os.Handler;
@@ -67,7 +66,6 @@ import android.view.WindowManager.LayoutParams;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.ArrayUtils;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -87,13 +85,6 @@ public final class InputManager {
    private static final int MSG_DEVICE_REMOVED = 2;
    private static final int MSG_DEVICE_CHANGED = 3;

    /** @hide */
    public static final int[] BLOCK_UNTRUSTED_TOUCHES_MODES = {
            BlockUntrustedTouchesMode.DISABLED,
            BlockUntrustedTouchesMode.PERMISSIVE,
            BlockUntrustedTouchesMode.BLOCK
    };

    private static InputManager sInstance;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
@@ -199,14 +190,6 @@ public final class InputManager {
     */
    public static final float DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH = .8f;

    /**
     * Default mode of the block untrusted touches mode feature.
     * @hide
     */
    @BlockUntrustedTouchesMode
    public static final int DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE =
            BlockUntrustedTouchesMode.BLOCK;

    /**
     * Prevent touches from being consumed by apps if these touches passed through a non-trusted
     * window from a different UID and are considered unsafe.
@@ -1014,50 +997,6 @@ public final class InputManager {
                Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH, opacity);
    }

    /**
     * Returns the current mode of the block untrusted touches feature, one of:
     * <ul>
     *     <li>{@link BlockUntrustedTouchesMode#DISABLED}
     *     <li>{@link BlockUntrustedTouchesMode#PERMISSIVE}
     *     <li>{@link BlockUntrustedTouchesMode#BLOCK}
     * </ul>
     *
     * @hide
     */
    @TestApi
    @BlockUntrustedTouchesMode
    public int getBlockUntrustedTouchesMode(@NonNull Context context) {
        int mode = Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE, DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE);
        if (!ArrayUtils.contains(BLOCK_UNTRUSTED_TOUCHES_MODES, mode)) {
            Log.w(TAG, "Unknown block untrusted touches feature mode " + mode + ", using "
                    + "default " + DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE);
            return DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE;
        }
        return mode;
    }

    /**
     * Sets the mode of the block untrusted touches feature to one of:
     * <ul>
     *     <li>{@link BlockUntrustedTouchesMode#DISABLED}
     *     <li>{@link BlockUntrustedTouchesMode#PERMISSIVE}
     *     <li>{@link BlockUntrustedTouchesMode#BLOCK}
     * </ul>
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
    public void setBlockUntrustedTouchesMode(@NonNull Context context,
            @BlockUntrustedTouchesMode int mode) {
        if (!ArrayUtils.contains(BLOCK_UNTRUSTED_TOUCHES_MODES, mode)) {
            throw new IllegalArgumentException("Invalid feature mode " + mode);
        }
        Settings.Global.putInt(context.getContentResolver(),
                Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE, mode);
    }

    /**
     * Queries the framework about whether any physical keys exist on any currently attached input
     * devices that are capable of producing the given array of key codes.
+0 −16
Original line number Diff line number Diff line
@@ -16884,22 +16884,6 @@ public final class Settings {
         */
        public static final String SHOW_NEW_NOTIF_DISMISS = "show_new_notif_dismiss";
        /**
         * Block untrusted touches mode.
         *
         * Can be one of:
         * <ul>
         *      <li>0 = {@link BlockUntrustedTouchesMode#DISABLED}: Feature is off.
         *      <li>1 = {@link BlockUntrustedTouchesMode#PERMISSIVE}: Untrusted touches are flagged
         *          but not blocked
         *      <li>2 = {@link BlockUntrustedTouchesMode#BLOCK}: Untrusted touches are blocked
         * </ul>
         *
         * @hide
         */
        @Readable
        public static final String BLOCK_UNTRUSTED_TOUCHES_MODE = "block_untrusted_touches";
        /**
         * The maximum allowed obscuring opacity by UID to propagate touches.
         *
+0 −1
Original line number Diff line number Diff line
@@ -156,7 +156,6 @@ public class SettingsBackupTest {
                    Settings.Global.BLE_SCAN_LOW_LATENCY_WINDOW_MS,
                    Settings.Global.BLE_SCAN_LOW_LATENCY_INTERVAL_MS,
                    Settings.Global.BLE_SCAN_BACKGROUND_MODE,
                    Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE,
                    Settings.Global.BLOCKED_SLICES,
                    Settings.Global.BLOCKING_HELPER_DISMISS_TO_VIEW_RATIO_LIMIT,
                    Settings.Global.BLOCKING_HELPER_STREAK_LIMIT,
+0 −49
Original line number Diff line number Diff line
@@ -115,7 +115,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
@@ -171,19 +170,6 @@ public class InputManagerService extends IInputManager.Stub

    private static final int DEFAULT_VIBRATION_MAGNITUDE = 192;

    /**
     * We know the issue and are working to fix it, so suppressing the toast to not annoy
     * dogfooders.
     *
     * TODO(b/169067926): Remove this
     */
    private static final String[] PACKAGE_BLOCKLIST_FOR_UNTRUSTED_TOUCHES_TOAST = {
            "com.snapchat.android" // b/173297887
    };

    /** TODO(b/169067926): Remove this. */
    private static final boolean UNTRUSTED_TOUCHES_TOAST = false;

    private final NativeInputManagerService mNative;

    private final Context mContext;
@@ -462,7 +448,6 @@ public class InputManagerService extends IInputManager.Stub
        registerAccessibilityLargePointerSettingObserver();
        registerLongPressTimeoutObserver();
        registerMaximumObscuringOpacityForTouchSettingObserver();
        registerBlockUntrustedTouchesModeSettingObserver();

        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
@@ -479,7 +464,6 @@ public class InputManagerService extends IInputManager.Stub
        updateAccessibilityLargePointerFromSettings();
        updateDeepPressStatusFromSettings("just booted");
        updateMaximumObscuringOpacityForTouchFromSettings();
        updateBlockUntrustedTouchesModeFromSettings();
    }

    // TODO(BT) Pass in parameter for bluetooth system
@@ -1938,23 +1922,6 @@ public class InputManagerService extends IInputManager.Stub
                }, UserHandle.USER_ALL);
    }

    private void registerBlockUntrustedTouchesModeSettingObserver() {
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE),
                /* notifyForDescendants */ true,
                new ContentObserver(mHandler) {
                    @Override
                    public void onChange(boolean selfChange) {
                        updateBlockUntrustedTouchesModeFromSettings();
                    }
                }, UserHandle.USER_ALL);
    }

    private void updateBlockUntrustedTouchesModeFromSettings() {
        final int mode = InputManager.getInstance().getBlockUntrustedTouchesMode(mContext);
        mNative.setBlockUntrustedTouchesMode(mode);
    }

    private void registerMaximumObscuringOpacityForTouchSettingObserver() {
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH),
@@ -2854,22 +2821,6 @@ public class InputManagerService extends IInputManager.Stub
        mWindowManagerCallbacks.notifyDropWindow(token, x, y);
    }

    // Native callback
    @SuppressWarnings("unused")
    private void notifyUntrustedTouch(String packageName) {
        // TODO(b/169067926): Remove toast after gathering feedback on dogfood.
        if (!UNTRUSTED_TOUCHES_TOAST || ArrayUtils.contains(
                PACKAGE_BLOCKLIST_FOR_UNTRUSTED_TOUCHES_TOAST, packageName)) {
            Log.i(TAG, "Suppressing untrusted touch toast for " + packageName);
            return;
        }
        DisplayThread.getHandler().post(() ->
                Toast.makeText(mContext,
                        "Touch obscured by " + packageName
                                + " will be blocked. Check go/untrusted-touches",
                        Toast.LENGTH_SHORT).show());
    }

    // Native callback.
    @SuppressWarnings("unused")
    private void notifyNoFocusedWindowAnr(InputApplicationHandle inputApplicationHandle) {
Loading