Skip to content

Commit 9130e61

Browse files
vishniakouInVictusXV
authored andcommitted
Add ALLOW_SLIPPERY_TOUCHES permission
This permission allows the app to use FLAG_SLIPPERY. This means, windows of the app that has this permission can let touches slip out when the finger moves out of the window bounds. Bug: 157929241 Bug: 206188649 Test: atest FlagSlipperyTest Change-Id: I9ccdfd298f32c36b9c4da68c2e9c355c97dc7593 Merged-In: I9ccdfd298f32c36b9c4da68c2e9c355c97dc7593 (cherry picked from commit cccf191) Merged-In:I9ccdfd298f32c36b9c4da68c2e9c355c97dc7593
1 parent fed84f2 commit 9130e61

4 files changed

Lines changed: 25 additions & 17 deletions

File tree

core/res/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5074,6 +5074,10 @@
50745074
<!-- Allows input events to be monitored. Very dangerous! @hide -->
50755075
<permission android:name="android.permission.MONITOR_INPUT"
50765076
android:protectionLevel="signature" />
5077+
<!-- Allows the use of FLAG_SLIPPERY, which permits touch events to slip from the current
5078+
window to the window where the touch currently is on top of. @hide -->
5079+
<permission android:name="android.permission.ALLOW_SLIPPERY_TOUCHES"
5080+
android:protectionLevel="signature" />
50775081
<!-- Allows the caller to change the associations between input devices and displays.
50785082
Very dangerous! @hide -->
50795083
<permission android:name="android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY_BY_PORT"

packages/SystemUI/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
117117
<uses-permission android:name="android.permission.MONITOR_INPUT" />
118118
<uses-permission android:name="android.permission.INPUT_CONSUMER" />
119+
<uses-permission android:name="android.permission.ALLOW_SLIPPERY_TOUCHES" />
119120

120121
<!-- DreamManager -->
121122
<uses-permission android:name="android.permission.READ_DREAM_STATE" />

services/core/java/com/android/server/wm/DisplayPolicy.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
6666
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
6767
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
68-
import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
6968
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
7069
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
7170
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
@@ -874,20 +873,6 @@ private boolean hasStatusBarServicePermission(int pid, int uid) {
874873
== PackageManager.PERMISSION_GRANTED;
875874
}
876875

877-
/**
878-
* Only trusted overlays are allowed to use FLAG_SLIPPERY.
879-
*/
880-
static int sanitizeFlagSlippery(int flags, int privateFlags, String name) {
881-
if ((flags & FLAG_SLIPPERY) == 0) {
882-
return flags;
883-
}
884-
if ((privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0) {
885-
return flags;
886-
}
887-
Slog.w(TAG, "Removing FLAG_SLIPPERY for non-trusted overlay " + name);
888-
return flags & ~FLAG_SLIPPERY;
889-
}
890-
891876
/**
892877
* Sanitize the layout parameters coming from a client. Allows the policy
893878
* to do things like ensure that windows of a specific type can't take
@@ -971,7 +956,6 @@ public void adjustWindowParamsLw(WindowState win, WindowManager.LayoutParams att
971956
}
972957
break;
973958
}
974-
attrs.flags = sanitizeFlagSlippery(attrs.flags, attrs.privateFlags, win.getName());
975959

976960
// Check if alternate bars positions were updated.
977961
if (mStatusBarAlt == win) {

services/core/java/com/android/server/wm/WindowManagerService.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,7 @@ public int addWindow(Session session, IWindow client, int seq,
15711571

15721572
final DisplayPolicy displayPolicy = displayContent.getDisplayPolicy();
15731573
displayPolicy.adjustWindowParamsLw(win, win.mAttrs, callingPid, callingUid);
1574+
attrs.flags = sanitizeFlagSlippery(attrs.flags, win.getName(), callingUid, callingPid);
15741575

15751576
res = displayPolicy.validateAddingWindowLw(attrs, callingPid, callingUid);
15761577
if (res != WindowManagerGlobal.ADD_OKAY) {
@@ -2155,6 +2156,7 @@ public int relayoutWindow(Session session, IWindow client, int seq, LayoutParams
21552156
if (attrs != null) {
21562157
displayPolicy.adjustWindowParamsLw(win, attrs, pid, uid);
21572158
win.mToken.adjustWindowParams(win, attrs);
2159+
attrs.flags = sanitizeFlagSlippery(attrs.flags, win.getName(), uid, pid);
21582160
// if they don't have the permission, mask out the status bar bits
21592161
if (seq == win.mSeq) {
21602162
int systemUiVisibility = attrs.systemUiVisibility
@@ -8051,6 +8053,23 @@ void handleTaskFocusChange(Task task) {
80518053
}
80528054
}
80538055

8056+
/**
8057+
* You need ALLOW_SLIPPERY_TOUCHES permission to be able to set FLAG_SLIPPERY.
8058+
*/
8059+
private int sanitizeFlagSlippery(int flags, String windowName, int callingUid, int callingPid) {
8060+
if ((flags & FLAG_SLIPPERY) == 0) {
8061+
return flags;
8062+
}
8063+
final int permissionResult = mContext.checkPermission(
8064+
android.Manifest.permission.ALLOW_SLIPPERY_TOUCHES, callingPid, callingUid);
8065+
if (permissionResult != PackageManager.PERMISSION_GRANTED) {
8066+
Slog.w(TAG, "Removing FLAG_SLIPPERY from '" + windowName
8067+
+ "' because it doesn't have ALLOW_SLIPPERY_TOUCHES permission");
8068+
return flags & ~FLAG_SLIPPERY;
8069+
}
8070+
return flags;
8071+
}
8072+
80548073
/**
80558074
* Assigns an InputChannel to a SurfaceControl and configures it to receive
80568075
* touch input according to it's on-screen geometry.
@@ -8088,7 +8107,7 @@ private void updateInputChannel(IBinder channelToken, int callingUid, int callin
80888107
h.token = channelToken;
80898108
h.name = name;
80908109

8091-
flags = DisplayPolicy.sanitizeFlagSlippery(flags, privateFlags, name);
8110+
flags = sanitizeFlagSlippery(flags, name, callingUid, callingPid);
80928111

80938112
final int sanitizedFlags = flags & (LayoutParams.FLAG_NOT_TOUCHABLE | FLAG_SLIPPERY);
80948113
h.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | sanitizedFlags;

0 commit comments

Comments
 (0)