From 97f0a783385dedea1de246016869a9cfe16dbfd7 Mon Sep 17 00:00:00 2001 From: Bernardo Rufino Date: Mon, 18 Jan 2021 11:24:46 +0000 Subject: [PATCH] Open IM.getMaximumObscuringOpacityForTouch() and update docs. Bug: 158002302 Test: atest WindowUntrustedTouchTest Change-Id: I735169e0508678e07431704f184a938ffada53cc --- core/api/current.txt | 1 + core/api/test-current.txt | 3 +-- .../android/hardware/input/InputManager.java | 23 ++++++++++--------- core/java/android/provider/Settings.java | 5 ++-- core/java/android/view/WindowManager.java | 17 ++++++++++---- .../server/input/InputManagerService.java | 3 +-- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index e0e2762cdd569..b3cb0bedd279c 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -18443,6 +18443,7 @@ package android.hardware.input { public final class InputManager { method public android.view.InputDevice getInputDevice(int); method public int[] getInputDeviceIds(); + method public float getMaximumObscuringOpacityForTouch(); method public void registerInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener, android.os.Handler); method public void unregisterInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener); method @Nullable public android.view.VerifiedInputEvent verifyInputEvent(@NonNull android.view.InputEvent); diff --git a/core/api/test-current.txt b/core/api/test-current.txt index d6abbeca44808..11168e4f8d4e9 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -922,9 +922,8 @@ package android.hardware.input { public final class InputManager { method public int getBlockUntrustedTouchesMode(@NonNull android.content.Context); - method public float getMaximumObscuringOpacityForTouch(@NonNull android.content.Context); method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setBlockUntrustedTouchesMode(@NonNull android.content.Context, int); - method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setMaximumObscuringOpacityForTouch(@NonNull android.content.Context, float); + method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setMaximumObscuringOpacityForTouch(float); field public static final long BLOCK_UNTRUSTED_TOUCHES = 158002302L; // 0x96aec7eL } diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 6ab11068aac7c..e63dc112233f8 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -25,6 +25,7 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemService; import android.annotation.TestApi; +import android.app.ActivityThread; import android.compat.annotation.ChangeId; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -909,18 +910,17 @@ public final class InputManager { } /** - * Returns the maximum allowed obscuring opacity by UID to propagate touches. + * Returns the maximum allowed obscuring opacity per UID to propagate touches. * - * For certain window types (eg. SAWs), the decision of honoring {@link LayoutParams - * #FLAG_NOT_TOUCHABLE} or not depends on the combined obscuring opacity of the windows - * above the touch-consuming window. + *

For certain window types (eg. {@link LayoutParams#TYPE_APPLICATION_OVERLAY}), the decision + * of honoring {@link LayoutParams#FLAG_NOT_TOUCHABLE} or not depends on the combined obscuring + * opacity of the windows above the touch-consuming window, per UID. Check documentation of + * {@link LayoutParams#FLAG_NOT_TOUCHABLE} for more details. * - * @see #setMaximumObscuringOpacityForTouch(Context, float) - * - * @hide + * @see LayoutParams#FLAG_NOT_TOUCHABLE */ - @TestApi - public float getMaximumObscuringOpacityForTouch(@NonNull Context context) { + public float getMaximumObscuringOpacityForTouch() { + Context context = ActivityThread.currentApplication(); return Settings.Global.getFloat(context.getContentResolver(), Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH, DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH); @@ -946,17 +946,18 @@ public final class InputManager { * * This value should be between 0 (inclusive) and 1 (inclusive). * - * @see #getMaximumObscuringOpacityForTouch(Context) + * @see #getMaximumObscuringOpacityForTouch() * * @hide */ @TestApi @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS) - public void setMaximumObscuringOpacityForTouch(@NonNull Context context, float opacity) { + public void setMaximumObscuringOpacityForTouch(float opacity) { if (opacity < 0 || opacity > 1) { throw new IllegalArgumentException( "Maximum obscuring opacity for touch should be >= 0 and <= 1"); } + Context context = ActivityThread.currentApplication(); Settings.Global.putFloat(context.getContentResolver(), Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH, opacity); } diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 743713c096be9..7e6267e8cce7d 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -15766,9 +15766,8 @@ public final class Settings { * touch, allow the UID to propagate the touch. * * - * @see android.hardware.input.InputManager#getMaximumObscuringOpacityForTouch(Context) - * @see android.hardware.input.InputManager#setMaximumObscuringOpacityForTouch(Context, - * float) + * @see android.hardware.input.InputManager#getMaximumObscuringOpacityForTouch() + * @see android.hardware.input.InputManager#setMaximumObscuringOpacityForTouch(float) * * @hide */ diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 1327f9c6e8270..6edae93c35428 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -1555,17 +1555,26 @@ public interface WindowManager extends ViewManager { *

  • Fully transparent windows: This window has {@link LayoutParams#alpha} equal * to 0. *
  • One SAW window with enough transparency: This window is of type {@link - * #TYPE_APPLICATION_OVERLAY}, has {@link LayoutParams#alpha} below or equal to 0.8 - * and it's the only window of type {@link #TYPE_APPLICATION_OVERLAY} from this UID - * in the touch path. + * #TYPE_APPLICATION_OVERLAY}, has {@link LayoutParams#alpha} below or equal to the + * maximum obscuring opacity (see below) and it's the + * only window of type {@link #TYPE_APPLICATION_OVERLAY} from this UID in the touch + * path. *
  • Multiple SAW windows with enough transparency: The multiple overlapping * {@link #TYPE_APPLICATION_OVERLAY} windows in the * touch path from this UID have a combined obscuring opacity below or equal to - * 0.8. See section below on how to compute this value. + * the maximum obscuring opacity. See section + * Combined obscuring opacity below on how to compute this + * value. * *

    If none of these cases hold, the touch will not be delivered and a message will be * logged to logcat.

    * + * + *

    Maximum obscuring opacity

    + *

    This value is 0.8. Apps that want to gather this value from the system rather + * than hard-coding it might want to use {@link + * android.hardware.input.InputManager#getMaximumObscuringOpacityForTouch()}.

    + * * *

    Combined obscuring opacity

    * diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 23c70ee69514c..f6e08fbaf3791 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -1818,8 +1818,7 @@ public class InputManagerService extends IInputManager.Stub } private void updateMaximumObscuringOpacityForTouchFromSettings() { - final float opacity = InputManager.getInstance().getMaximumObscuringOpacityForTouch( - mContext); + final float opacity = InputManager.getInstance().getMaximumObscuringOpacityForTouch(); if (opacity < 0 || opacity > 1) { Log.e(TAG, "Invalid maximum obscuring opacity " + opacity + ", it should be >= 0 and <= 1, rejecting update.");