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

This commit is contained in:
Phil Weaver
2017-08-31 21:20:31 +00:00
committed by Android (Google) Code Review
2 changed files with 56 additions and 18 deletions

View File

@@ -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();
}
onUserStateChangedLocked(userState);
// 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
@@ -3313,8 +3330,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
}
if (mMotionEventInjector != null) {
List<GestureDescription.GestureStep> steps = gestureSteps.getList();
mMotionEventInjector.injectEvents(steps, mServiceInterface, sequence);
return;
mMotionEventInjector.injectEvents(steps, mServiceInterface, sequence);
return;
} else {
Slog.e(LOG_TAG, "MotionEventInjector installation timed out");
}
@@ -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,14 +3516,30 @@ 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) {
synchronized (mLock) {

View File

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