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

This commit is contained in:
Phil Weaver
2016-05-10 20:18:11 +00:00
committed by Android (Google) Code Review
4 changed files with 63 additions and 21 deletions

View File

@@ -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();

View File

@@ -75,7 +75,7 @@ interface IAccessibilityServiceConnection {
float getMagnificationCenterY();
Region getMagnifiedRegion();
Region getMagnificationRegion();
boolean resetMagnification(boolean animate);

View File

@@ -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) {
if (!isCalledForCurrentUserLocked()) {
return Region.obtain();
}
}
final long identity = Binder.clearCallingIdentity();
try {
final Region region = Region.obtain();
getMagnificationController().getMagnificationRegion(region);
return region;
} finally {
Binder.restoreCallingIdentity(identity);
if (!isCalledForCurrentUserLocked()) {
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 {
magnificationController.getMagnificationRegion(region);
return region;
} finally {
Binder.restoreCallingIdentity(identity);
if (!initiallyRegistered && forceRegistration) {
magnificationController.unregister();
}
}
}
}
@@ -2940,13 +2965,17 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
if (!permissionGranted) {
return false;
}
}
final long identity = Binder.clearCallingIdentity();
try {
return getMagnificationController().setScaleAndCenter(
scale, centerX, centerY, animate, mId);
} finally {
Binder.restoreCallingIdentity(identity);
final long identity = Binder.clearCallingIdentity();
try {
MagnificationController magnificationController = getMagnificationController();
if (!magnificationController.isRegisteredLocked()) {
magnificationController.register();
}
return magnificationController
.setScaleAndCenter(scale, centerX, centerY, animate, mId);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
}

View File

@@ -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;