OSDN Git Service

Merge "Let TYPE_ANNOUNCEMENT be sent from any window" into lmp-dev
[android-x86/frameworks-base.git] / services / accessibility / java / com / android / server / accessibility / AccessibilityManagerService.java
index 7d4156f..bfbf0ac 100644 (file)
@@ -67,7 +67,6 @@ import android.util.Pools.Pool;
 import android.util.Pools.SimplePool;
 import android.util.Slog;
 import android.util.SparseArray;
-import android.view.AccessibilityManagerInternal;
 import android.view.Display;
 import android.view.IWindow;
 import android.view.InputDevice;
@@ -148,6 +147,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
 
     private static final int MAX_POOL_SIZE = 10;
 
+    private static final int WINDOW_ID_UNKNOWN = -1;
+
     private static int sIdCounter = 0;
 
     private static int sNextWindowId;
@@ -233,7 +234,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
         registerBroadcastReceivers();
         new AccessibilityContentObserver(mMainHandler).register(
                 context.getContentResolver());
-        LocalServices.addService(AccessibilityManagerInternal.class, new LocalService());
     }
 
     private UserState getUserStateLocked(int userId) {
@@ -764,6 +764,35 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                 .getAccessibilityFocusClickPointInScreenNotLocked(outPoint);
     }
 
+    /**
+     * Gets the bounds of the active window.
+     *
+     * @param outBounds The output to which to write the bounds.
+     */
+    boolean getActiveWindowBounds(Rect outBounds) {
+        // TODO: This should be refactored to work with accessibility
+        // focus in multiple windows.
+        IBinder token;
+        synchronized (mLock) {
+            final int windowId = mSecurityPolicy.mActiveWindowId;
+            token = mGlobalWindowTokens.get(windowId);
+            if (token == null) {
+                token = getCurrentUserStateLocked().mWindowTokens.get(windowId);
+            }
+        }
+        mWindowManagerService.getWindowFrame(token, outBounds);
+        if (!outBounds.isEmpty()) {
+            return true;
+        }
+        return false;
+    }
+
+    boolean accessibilityFocusOnlyInActiveWindow() {
+        synchronized (mLock) {
+            return mWindowsForAccessibilityCallback == null;
+        }
+    }
+
     int getActiveWindowId() {
         return mSecurityPolicy.getActiveWindowId();
     }
@@ -1050,7 +1079,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
             return false;
         }
 
-        if (!event.isImportantForAccessibility()
+        if (event.getWindowId() != WINDOW_ID_UNKNOWN && !event.isImportantForAccessibility()
                 && (service.mFetchFlags
                         & AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) == 0) {
             return false;
@@ -1300,7 +1329,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
         updateTouchExplorationLocked(userState);
         updateEnhancedWebAccessibilityLocked(userState);
         updateDisplayColorAdjustmentSettingsLocked(userState);
-        updateEncryptionState(userState);
         scheduleUpdateInputFilter(userState);
         scheduleUpdateClientsIfNeededLocked(userState);
     }
@@ -1577,17 +1605,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
         DisplayAdjustmentUtils.applyAdjustments(mContext, userState.mUserId);
     }
 
-    private void updateEncryptionState(UserState userState) {
-        if (userState.mUserId != UserHandle.USER_OWNER) {
-            return;
-        }
-        if (hasRunningServicesLocked(userState) && LockPatternUtils.isDeviceEncrypted()) {
-            // If there are running accessibility services we do not have encryption as
-            // the user needs the accessibility layer to be running to authenticate.
-            mLockPatternUtils.clearEncryptionPassword();
-        }
-    }
-
     private boolean hasRunningServicesLocked(UserState userState) {
         return !userState.mBoundServices.isEmpty() || !userState.mBindingServices.isEmpty();
     }
@@ -3207,6 +3224,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                     point.y = (int) (point.y * (1 / spec.scale));
                 }
 
+                // Make sure the point is within the window.
+                Rect windowBounds = mTempRect;
+                getActiveWindowBounds(windowBounds);
+                if (!windowBounds.contains(point.x, point.y)) {
+                    return false;
+                }
+
                 // Make sure the point is within the screen.
                 Point screenSize = mTempPoint;
                 mDefaultDisplay.getRealSize(screenSize);
@@ -3288,6 +3312,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                     }
                 // $fall-through$
                 case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
+                case AccessibilityEvent.TYPE_ANNOUNCEMENT:
                 // All events generated by the user touching the
                 // screen should *always* be dispatched.
                 case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START:
@@ -3566,6 +3591,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
         }
 
         private void notifyWindowsChanged() {
+            if (mWindowsForAccessibilityCallback == null) {
+                return;
+            }
             final long identity = Binder.clearCallingIdentity();
             try {
                 // Let the client know the windows changed.
@@ -3650,6 +3678,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
         }
 
         private boolean isRetrievalAllowingWindow(int windowId) {
+            // The system gets to interact with any window it wants.
+            if (Binder.getCallingUid() == Process.SYSTEM_UID) {
+                return true;
+            }
             if (windowId == mActiveWindowId) {
                 return true;
             }
@@ -3919,14 +3951,4 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
             }
         }
     }
-
-    private final class LocalService extends AccessibilityManagerInternal {
-        @Override
-        public boolean isNonDefaultEncryptionPasswordAllowed() {
-            synchronized (mLock) {
-                UserState userState = getCurrentUserStateLocked();
-                return !hasRunningServicesLocked(userState);
-            }
-        }
-    }
 }