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

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

Merge "Reduce cost of a11y services with magnification." into nyc-dev

am: cdaaaaad

* commit 'cdaaaaad':
  Reduce cost of a11y services with magnification.

Change-Id: Ib93769bbbce508d0eae77cd830d361e5e686de47
parents 9f519245 cdaaaaad
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -949,7 +949,7 @@ public abstract class AccessibilityService extends Service {
                            mService.mConnectionId);
            if (connection != null) {
                try {
                    return connection.getMagnifiedRegion();
                    return connection.getMagnificationRegion();
                } catch (RemoteException re) {
                    Log.w(LOG_TAG, "Failed to obtain magnified region", re);
                    re.rethrowFromSystemServer();
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ interface IAccessibilityServiceConnection {

    float getMagnificationCenterY();

    Region getMagnifiedRegion();
    Region getMagnificationRegion();

    boolean resetMagnification(boolean animate);

+47 −18
Original line number Diff line number Diff line
@@ -1737,7 +1737,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
        }

        if (userState.mIsDisplayMagnificationEnabled ||
                userHasMagnificationServicesLocked(userState)) {
                userHasListeningMagnificationServicesLocked(userState)) {
            // Initialize the magnification controller if necessary
            getMagnificationController();
            mMagnificationController.register();
@@ -1761,6 +1761,22 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
        return false;
    }

    /**
     * Returns whether the specified user has any services that are capable of
     * controlling magnification and are actively listening for magnification updates.
     */
    private boolean userHasListeningMagnificationServicesLocked(UserState userState) {
        final List<Service> services = userState.mBoundServices;
        for (int i = 0, count = services.size(); i < count; i++) {
            final Service service = services.get(i);
            if (mSecurityPolicy.canControlMagnification(service)
                    && service.mInvocationHandler.mIsMagnificationCallbackEnabled) {
                return true;
            }
        }
        return false;
    }

    private void updateSoftKeyboardShowModeLocked(UserState userState) {
        final int userId = userState.mUserId;
        // Only check whether we need to reset the soft keyboard mode if it is not set to the
@@ -2864,19 +2880,28 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
        }

        @Override
        public Region getMagnifiedRegion() {
        public Region getMagnificationRegion() {
            synchronized (mLock) {
                final Region region = Region.obtain();
                if (!isCalledForCurrentUserLocked()) {
                    return Region.obtain();
                    return region;
                }
                MagnificationController magnificationController = getMagnificationController();
                boolean forceRegistration = mSecurityPolicy.canControlMagnification(this);
                boolean initiallyRegistered = magnificationController.isRegisteredLocked();
                if (!initiallyRegistered && forceRegistration) {
                    magnificationController.register();
                }
                final long identity = Binder.clearCallingIdentity();
                try {
                final Region region = Region.obtain();
                getMagnificationController().getMagnificationRegion(region);
                    magnificationController.getMagnificationRegion(region);
                    return region;
                } finally {
                    Binder.restoreCallingIdentity(identity);
                    if (!initiallyRegistered && forceRegistration) {
                        magnificationController.unregister();
                    }
                }
            }
        }

@@ -2940,15 +2965,19 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                if (!permissionGranted) {
                    return false;
                }
            }
                final long identity = Binder.clearCallingIdentity();
                try {
                return getMagnificationController().setScaleAndCenter(
                        scale, centerX, centerY, animate, mId);
                    MagnificationController magnificationController = getMagnificationController();
                    if (!magnificationController.isRegisteredLocked()) {
                        magnificationController.register();
                    }
                    return magnificationController
                            .setScaleAndCenter(scale, centerX, centerY, animate, mId);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            }
        }

        @Override
        public void setMagnificationCallbackEnabled(boolean enabled) {
+13 −0
Original line number Diff line number Diff line
@@ -151,6 +151,15 @@ class MagnificationController {
        }
    }

    /**
     * Check if we are registered. Note that we may be planning to unregister at any moment.
     *
     * @return {@code true} if the controller is registered. {@code false} otherwise.
     */
    public boolean isRegisteredLocked() {
        return mRegistered;
    }

    private void unregisterInternalLocked() {
        if (mRegistered) {
            mSpecAnimationBridge.setEnabled(false);
@@ -179,6 +188,10 @@ class MagnificationController {
     */
    private void onMagnificationRegionChanged(Region magnified, boolean updateSpec) {
        synchronized (mLock) {
            if (!mRegistered) {
                // Don't update if we've unregistered
                return;
            }
            boolean magnificationChanged = false;
            boolean boundsChanged = false;