summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Linus Tufvesson <lus@google.com> 2020-11-06 13:07:44 +0000
committer Linus Tufvesson <lus@google.com> 2020-12-10 10:47:48 +0000
commitf57a88f03b7ef55cb8802f1c02b2dc69f3d183ef (patch)
tree8daf71aefacd6c0156b9e84f1f994dd2998eaad1
parente386b0a3dff9113c5b98ee6bee7be1018ff0496d (diff)
Allow 3p apps to hide non system overlay windows
SAW permission is added to the shell to allow it to create TYPE_APPLICATION_OVERLAY windows during testing. Test: atest CtsWindowManagerDeviceTestCases:HideOverlayWindowsTest Bug: 159616727 Change-Id: I503cd8da24ff4d2b928f930ac61090e6782c1546
-rw-r--r--core/api/current.txt2
-rw-r--r--core/api/system-current.txt2
-rw-r--r--core/java/android/view/Window.java25
-rw-r--r--core/res/AndroidManifest.xml5
-rw-r--r--packages/Shell/AndroidManifest.xml3
-rw-r--r--services/core/java/com/android/server/wm/Session.java5
6 files changed, 40 insertions, 2 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index 423b523a1027..01e89f474dd3 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -87,6 +87,7 @@ package android {
field public static final String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
field @Deprecated public static final String GET_TASKS = "android.permission.GET_TASKS";
field public static final String GLOBAL_SEARCH = "android.permission.GLOBAL_SEARCH";
+ field public static final String HIDE_OVERLAY_WINDOWS = "android.permission.HIDE_OVERLAY_WINDOWS";
field public static final String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER";
field public static final String INSTALL_PACKAGES = "android.permission.INSTALL_PACKAGES";
field public static final String INSTALL_SHORTCUT = "com.android.launcher.permission.INSTALL_SHORTCUT";
@@ -54221,6 +54222,7 @@ package android.view {
method public void setFlags(int, int);
method public void setFormat(int);
method public void setGravity(int);
+ method @RequiresPermission(android.Manifest.permission.HIDE_OVERLAY_WINDOWS) public final void setHideOverlayWindows(boolean);
method public void setIcon(@DrawableRes int);
method public void setLayout(int, int);
method public void setLocalFocus(boolean, boolean);
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 7ef2ccbd8a33..8248ce95f560 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -93,7 +93,7 @@ package android {
field public static final String HANDLE_CAR_MODE_CHANGES = "android.permission.HANDLE_CAR_MODE_CHANGES";
field public static final String HARDWARE_TEST = "android.permission.HARDWARE_TEST";
field public static final String HDMI_CEC = "android.permission.HDMI_CEC";
- field public static final String HIDE_NON_SYSTEM_OVERLAY_WINDOWS = "android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS";
+ field @Deprecated public static final String HIDE_NON_SYSTEM_OVERLAY_WINDOWS = "android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS";
field public static final String INJECT_EVENTS = "android.permission.INJECT_EVENTS";
field public static final String INSTALL_DYNAMIC_SYSTEM = "android.permission.INSTALL_DYNAMIC_SYSTEM";
field public static final String INSTALL_GRANT_RUNTIME_PERMISSIONS = "android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS";
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 13d9eb9d3c7d..af18293398da 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -16,7 +16,11 @@
package android.view;
+import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import static android.Manifest.permission.HIDE_OVERLAY_WINDOWS;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
@@ -24,6 +28,7 @@ import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.annotation.StyleRes;
import android.annotation.SystemApi;
import android.annotation.TestApi;
@@ -991,6 +996,26 @@ public abstract class Window {
}
/**
+ * Prevent non-system overlay windows from being drawn on top of this window.
+ *
+ * @param hide whether non-system overlay windows should be hidden.
+ */
+ @RequiresPermission(HIDE_OVERLAY_WINDOWS)
+ public final void setHideOverlayWindows(boolean hide) {
+ // This permission check is here to throw early and let the developer know that they need
+ // to hold HIDE_OVERLAY_WINDOWS for the flag to have any effect. The WM verifies that the
+ // owner of the window has the permission before applying the flag, but this is done
+ // asynchronously.
+ if (mContext.checkSelfPermission(HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != PERMISSION_GRANTED
+ && mContext.checkSelfPermission(HIDE_OVERLAY_WINDOWS) != PERMISSION_GRANTED) {
+ throw new SecurityException(
+ "Permission denial: setHideOverlayWindows: HIDE_OVERLAY_WINDOWS");
+ }
+ setPrivateFlags(hide ? SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS : 0,
+ SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ }
+
+ /**
* Take ownership of this window's surface. The window's view hierarchy
* will no longer draw into the surface, though it will otherwise continue
* to operate (such as for receiving input events). The given SurfaceHolder
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 7cd497ef471e..3cb2dd4b5a5a 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2730,6 +2730,10 @@
<permission android:name="android.permission.TOGGLE_AUTOMOTIVE_PROJECTION"
android:protectionLevel="signature|privileged" />
+ <!-- Allows an app to prevent non-system-overlay windows from being drawn on top of it -->
+ <permission android:name="android.permission.HIDE_OVERLAY_WINDOWS"
+ android:protectionLevel="normal" />
+
<!-- ================================== -->
<!-- Permissions affecting the system wallpaper -->
<!-- ================================== -->
@@ -3284,6 +3288,7 @@
{@link android.view.WindowManager.LayoutsParams#SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS}
to hide non-system-overlay windows.
<p>Not for use by third-party applications.
+ @deprecated Use {@link android.Manifest.permission#HIDE_OVERLAY_WINDOWS} instead
@hide
-->
<permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index 7b1257b0f194..be0970cb39b1 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -362,6 +362,9 @@
<!-- Permissions required for CTS tests to close system dialogs -->
<uses-permission android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS" />
+ <!-- Permission required for CTS test - HideOverlayWindowsTest -->
+ <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
+
<application android:label="@string/app_label"
android:theme="@android:style/Theme.DeviceDefault.DayNight"
android:defaultToDeviceProtectedStorage="true"
diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java
index c414c6421dc8..57d48c6bb9f4 100644
--- a/services/core/java/com/android/server/wm/Session.java
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -18,6 +18,7 @@ package com.android.server.wm;
import static android.Manifest.permission.DEVICE_POWER;
import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import static android.Manifest.permission.HIDE_OVERLAY_WINDOWS;
import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
import static android.Manifest.permission.START_TASKS_FROM_RECENTS;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
@@ -124,7 +125,9 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
- HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
+ HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED
+ || service.mContext.checkCallingOrSelfPermission(HIDE_OVERLAY_WINDOWS)
+ == PERMISSION_GRANTED;
mOverlaysCanBeHidden = !mCanAddInternalSystemWindow
&& !mService.mAtmInternal.isCallerRecents(mUid);
mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)