Merge "Reduce cost of a11y services with magnification." into nyc-dev
This commit is contained in:
@@ -949,7 +949,7 @@ public abstract class AccessibilityService extends Service {
|
|||||||
mService.mConnectionId);
|
mService.mConnectionId);
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
return connection.getMagnifiedRegion();
|
return connection.getMagnificationRegion();
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.w(LOG_TAG, "Failed to obtain magnified region", re);
|
Log.w(LOG_TAG, "Failed to obtain magnified region", re);
|
||||||
re.rethrowFromSystemServer();
|
re.rethrowFromSystemServer();
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ interface IAccessibilityServiceConnection {
|
|||||||
|
|
||||||
float getMagnificationCenterY();
|
float getMagnificationCenterY();
|
||||||
|
|
||||||
Region getMagnifiedRegion();
|
Region getMagnificationRegion();
|
||||||
|
|
||||||
boolean resetMagnification(boolean animate);
|
boolean resetMagnification(boolean animate);
|
||||||
|
|
||||||
|
|||||||
@@ -1737,7 +1737,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userState.mIsDisplayMagnificationEnabled ||
|
if (userState.mIsDisplayMagnificationEnabled ||
|
||||||
userHasMagnificationServicesLocked(userState)) {
|
userHasListeningMagnificationServicesLocked(userState)) {
|
||||||
// Initialize the magnification controller if necessary
|
// Initialize the magnification controller if necessary
|
||||||
getMagnificationController();
|
getMagnificationController();
|
||||||
mMagnificationController.register();
|
mMagnificationController.register();
|
||||||
@@ -1761,6 +1761,22 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
|
|||||||
return false;
|
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) {
|
private void updateSoftKeyboardShowModeLocked(UserState userState) {
|
||||||
final int userId = userState.mUserId;
|
final int userId = userState.mUserId;
|
||||||
// Only check whether we need to reset the soft keyboard mode if it is not set to the
|
// 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
|
@Override
|
||||||
public Region getMagnifiedRegion() {
|
public Region getMagnificationRegion() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
final Region region = Region.obtain();
|
||||||
if (!isCalledForCurrentUserLocked()) {
|
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();
|
final long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
final Region region = Region.obtain();
|
magnificationController.getMagnificationRegion(region);
|
||||||
getMagnificationController().getMagnificationRegion(region);
|
|
||||||
return region;
|
return region;
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
|
if (!initiallyRegistered && forceRegistration) {
|
||||||
|
magnificationController.unregister();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2940,15 +2965,19 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
|
|||||||
if (!permissionGranted) {
|
if (!permissionGranted) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
final long identity = Binder.clearCallingIdentity();
|
final long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
return getMagnificationController().setScaleAndCenter(
|
MagnificationController magnificationController = getMagnificationController();
|
||||||
scale, centerX, centerY, animate, mId);
|
if (!magnificationController.isRegisteredLocked()) {
|
||||||
|
magnificationController.register();
|
||||||
|
}
|
||||||
|
return magnificationController
|
||||||
|
.setScaleAndCenter(scale, centerX, centerY, animate, mId);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMagnificationCallbackEnabled(boolean enabled) {
|
public void setMagnificationCallbackEnabled(boolean enabled) {
|
||||||
|
|||||||
@@ -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() {
|
private void unregisterInternalLocked() {
|
||||||
if (mRegistered) {
|
if (mRegistered) {
|
||||||
mSpecAnimationBridge.setEnabled(false);
|
mSpecAnimationBridge.setEnabled(false);
|
||||||
@@ -179,6 +188,10 @@ class MagnificationController {
|
|||||||
*/
|
*/
|
||||||
private void onMagnificationRegionChanged(Region magnified, boolean updateSpec) {
|
private void onMagnificationRegionChanged(Region magnified, boolean updateSpec) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
if (!mRegistered) {
|
||||||
|
// Don't update if we've unregistered
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean magnificationChanged = false;
|
boolean magnificationChanged = false;
|
||||||
boolean boundsChanged = false;
|
boolean boundsChanged = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user