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

Commit e9d766f3 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Add new API to disable sending touch to wallpaper

Currently, all touch events on a Window are sent to wallpaper,
if the window uses FLAG_SHOW_WALLPAPER to show system wallpaper
in the background. This may have a security implications if
the Window is showing sensitive information. So, we are adding a
new API to allow developers to block touched to wallpaper.

Test: atest android.server.wm.WallpaperWindowInputTests

Bug: 177054831
Change-Id: I38d2e87d9b3b397f6946a638a7ecb4030ad21ddf
parent 4a0d85e1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -51473,6 +51473,7 @@ package android.view {
    ctor public WindowManager.LayoutParams(int, int, int, int, int);
    ctor public WindowManager.LayoutParams(int, int, int, int, int, int, int);
    ctor public WindowManager.LayoutParams(android.os.Parcel);
    method public boolean areWallpaperTouchEventsEnabled();
    method public final int copyFrom(android.view.WindowManager.LayoutParams);
    method public String debug(String);
    method public int describeContents();
@@ -51489,6 +51490,7 @@ package android.view {
    method public void setFitInsetsSides(int);
    method public void setFitInsetsTypes(int);
    method public final void setTitle(CharSequence);
    method public void setWallpaperTouchEventsEnabled(boolean);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int ALPHA_CHANGED = 128; // 0x80
    field public static final int ANIMATION_CHANGED = 16; // 0x10
+48 −0
Original line number Diff line number Diff line
@@ -1955,6 +1955,13 @@ public interface WindowManager extends ViewManager {
         * {@link android.R.style#Theme_Holo_Wallpaper_NoTitleBar},
         * {@link android.R.style#Theme_DeviceDefault_Wallpaper}, and
         * {@link android.R.style#Theme_DeviceDefault_Wallpaper_NoTitleBar}.</p>
         *
         * <p> When this flag is set, all touch events sent to this window is also sent to the
         * wallpaper, which is used to interact with live wallpapers. Check
         * {@link LayoutParams#areWallpaperTouchEventsEnabled()}, which is set to {@code true}
         * by default. When showing sensitive information on the window, if you want to disable
         * sending the touch events to the wallpaper, use
         * {@link LayoutParams#setWallpaperTouchEventsEnabled(boolean)}.</p>
         */
        public static final int FLAG_SHOW_WALLPAPER = 0x00100000;

@@ -3625,6 +3632,15 @@ public interface WindowManager extends ViewManager {
         */
        public LayoutParams[] paramsForRotation;

        /**
         * Specifies whether to send touch events to wallpaper, if the window shows wallpaper in the
         * background. By default, this is set to {@code true} i.e. if any window shows wallpaper
         * in the background, the wallpaper will receive touch events, unless specified otherwise.
         *
         * @see android.view.WindowManager.LayoutParams#FLAG_SHOW_WALLPAPER
         */
        private boolean mWallpaperTouchEventsEnabled = true;

        /**
         * Specifies types of insets that this window should avoid overlapping during layout.
         *
@@ -3702,6 +3718,31 @@ public interface WindowManager extends ViewManager {
                    == PRIVATE_FLAG_SYSTEM_APPLICATION_OVERLAY;
        }

        /**
         * Set whether sending touch events to the system wallpaper (which can be provided by a
         * third-party application) should be enabled for windows that show wallpaper in
         * background. By default, this is set to {@code true}.
         * Check {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WALLPAPER} for more
         * information on showing system wallpaper behind the window.
         *
         * @param enable whether to enable sending touch events to the system wallpaper.
         */
        public void setWallpaperTouchEventsEnabled(boolean enable) {
            mWallpaperTouchEventsEnabled = enable;
        }

        /**
         * Returns whether sending touch events to the system wallpaper (which can be provided by a
         * third-party application) is enabled for windows that show wallpaper in background.
         * Check {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WALLPAPER} for more
         * information on showing system wallpaper behind the window.
         *
         * @return whether sending touch events to the system wallpaper is enabled.
         */
        public boolean areWallpaperTouchEventsEnabled() {
            return mWallpaperTouchEventsEnabled;
        }

        /**
         * @return the {@link WindowInsets.Type}s that this window is avoiding overlapping.
         */
@@ -4010,6 +4051,7 @@ public interface WindowManager extends ViewManager {
            } else {
                out.writeInt(0);
            }
            out.writeBoolean(mWallpaperTouchEventsEnabled);
        }

        public static final @android.annotation.NonNull Parcelable.Creator<LayoutParams> CREATOR
@@ -4097,6 +4139,7 @@ public interface WindowManager extends ViewManager {
                paramsForRotation = new LayoutParams[paramsForRotationLength];
                in.readTypedArray(paramsForRotation, LayoutParams.CREATOR);
            }
            mWallpaperTouchEventsEnabled = in.readBoolean();
        }

        @SuppressWarnings({"PointlessBitwiseExpression"})
@@ -4414,6 +4457,11 @@ public interface WindowManager extends ViewManager {
                changes |= LAYOUT_CHANGED;
            }

            if (mWallpaperTouchEventsEnabled != o.mWallpaperTouchEventsEnabled) {
                mWallpaperTouchEventsEnabled = o.mWallpaperTouchEventsEnabled;
                changes |= LAYOUT_CHANGED;
            }

            return changes;
        }

+1 −10
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
@@ -82,7 +81,6 @@ final class InputMonitor {
    private boolean mUpdateInputWindowsPending;
    private boolean mUpdateInputWindowsImmediately;

    private boolean mDisableWallpaperTouchEvents;
    private final Region mTmpRegion = new Region();
    private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer;

@@ -272,7 +270,7 @@ final class InputMonitor {

        final boolean hasWallpaper = mDisplayContent.mWallpaperController.isWallpaperTarget(w)
                && !mService.mPolicy.isKeyguardShowing()
                && !mDisableWallpaperTouchEvents;
                && w.mAttrs.areWallpaperTouchEventsEnabled();
        inputWindowHandle.setHasWallpaper(hasWallpaper);

        // Surface insets are hardcoded to be the same in all directions
@@ -513,7 +511,6 @@ final class InputMonitor {
            mAddWallpaperInputConsumerHandle = mWallpaperInputConsumer != null;
            mAddRecentsAnimationInputConsumerHandle = mRecentsAnimationInputConsumer != null;

            mDisableWallpaperTouchEvents = false;
            mInDrag = inDrag;

            resetInputConsumers(mInputTransaction);
@@ -563,8 +560,6 @@ final class InputMonitor {
                return;
            }

            final int privateFlags = w.mAttrs.privateFlags;

            // This only works for legacy transitions.
            if (mAddRecentsAnimationInputConsumerHandle && shouldApplyRecentsInputConsumer) {
                if (recentsAnimationController.updateInputConsumerForApp(
@@ -601,10 +596,6 @@ final class InputMonitor {
                }
            }

            if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
                mDisableWallpaperTouchEvents = true;
            }

            // If there's a drag in progress and 'child' is a potential drop target,
            // make sure it's been told about the drag
            if (mInDrag && w.isVisible() && w.getDisplayContent().isDefaultDisplay) {