diff --git a/core/api/current.txt b/core/api/current.txt index 423b523a1027e..01e89f474dd39 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 7ef2ccbd8a33d..8248ce95f560a 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 13d9eb9d3c7d2..af18293398da7 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; @@ -990,6 +995,26 @@ public abstract class Window { mRestrictedCaptionAreaRect = listener != null ? new Rect() : null; } + /** + * 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 diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 7cd497ef471e0..3cb2dd4b5a5a5 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -2730,6 +2730,10 @@ + + + @@ -3284,6 +3288,7 @@ {@link android.view.WindowManager.LayoutsParams#SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS} to hide non-system-overlay windows.

Not for use by third-party applications. + @deprecated Use {@link android.Manifest.permission#HIDE_OVERLAY_WINDOWS} instead @hide --> + + +