Merge "Only allow trusted overlays to specify FLAG_SLIPPERY"

This commit is contained in:
TreeHugger Robot
2021-08-19 19:21:58 +00:00
committed by Android (Google) Code Review
4 changed files with 23 additions and 1 deletions

View File

@@ -2852,6 +2852,7 @@ package android.view {
method @Nullable public final android.os.IBinder getWindowContextToken();
method public final void setWindowContextToken(@NonNull android.os.IBinder);
field public static final int ACCESSIBILITY_TITLE_CHANGED = 33554432; // 0x2000000
field public static final int FLAG_SLIPPERY = 536870912; // 0x20000000
field public static final int PRIVATE_FLAG_NO_MOVE_ANIMATION = 64; // 0x40
field public CharSequence accessibilityTitle;
field public int privateFlags;

View File

@@ -2105,6 +2105,7 @@ public interface WindowManager extends ViewManager {
* {@hide}
*/
@UnsupportedAppUsage
@TestApi
public static final int FLAG_SLIPPERY = 0x20000000;
/**

View File

@@ -54,6 +54,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
@@ -871,6 +872,20 @@ public class DisplayPolicy {
== PackageManager.PERMISSION_GRANTED;
}
/**
* Only trusted overlays are allowed to use FLAG_SLIPPERY.
*/
static int sanitizeFlagSlippery(int flags, int privateFlags, String name) {
if ((flags & FLAG_SLIPPERY) == 0) {
return flags;
}
if ((privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0) {
return flags;
}
Slog.w(TAG, "Removing FLAG_SLIPPERY for non-trusted overlay " + name);
return flags & ~FLAG_SLIPPERY;
}
/**
* Sanitize the layout parameters coming from a client. Allows the policy
* to do things like ensure that windows of a specific type can't take
@@ -951,6 +966,8 @@ public class DisplayPolicy {
if (mExtraNavBarAlt == win) {
mExtraNavBarAltPosition = getAltBarPosition(attrs);
}
attrs.flags = sanitizeFlagSlippery(attrs.flags, attrs.privateFlags, win.getName());
}
/**

View File

@@ -57,6 +57,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
import static android.view.WindowManager.LayoutParams.INVALID_WINDOW_TYPE;
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
@@ -8278,8 +8279,10 @@ public class WindowManagerService extends IWindowManager.Stub
h.setWindowToken(window);
h.name = name;
flags = DisplayPolicy.sanitizeFlagSlippery(flags, privateFlags, name);
final int sanitizedFlags = flags & (LayoutParams.FLAG_NOT_TOUCHABLE
| LayoutParams.FLAG_SLIPPERY | LayoutParams.FLAG_NOT_FOCUSABLE);
| FLAG_SLIPPERY | LayoutParams.FLAG_NOT_FOCUSABLE);
h.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | sanitizedFlags;
h.layoutParamsType = type;
h.dispatchingTimeoutMillis = DEFAULT_DISPATCHING_TIMEOUT_MILLIS;