Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7836b98 authored by Phil Weaver's avatar Phil Weaver Committed by android-build-merger
Browse files

Merge "Better guarantee a11y service initial state" into oc-mr1-dev

am: c354e022

Change-Id: I1fcb2898c1081797e2f6068e5ec9d1ea34452dfc
parents a040bae5 c354e022
Loading
Loading
Loading
Loading
+54 −18
Original line number Diff line number Diff line
@@ -2397,6 +2397,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
        public static final int MSG_SEND_RELEVANT_EVENTS_CHANGED_TO_CLIENTS = 12;
        public static final int MSG_SEND_ACCESSIBILITY_BUTTON_TO_INPUT_FILTER = 13;
        public static final int MSG_SHOW_ACCESSIBILITY_BUTTON_CHOOSER = 14;
        public static final int MSG_INIT_SERVICE = 15;

        public MainHandler(Looper looper) {
            super(looper);
@@ -2495,6 +2496,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                case MSG_SHOW_ACCESSIBILITY_BUTTON_CHOOSER: {
                    showAccessibilityButtonTargetSelection();
                } break;

                case MSG_INIT_SERVICE: {
                    final Service service = (Service) msg.obj;
                    service.initializeService();
                } break;
            }
        }

@@ -2950,20 +2956,31 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                if (userState.mBindingServices.contains(mComponentName) || mWasConnectedAndDied) {
                    userState.mBindingServices.remove(mComponentName);
                    mWasConnectedAndDied = false;
                    try {
                       mServiceInterface.init(this, mId, mOverlayWindowToken);
                    onUserStateChangedLocked(userState);
                    } catch (RemoteException re) {
                        Slog.w(LOG_TAG, "Error while setting connection for service: "
                                + service, re);
                        binderDied();
                    }
                    // Initialize the service on the main handler after we're done setting up for
                    // the new configuration (for example, initializing the input filter).
                    mMainHandler.obtainMessage(MainHandler.MSG_INIT_SERVICE, this).sendToTarget();
                } else {
                    binderDied();
                }
            }
        }

        private void initializeService() {
            final IAccessibilityServiceClient serviceInterface;
            synchronized (mLock) {
                serviceInterface = mServiceInterface;
            }
            if (serviceInterface == null) return;
            try {
                serviceInterface.init(this, mId, mOverlayWindowToken);
            } catch (RemoteException re) {
                Slog.w(LOG_TAG, "Error while setting connection for service: "
                        + serviceInterface, re);
                binderDied();
            }
        }

        private boolean isCalledForCurrentUserLocked() {
            // We treat calls from a profile as if made by its parent as profiles
            // share the accessibility state of the parent. The call below
@@ -3456,18 +3473,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                    return region;
                }
                MagnificationController magnificationController = getMagnificationController();
                boolean forceRegistration = mSecurityPolicy.canControlMagnification(this);
                boolean initiallyRegistered = magnificationController.isRegisteredLocked();
                if (!initiallyRegistered && forceRegistration) {
                    magnificationController.register();
                }
                boolean registeredJustForThisCall =
                        registerMagnificationIfNeeded(magnificationController);
                final long identity = Binder.clearCallingIdentity();
                try {
                    magnificationController.getMagnificationRegion(region);
                    return region;
                } finally {
                    Binder.restoreCallingIdentity(identity);
                    if (!initiallyRegistered && forceRegistration) {
                    if (registeredJustForThisCall) {
                        magnificationController.unregister();
                    }
                }
@@ -3481,11 +3495,17 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                    return 0.0f;
                }
            }
            MagnificationController magnificationController = getMagnificationController();
            boolean registeredJustForThisCall =
                    registerMagnificationIfNeeded(magnificationController);
            final long identity = Binder.clearCallingIdentity();
            try {
                return getMagnificationController().getCenterX();
                return magnificationController.getCenterX();
            } finally {
                Binder.restoreCallingIdentity(identity);
                if (registeredJustForThisCall) {
                    magnificationController.unregister();
                }
            }
        }

@@ -3496,13 +3516,29 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                    return 0.0f;
                }
            }
            MagnificationController magnificationController = getMagnificationController();
            boolean registeredJustForThisCall =
                    registerMagnificationIfNeeded(magnificationController);
            final long identity = Binder.clearCallingIdentity();
            try {
                return getMagnificationController().getCenterY();
                return magnificationController.getCenterY();
            } finally {
                Binder.restoreCallingIdentity(identity);
                if (registeredJustForThisCall) {
                    magnificationController.unregister();
                }
            }
        }

        private boolean registerMagnificationIfNeeded(
                MagnificationController magnificationController) {
            if (!magnificationController.isRegisteredLocked()
                    && mSecurityPolicy.canControlMagnification(this)) {
                magnificationController.register();
                return true;
            }
            return false;
        }

        @Override
        public boolean resetMagnification(boolean animate) {
+2 −0
Original line number Diff line number Diff line
@@ -429,6 +429,8 @@ final class AccessibilityController {
        }

        public void getMagnificationRegionLocked(Region outMagnificationRegion) {
            // Make sure we're working with the most current bounds
            mMagnifedViewport.recomputeBoundsLocked();
            mMagnifedViewport.getMagnificationRegionLocked(outMagnificationRegion);
        }