diff options
| author | 2023-09-18 22:22:10 +0000 | |
|---|---|---|
| committer | 2023-09-18 22:22:10 +0000 | |
| commit | 14b9b5ee59f9a102133b42d644db582c49e832d5 (patch) | |
| tree | f29e51dab7400a5962bce73c21e90d992787876a | |
| parent | 98b8468c21e619a01b5c75f52dd86b7c9063eef4 (diff) | |
Revert "Set trusted overlay on SurfaceControl instead of InputWindow"
This reverts commit 98b8468c21e619a01b5c75f52dd86b7c9063eef4.
Reason for revert: b/300659960
Change-Id: I635986c1aec2b3124944f8ff361e3a4027b98952
11 files changed, 29 insertions, 204 deletions
diff --git a/core/java/android/view/InputWindowHandle.java b/core/java/android/view/InputWindowHandle.java index bc837501037f..2761aaeb4a7d 100644 --- a/core/java/android/view/InputWindowHandle.java +++ b/core/java/android/view/InputWindowHandle.java @@ -35,8 +35,6 @@ import java.lang.ref.WeakReference; * @hide */ public final class InputWindowHandle { - // TODO (b/300094445): Convert to use correct flagging infrastructure - public static final boolean USE_SURFACE_TRUSTED_OVERLAY = true; /** * An internal annotation for all the {@link android.os.InputConfig} flags that can be @@ -61,6 +59,7 @@ public final class InputWindowHandle { InputConfig.DUPLICATE_TOUCH_TO_WALLPAPER, InputConfig.IS_WALLPAPER, InputConfig.PAUSE_DISPATCHING, + InputConfig.TRUSTED_OVERLAY, InputConfig.WATCH_OUTSIDE_TOUCH, InputConfig.SLIPPERY, InputConfig.DISABLE_USER_ACTIVITY, @@ -273,13 +272,4 @@ public final class InputWindowHandle { } this.inputConfig &= ~inputConfig; } - - public void setTrustedOverlay(SurfaceControl.Transaction t, SurfaceControl sc, - boolean isTrusted) { - if (USE_SURFACE_TRUSTED_OVERLAY) { - t.setTrustedOverlay(sc, isTrusted); - } else if (isTrusted) { - inputConfig |= InputConfig.TRUSTED_OVERLAY; - } - } } diff --git a/services/core/java/com/android/server/input/GestureMonitorSpyWindow.java b/services/core/java/com/android/server/input/GestureMonitorSpyWindow.java index a2c8748a9142..2ede56dcecd9 100644 --- a/services/core/java/com/android/server/input/GestureMonitorSpyWindow.java +++ b/services/core/java/com/android/server/input/GestureMonitorSpyWindow.java @@ -62,10 +62,10 @@ class GestureMonitorSpyWindow { mWindowHandle.ownerUid = uid; mWindowHandle.scaleFactor = 1.0f; mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */); - mWindowHandle.inputConfig = InputConfig.NOT_FOCUSABLE | InputConfig.SPY; + mWindowHandle.inputConfig = + InputConfig.NOT_FOCUSABLE | InputConfig.SPY | InputConfig.TRUSTED_OVERLAY; final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); - mWindowHandle.setTrustedOverlay(t, mInputSurface, true); t.setInputWindowInfo(mInputSurface, mWindowHandle); t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_GESTURE_MONITOR); t.setPosition(mInputSurface, 0, 0); diff --git a/services/core/java/com/android/server/inputmethod/HandwritingEventReceiverSurface.java b/services/core/java/com/android/server/inputmethod/HandwritingEventReceiverSurface.java index dbbbed31df76..7726f40fa2ae 100644 --- a/services/core/java/com/android/server/inputmethod/HandwritingEventReceiverSurface.java +++ b/services/core/java/com/android/server/inputmethod/HandwritingEventReceiverSurface.java @@ -57,13 +57,13 @@ final class HandwritingEventReceiverSurface { InputConfig.NOT_FOCUSABLE | InputConfig.NOT_TOUCHABLE | InputConfig.SPY - | InputConfig.INTERCEPTS_STYLUS; + | InputConfig.INTERCEPTS_STYLUS + | InputConfig.TRUSTED_OVERLAY; // Configure the surface to receive stylus events across the entire display. mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */); final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); - mWindowHandle.setTrustedOverlay(t, mInputSurface, true); t.setInputWindowInfo(mInputSurface, mWindowHandle); t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_HANDWRITING_SURFACE); t.setPosition(mInputSurface, 0, 0); diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java index 8519e4d3e53a..0f1a1053716e 100644 --- a/services/core/java/com/android/server/wm/DragState.java +++ b/services/core/java/com/android/server/wm/DragState.java @@ -21,6 +21,7 @@ import static android.content.ClipDescription.MIMETYPE_APPLICATION_SHORTCUT; import static android.content.ClipDescription.MIMETYPE_APPLICATION_TASK; import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP; + import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ORIENTATION; import static com.android.internal.protolog.ProtoLogGroup.WM_SHOW_TRANSACTIONS; import static com.android.server.wm.DragDropController.MSG_ANIMATION_END; @@ -32,6 +33,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACT import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import static com.android.server.wm.WindowManagerService.MY_PID; import static com.android.server.wm.WindowManagerService.MY_UID; + import static java.util.concurrent.CompletableFuture.completedFuture; import android.animation.Animator; @@ -46,6 +48,7 @@ import android.hardware.input.InputManagerGlobal; import android.os.Binder; import android.os.Build; import android.os.IBinder; +import android.os.InputConfig; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; @@ -183,13 +186,8 @@ class DragState { // Crop the input surface to the display size. mTmpClipRect.set(0, 0, mDisplaySize.x, mDisplaySize.y); - // Make trusted overlay to not block any touches while D&D ongoing and allowing - // touches to pass through to windows underneath. This allows user to interact with the - // UI to navigate while dragging. - h.setTrustedOverlay(mTransaction, mInputSurface, true); mTransaction.show(mInputSurface) .setInputWindowInfo(mInputSurface, h) - .setTrustedOverlay(mInputSurface, true) .setLayer(mInputSurface, Integer.MAX_VALUE) .setCrop(mInputSurface, mTmpClipRect); @@ -379,6 +377,11 @@ class DragState { mDragWindowHandle.ownerUid = MY_UID; mDragWindowHandle.scaleFactor = 1.0f; + // InputConfig.TRUSTED_OVERLAY: To not block any touches while D&D ongoing and allowing + // touches to pass through to windows underneath. This allows user to interact with the + // UI to navigate while dragging. + mDragWindowHandle.inputConfig = InputConfig.TRUSTED_OVERLAY; + // The drag window cannot receive new touches. mDragWindowHandle.touchableRegion.setEmpty(); diff --git a/services/core/java/com/android/server/wm/InputConsumerImpl.java b/services/core/java/com/android/server/wm/InputConsumerImpl.java index c21930dab5eb..39622c1c5aaf 100644 --- a/services/core/java/com/android/server/wm/InputConsumerImpl.java +++ b/services/core/java/com/android/server/wm/InputConsumerImpl.java @@ -74,7 +74,7 @@ class InputConsumerImpl implements IBinder.DeathRecipient { mWindowHandle.ownerPid = WindowManagerService.MY_PID; mWindowHandle.ownerUid = WindowManagerService.MY_UID; mWindowHandle.scaleFactor = 1.0f; - mWindowHandle.inputConfig = InputConfig.NOT_FOCUSABLE; + mWindowHandle.inputConfig = InputConfig.NOT_FOCUSABLE | InputConfig.TRUSTED_OVERLAY; mInputSurface = mService.makeSurfaceBuilder( mService.mRoot.getDisplayContent(displayId).getSession()) @@ -129,14 +129,12 @@ class InputConsumerImpl implements IBinder.DeathRecipient { void show(SurfaceControl.Transaction t, WindowContainer w) { t.show(mInputSurface); - mWindowHandle.setTrustedOverlay(t, mInputSurface, true); t.setInputWindowInfo(mInputSurface, mWindowHandle); t.setRelativeLayer(mInputSurface, w.getSurfaceControl(), 1); } void show(SurfaceControl.Transaction t, int layer) { t.show(mInputSurface); - mWindowHandle.setTrustedOverlay(t, mInputSurface, true); t.setInputWindowInfo(mInputSurface, mWindowHandle); t.setLayer(mInputSurface, layer); } diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index f77da6287176..825d38b3eed7 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -40,10 +40,12 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL; import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; + import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import static com.android.server.wm.WindowManagerService.LOGTAG_INPUT_FOCUS; + import static java.lang.Integer.MAX_VALUE; import android.annotation.Nullable; @@ -730,7 +732,7 @@ final class InputMonitor { new InputWindowHandle(null /* inputApplicationHandle */, displayId)); inputWindowHandle.setName(name); inputWindowHandle.setLayoutParamsType(TYPE_SECURE_SYSTEM_OVERLAY); - inputWindowHandle.setTrustedOverlay(t, sc, true); + inputWindowHandle.setTrustedOverlay(true); populateOverlayInputInfo(inputWindowHandle); setInputWindowInfoIfNeeded(t, sc, inputWindowHandle); } diff --git a/services/core/java/com/android/server/wm/InputWindowHandleWrapper.java b/services/core/java/com/android/server/wm/InputWindowHandleWrapper.java index 90d81bd82087..64b7a6064e45 100644 --- a/services/core/java/com/android/server/wm/InputWindowHandleWrapper.java +++ b/services/core/java/com/android/server/wm/InputWindowHandleWrapper.java @@ -195,11 +195,6 @@ class InputWindowHandleWrapper { mChanged = true; } - void setTrustedOverlay(SurfaceControl.Transaction t, SurfaceControl sc, - boolean trustedOverlay) { - mHandle.setTrustedOverlay(t, sc, trustedOverlay); - } - void setOwnerPid(int pid) { if (mHandle.ownerPid == pid) { return; diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 0a752d7daebd..439b7193dd4b 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -97,6 +97,7 @@ import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_MULTIPLIER; import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_MISSING_WINDOW; import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_NOT_VISIBLE_ON_SCREEN; import static android.window.WindowProviderService.isWindowProviderService; + import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ANIM; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_BOOT; @@ -8867,6 +8868,11 @@ public class WindowManagerService extends IWindowManager.Stub h.inputConfig |= InputConfig.NOT_FOCUSABLE; } + // Check private trusted overlay flag to set trustedOverlay field of input window handle. + if ((privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0) { + h.inputConfig |= InputConfig.TRUSTED_OVERLAY; + } + h.dispatchingTimeoutMillis = DEFAULT_DISPATCHING_TIMEOUT_MILLIS; h.ownerUid = callingUid; h.ownerPid = callingPid; @@ -8886,8 +8892,6 @@ public class WindowManagerService extends IWindowManager.Stub } final SurfaceControl.Transaction t = mTransactionFactory.get(); - // Check private trusted overlay flag to set trustedOverlay field of input window handle. - h.setTrustedOverlay(t, surface, (privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0); t.setInputWindowInfo(surface, h); t.apply(); t.close(); diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 822082ba4c70..b12cc0b30f53 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -28,7 +28,6 @@ import static android.graphics.GraphicsProtos.dumpPointProto; import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS; import static android.os.PowerManager.DRAW_WAKE_LOCK; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; -import static android.view.InputWindowHandle.USE_SURFACE_TRUSTED_OVERLAY; import static android.view.SurfaceControl.Transaction; import static android.view.SurfaceControl.getGlobalTransaction; import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; @@ -99,6 +98,7 @@ import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME; import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_MULTIPLIER; import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_OFFSET; + import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ANIM; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; @@ -1112,9 +1112,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP mInputWindowHandle.setName(getName()); mInputWindowHandle.setPackageName(mAttrs.packageName); mInputWindowHandle.setLayoutParamsType(mAttrs.type); - if (!USE_SURFACE_TRUSTED_OVERLAY) { - mInputWindowHandle.setTrustedOverlay(isWindowTrustedOverlay()); - } + mInputWindowHandle.setTrustedOverlay(shouldWindowHandleBeTrusted(s)); if (DEBUG) { Slog.v(TAG, "Window " + this + " client=" + c.asBinder() + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); @@ -1195,12 +1193,12 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP : service.mAtmService.getProcessController(s.mPid, s.mUid); } - private boolean isWindowTrustedOverlay() { + boolean shouldWindowHandleBeTrusted(Session s) { return InputMonitor.isTrustedOverlay(mAttrs.type) || ((mAttrs.privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0 - && mSession.mCanAddInternalSystemWindow) + && s.mCanAddInternalSystemWindow) || ((mAttrs.privateFlags & PRIVATE_FLAG_SYSTEM_APPLICATION_OVERLAY) != 0 - && mSession.mCanCreateSystemApplicationOverlay); + && s.mCanCreateSystemApplicationOverlay); } int getTouchOcclusionMode() { @@ -5194,9 +5192,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP updateFrameRateSelectionPriorityIfNeeded(); updateScaleIfNeeded(); mWinAnimator.prepareSurfaceLocked(getSyncTransaction()); - if (USE_SURFACE_TRUSTED_OVERLAY) { - getSyncTransaction().setTrustedOverlay(mSurfaceControl, isWindowTrustedOverlay()); - } } super.prepareSurfaces(); } @@ -5949,13 +5944,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP } boolean isTrustedOverlay() { - if (USE_SURFACE_TRUSTED_OVERLAY) { - WindowState parentWindow = getParentWindow(); - return isWindowTrustedOverlay() || (parentWindow != null - && parentWindow.isWindowTrustedOverlay()); - } else { - return mInputWindowHandle.isTrustedOverlay(); - } + return mInputWindowHandle.isTrustedOverlay(); } public boolean receiveFocusFromTapOutside() { diff --git a/services/tests/wmtests/AndroidManifest.xml b/services/tests/wmtests/AndroidManifest.xml index d6a38773bf6b..42e3383987d6 100644 --- a/services/tests/wmtests/AndroidManifest.xml +++ b/services/tests/wmtests/AndroidManifest.xml @@ -47,8 +47,6 @@ <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION"/> - <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"/> - <!-- TODO: Remove largeHeap hack when memory leak is fixed (b/123984854) --> <application android:debuggable="true" @@ -106,11 +104,6 @@ android:showWhenLocked="true" android:turnScreenOn="true" /> - <activity android:name="android.app.Activity" - android:exported="true" - android:showWhenLocked="true" - android:turnScreenOn="true" /> - <activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity" android:exported="true"> diff --git a/services/tests/wmtests/src/com/android/server/wm/TrustedOverlayTests.java b/services/tests/wmtests/src/com/android/server/wm/TrustedOverlayTests.java deleted file mode 100644 index e8a847c5d8a4..000000000000 --- a/services/tests/wmtests/src/com/android/server/wm/TrustedOverlayTests.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wm; - -import static android.view.InputWindowHandle.USE_SURFACE_TRUSTED_OVERLAY; -import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY; -import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; - -import android.app.Activity; -import android.app.Instrumentation; -import android.os.IBinder; -import android.platform.test.annotations.Presubmit; -import android.server.wm.BuildUtils; -import android.server.wm.CtsWindowInfoUtils; -import android.view.View; -import android.view.ViewTreeObserver; -import android.view.WindowManager; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.rule.ActivityTestRule; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -@Presubmit -public class TrustedOverlayTests { - private static final String TAG = "TrustedOverlayTests"; - private static final long TIMEOUT_S = 5L * BuildUtils.HW_TIMEOUT_MULTIPLIER; - - @Rule - public TestName mName = new TestName(); - - private final ActivityTestRule<Activity> mActivityRule = new ActivityTestRule<>( - Activity.class); - - private Instrumentation mInstrumentation; - private Activity mActivity; - - @Before - public void setup() { - mInstrumentation = InstrumentationRegistry.getInstrumentation(); - mActivity = mActivityRule.launchActivity(null); - } - - @Test - public void setTrustedOverlayInputWindow() throws InterruptedException { - assumeFalse(USE_SURFACE_TRUSTED_OVERLAY); - testTrustedOverlayChildHelper(false); - } - - @Test - public void setTrustedOverlayChildLayer() throws InterruptedException { - assumeTrue(USE_SURFACE_TRUSTED_OVERLAY); - testTrustedOverlayChildHelper(true); - } - - private void testTrustedOverlayChildHelper(boolean expectTrusted) throws InterruptedException { - IBinder[] tokens = new IBinder[2]; - CountDownLatch hostTokenReady = new CountDownLatch(1); - mInstrumentation.runOnMainSync(() -> { - mActivity.getWindow().addPrivateFlags(PRIVATE_FLAG_TRUSTED_OVERLAY); - View rootView = mActivity.getWindow().getDecorView(); - if (rootView.isAttachedToWindow()) { - tokens[0] = rootView.getWindowToken(); - hostTokenReady.countDown(); - } else { - rootView.getViewTreeObserver().addOnWindowAttachListener( - new ViewTreeObserver.OnWindowAttachListener() { - @Override - public void onWindowAttached() { - tokens[0] = rootView.getWindowToken(); - hostTokenReady.countDown(); - } - - @Override - public void onWindowDetached() { - } - }); - } - }); - - assertTrue("Failed to wait for host to get added", - hostTokenReady.await(TIMEOUT_S, TimeUnit.SECONDS)); - - mInstrumentation.runOnMainSync(() -> { - WindowManager wm = mActivity.getSystemService(WindowManager.class); - - View childView = new View(mActivity) { - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - tokens[1] = getWindowToken(); - } - }; - WindowManager.LayoutParams params = new WindowManager.LayoutParams(); - params.token = tokens[0]; - params.type = TYPE_APPLICATION_PANEL; - wm.addView(childView, params); - }); - - boolean[] foundTrusted = new boolean[2]; - - CtsWindowInfoUtils.waitForWindowInfos( - windowInfos -> { - for (var windowInfo : windowInfos) { - if (windowInfo.windowToken == tokens[0] - && windowInfo.isTrustedOverlay) { - foundTrusted[0] = true; - } else if (windowInfo.windowToken == tokens[1] - && windowInfo.isTrustedOverlay) { - foundTrusted[1] = true; - } - } - return foundTrusted[0] && foundTrusted[1]; - }, TIMEOUT_S, TimeUnit.SECONDS); - - if (!foundTrusted[0] || !foundTrusted[1]) { - CtsWindowInfoUtils.dumpWindowsOnScreen(TAG, mName.getMethodName()); - } - - assertEquals("Failed to find parent window or was not marked trusted", expectTrusted, - foundTrusted[0]); - assertEquals("Failed to find child window or was not marked trusted", expectTrusted, - foundTrusted[1]); - } -} |