OSDN Git Service

Limit global drags to apps targeting SDK 24 and above
authorYorke Lee <yorkelee@google.com>
Wed, 15 Jun 2016 17:03:18 +0000 (10:03 -0700)
committerYorke Lee <yorkelee@google.com>
Thu, 16 Jun 2016 16:35:40 +0000 (09:35 -0700)
Bug: 29127791

Change-Id: Ib5f85a207bdb79eeac0418fda78e452d225761bc

core/java/android/view/IWindowManager.aidl
services/core/java/com/android/server/am/ActivityStack.java
services/core/java/com/android/server/wm/AppWindowToken.java
services/core/java/com/android/server/wm/DragState.java
services/core/java/com/android/server/wm/WindowManagerService.java
tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java

index f8a6a17..72126d0 100644 (file)
@@ -106,12 +106,13 @@ interface IWindowManager
      * @param alwaysFocusable True if the app windows are always focusable regardless of the stack
      *                        they are in.
      * @param homeTask True if this is the task.
+     * @param targetSdkVersion The application's target SDK version
      */
     void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId,
             int requestedOrientation, boolean fullscreen, boolean showWhenLocked, int userId,
             int configChanges, boolean voiceInteraction, boolean launchTaskBehind,
             in Rect taskBounds, in Configuration configuration, int taskResizeMode,
-            boolean alwaysFocusable, boolean homeTask);
+            boolean alwaysFocusable, boolean homeTask, int targetSdkVersion);
     /**
      *
      * @param token The token we are adding to the input task Id.
index d83a750..27145fc 100644 (file)
@@ -5177,7 +5177,8 @@ final class ActivityStack {
                 r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
                 (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges,
                 task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig,
-                task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask());
+                task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask(),
+                r.appInfo.targetSdkVersion);
         r.taskConfigOverride = task.mOverrideConfig;
     }
 
index f57e83a..b907da6 100644 (file)
@@ -72,6 +72,7 @@ class AppWindowToken extends WindowToken {
     int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
     boolean layoutConfigChanges;
     boolean showForAllUsers;
+    int targetSdk;
 
     // The input dispatching timeout for this application token in nanoseconds.
     long inputDispatchingTimeoutNanos;
index c4eca08..9d0fb61 100644 (file)
@@ -28,6 +28,7 @@ import android.content.Context;
 import android.graphics.Matrix;
 import android.graphics.Point;
 import android.hardware.input.InputManager;
+import android.os.Build;
 import android.os.IBinder;
 import android.os.Message;
 import android.os.Process;
@@ -289,7 +290,7 @@ class DragState {
         if (!targetWin.isPotentialDragTarget()) {
             return false;
         }
-        if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
+        if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0 || !targetWindowSupportsGlobalDrag(targetWin)) {
             // Drag is limited to the current window.
             if (mLocalWin != targetWin.mClient.asBinder()) {
                 return false;
@@ -300,6 +301,13 @@ class DragState {
                 mSourceUserId == UserHandle.getUserId(targetWin.getOwningUid());
     }
 
+    private boolean targetWindowSupportsGlobalDrag(WindowState targetWin) {
+        // Global drags are limited to system windows, and windows for apps that are targeting N and
+        // above.
+        return targetWin.mAppToken == null
+                || targetWin.mAppToken.targetSdk >= Build.VERSION_CODES.N;
+    }
+
     /* helper - send a ACTION_DRAG_STARTED event only if the window has not
      * previously been notified, i.e. it became visible after the drag operation
      * was begun.  This is a rare case.
index 8474fcf..3687512 100644 (file)
@@ -3420,7 +3420,7 @@ public class WindowManagerService extends IWindowManager.Stub
             int requestedOrientation, boolean fullscreen, boolean showForAllUsers, int userId,
             int configChanges, boolean voiceInteraction, boolean launchTaskBehind,
             Rect taskBounds, Configuration config, int taskResizeMode, boolean alwaysFocusable,
-            boolean homeTask) {
+            boolean homeTask, int targetSdkVersion) {
         if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
                 "addAppToken()")) {
             throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
@@ -3450,6 +3450,7 @@ public class WindowManagerService extends IWindowManager.Stub
             atoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
             atoken.appFullscreen = fullscreen;
             atoken.showForAllUsers = showForAllUsers;
+            atoken.targetSdk = targetSdkVersion;
             atoken.requestedOrientation = requestedOrientation;
             atoken.layoutConfigChanges = (configChanges &
                     (ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) != 0;
index 0286506..a726a15 100644 (file)
@@ -93,7 +93,7 @@ public class WindowManagerPermissionTests extends TestCase {
 
         try {
             mWm.addAppToken(0, null, 0, 0, 0, false, false, 0, 0, false, false, null,
-                    Configuration.EMPTY, 0, false, false);
+                    Configuration.EMPTY, 0, false, false, 0);
             fail("IWindowManager.addAppToken did not throw SecurityException as"
                     + " expected");
         } catch (SecurityException e) {
index ceebdd5..04a59bc 100644 (file)
@@ -78,7 +78,7 @@ public class IWindowManagerImpl implements IWindowManager {
     @Override
     public void addAppToken(int arg0, IApplicationToken arg1, int arg2, int arg3, int arg4,
             boolean arg5, boolean arg6, int arg7, int arg8, boolean arg9, boolean arg10,
-            Rect arg11, Configuration arg12, int arg13, boolean arg14, boolean arg15)
+            Rect arg11, Configuration arg12, int arg13, boolean arg14, boolean arg15, int arg16)
             throws RemoteException {
         // TODO Auto-generated method stub
     }