Fix the problem that system apps cannot drag
If an app with a uid of Process.SYSTEM_UID calls view.startDragAndDrop, IllegalStateException will be thrown in Session.performDrag, which makes the drag-and-drop feature unavailable in this app.
And we don't need this check either, because validateAndResolveDragMimeTypeExtras and validateDragFlags are indeed called before Binder.clearCallingIdentity.
Bug: 245626682
Change-Id: I1c27287e51a956284dae0f61bfa0cac14dd28a27
diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java
index 30b5083..c5f21eb 100644
--- a/services/core/java/com/android/server/wm/Session.java
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -322,7 +322,7 @@
final int callingPid = Binder.getCallingPid();
// Validate and resolve ClipDescription data before clearing the calling identity
validateAndResolveDragMimeTypeExtras(data, callingUid, callingPid, mPackageName);
- validateDragFlags(flags, callingUid);
+ validateDragFlags(flags);
final long ident = Binder.clearCallingIdentity();
try {
return mDragDropController.performDrag(mPid, mUid, window, flags, surface, touchSource,
@@ -347,11 +347,7 @@
* Validates the given drag flags.
*/
@VisibleForTesting
- void validateDragFlags(int flags, int callingUid) {
- if (callingUid == Process.SYSTEM_UID) {
- throw new IllegalStateException("Need to validate before calling identify is cleared");
- }
-
+ void validateDragFlags(int flags) {
if ((flags & View.DRAG_FLAG_REQUEST_SURFACE_FOR_RETURN_ANIMATION) != 0) {
if (!mCanStartTasksFromRecents) {
throw new SecurityException("Requires START_TASKS_FROM_RECENTS permission");
@@ -365,9 +361,6 @@
@VisibleForTesting
void validateAndResolveDragMimeTypeExtras(ClipData data, int callingUid, int callingPid,
String callingPackage) {
- if (callingUid == Process.SYSTEM_UID) {
- throw new IllegalStateException("Need to validate before calling identify is cleared");
- }
final ClipDescription desc = data != null ? data.getDescription() : null;
if (desc == null) {
return;
diff --git a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
index 28fc352..4526d18 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
@@ -467,8 +467,7 @@
public void onAnimatorScaleChanged(float scale) {}
});
try {
- session.validateDragFlags(View.DRAG_FLAG_REQUEST_SURFACE_FOR_RETURN_ANIMATION,
- TEST_UID);
+ session.validateDragFlags(View.DRAG_FLAG_REQUEST_SURFACE_FOR_RETURN_ANIMATION);
fail("Expected failure without permission");
} catch (SecurityException e) {
// Expected failure
@@ -484,8 +483,7 @@
public void onAnimatorScaleChanged(float scale) {}
});
try {
- session.validateDragFlags(View.DRAG_FLAG_REQUEST_SURFACE_FOR_RETURN_ANIMATION,
- TEST_UID);
+ session.validateDragFlags(View.DRAG_FLAG_REQUEST_SURFACE_FOR_RETURN_ANIMATION);
// Expected pass
} catch (SecurityException e) {
fail("Expected no failure with permission");