use of android.view.accessibility.IAccessibilityManager in project android_frameworks_base by ParanoidAndroid.
the class UiAutomationConnection method unregisterUiTestAutomationServiceLocked.
private void unregisterUiTestAutomationServiceLocked() {
IAccessibilityManager manager = IAccessibilityManager.Stub.asInterface(ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
try {
// Calling out with a lock held is fine since if the system
// process is gone the client calling in will be killed.
manager.unregisterUiTestAutomationService(mClient);
mClient = null;
} catch (RemoteException re) {
throw new IllegalStateException("Error while unregistering UiTestAutomationService", re);
}
}
use of android.view.accessibility.IAccessibilityManager in project android_frameworks_base by ParanoidAndroid.
the class UiAutomationConnection method registerUiTestAutomationServiceLocked.
private void registerUiTestAutomationServiceLocked(IAccessibilityServiceClient client) {
IAccessibilityManager manager = IAccessibilityManager.Stub.asInterface(ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.flags |= AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
info.setCapabilities(AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS);
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(mToken, client, info);
mClient = client;
} catch (RemoteException re) {
throw new IllegalStateException("Error while registering UiTestAutomationService.", re);
}
}
use of android.view.accessibility.IAccessibilityManager in project android_frameworks_base by ParanoidAndroid.
the class AccessibilityManagerTest method testGetAccessibilityServiceList.
@MediumTest
public void testGetAccessibilityServiceList() throws Exception {
// create a list of installed accessibility services the mock service returns
List<AccessibilityServiceInfo> expectedServices = new ArrayList<AccessibilityServiceInfo>();
AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
accessibilityServiceInfo.packageNames = new String[] { "foo.bar" };
expectedServices.add(accessibilityServiceInfo);
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(), UserHandle.USER_OWNER)).andReturn(AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
expect(mockServiceInterface.getInstalledAccessibilityServiceList(UserHandle.USER_OWNER)).andReturn(expectedServices);
replay(mockServiceInterface);
// invoke the method under test
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface, UserHandle.USER_OWNER);
List<AccessibilityServiceInfo> receivedServices = manager.getInstalledAccessibilityServiceList();
// check expected result (list equals() compares it contents as well)
assertEquals("All expected services must be returned", receivedServices, expectedServices);
// verify the mock service was properly called
verify(mockServiceInterface);
}
use of android.view.accessibility.IAccessibilityManager in project android_frameworks_base by ParanoidAndroid.
the class AccessibilityManagerTest method testIsEnabled.
@LargeTest
public void testIsEnabled() throws Exception {
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(), UserHandle.USER_OWNER)).andReturn(AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
replay(mockServiceInterface);
// invoke the method under test
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface, UserHandle.USER_OWNER);
boolean isEnabledServiceEnabled = manager.isEnabled();
// check expected result
assertTrue("Must be enabled since the mock service is enabled", isEnabledServiceEnabled);
// disable accessibility
manager.getClient().setState(0);
// wait for the asynchronous IBinder call to complete
Thread.sleep(TIMEOUT_BINDER_CALL);
// invoke the method under test
boolean isEnabledServcieDisabled = manager.isEnabled();
// check expected result
assertFalse("Must be disabled since the mock service is disabled", isEnabledServcieDisabled);
// verify the mock service was properly called
verify(mockServiceInterface);
}
use of android.view.accessibility.IAccessibilityManager in project platform_frameworks_base by android.
the class EnableAccessibilityController method enableAccessibility.
public static boolean enableAccessibility(Context context) {
final IAccessibilityManager accessibilityManager = IAccessibilityManager.Stub.asInterface(ServiceManager.getService("accessibility"));
final WindowManagerInternal windowManager = LocalServices.getService(WindowManagerInternal.class);
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
ComponentName componentName = getInstalledSpeakingAccessibilityServiceComponent(context);
if (componentName == null) {
return false;
}
boolean keyguardLocked = windowManager.isKeyguardLocked();
final boolean hasMoreThanOneUser = userManager.getUsers().size() > 1;
try {
if (!keyguardLocked || !hasMoreThanOneUser) {
final int userId = ActivityManager.getCurrentUser();
accessibilityManager.enableAccessibilityService(componentName, userId);
} else if (keyguardLocked) {
accessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved(componentName, true);
}
} catch (RemoteException e) {
Log.e(TAG, "cannot enable accessibilty: " + e);
}
return true;
}
Aggregations