private final Object mLock = new Object();
+ private final Binder mToken = new Binder();
+
private int mInitialFrozenRotation = INITIAL_FROZEN_ROTATION_UNSPECIFIED;
private IAccessibilityServiceClient mClient;
try {
// Calling out with a lock held is fine since if the system
// process is gone the client calling in will be killed.
- manager.registerUiTestAutomationService(client, info);
+ manager.registerUiTestAutomationService(mToken, client, info);
mClient = client;
} catch (RemoteException re) {
throw new IllegalStateException("Error while registering UiTestAutomationService.", re);
return -1;
}
- public void registerUiTestAutomationService(IAccessibilityServiceClient serviceClient,
+ public void registerUiTestAutomationService(IBinder owner, IAccessibilityServiceClient serviceClient,
AccessibilityServiceInfo accessibilityServiceInfo) {
mSecurityPolicy.enforceCallingPermission(Manifest.permission.RETRIEVE_WINDOW_CONTENT,
FUNCTION_REGISTER_UI_TEST_AUTOMATION_SERVICE);
+ "already registered!");
}
+ try {
+ owner.linkToDeath(userState.mUiAutomationSerivceOnwerDeathRecipient, 0);
+ } catch (RemoteException re) {
+ Slog.e(LOG_TAG, "Couldn't register for the death of a"
+ + " UiTestAutomationService!", re);
+ return;
+ }
+
+ userState.mUiAutomationServiceOwner = owner;
userState.mUiAutomationServiceClient = serviceClient;
// Set the temporary state.
if (!mIsAutomation) {
mContext.unbindService(this);
} else {
- userState.mUiAutomationService = null;
- userState.mUiAutomationServiceClient = null;
+ userState.destroyUiAutomationService();
}
removeServiceLocked(this, userState);
dispose();
// the state based on values in the settings database.
userState.mInstalledServices.remove(mAccessibilityServiceInfo);
userState.mEnabledServices.remove(mComponentName);
- userState.mUiAutomationService = null;
- userState.mUiAutomationServiceClient = null;
+ userState.destroyUiAutomationService();
}
onUserStateChangedLocked(userState);
}
private Service mUiAutomationService;
private IAccessibilityServiceClient mUiAutomationServiceClient;
+ private IBinder mUiAutomationServiceOwner;
+ private final DeathRecipient mUiAutomationSerivceOnwerDeathRecipient =
+ new DeathRecipient() {
+ @Override
+ public void binderDied() {
+ mUiAutomationServiceOwner.unlinkToDeath(
+ mUiAutomationSerivceOnwerDeathRecipient, 0);
+ mUiAutomationServiceOwner = null;
+ if (mUiAutomationService != null) {
+ mUiAutomationService.binderDied();
+ }
+ }
+ };
+
public UserState(int userId) {
mUserId = userId;
}
// Clear UI test automation state.
if (mUiAutomationService != null) {
mUiAutomationService.binderDied();
- mUiAutomationService = null;
- mUiAutomationServiceClient = null;
}
// Unbind all services.
mIsEnhancedWebAccessibilityEnabled = false;
mIsDisplayMagnificationEnabled = false;
}
+
+ public void destroyUiAutomationService() {
+ mUiAutomationService = null;
+ mUiAutomationServiceClient = null;
+ if (mUiAutomationServiceOwner != null) {
+ mUiAutomationServiceOwner.unlinkToDeath(
+ mUiAutomationSerivceOnwerDeathRecipient, 0);
+ mUiAutomationServiceOwner = null;
+ }
+ }
}
private final class AccessibilityContentObserver extends ContentObserver {