Search in sources :

Example 1 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class EnableAccessibilityController method enableAccessibility.

private void enableAccessibility() {
    List<AccessibilityServiceInfo> services = getInstalledSpeakingAccessibilityServices(mContext);
    if (services.isEmpty()) {
        return;
    }
    boolean keyguardLocked = false;
    try {
        keyguardLocked = mWindowManager.isKeyguardLocked();
    } catch (RemoteException re) {
    /* ignore */
    }
    final boolean hasMoreThanOneUser = mUserManager.getUsers().size() > 1;
    AccessibilityServiceInfo service = services.get(0);
    boolean enableTouchExploration = (service.flags & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0;
    // Try to find a service supporting explore by touch.
    if (!enableTouchExploration) {
        final int serviceCount = services.size();
        for (int i = 1; i < serviceCount; i++) {
            AccessibilityServiceInfo candidate = services.get(i);
            if ((candidate.flags & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0) {
                enableTouchExploration = true;
                service = candidate;
                break;
            }
        }
    }
    ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
    ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
    if (!keyguardLocked || !hasMoreThanOneUser) {
        final int userId = ActivityManager.getCurrentUser();
        String enabledServiceString = componentName.flattenToString();
        ContentResolver resolver = mContext.getContentResolver();
        // Enable one speaking accessibility service.
        Settings.Secure.putStringForUser(resolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServiceString, userId);
        // Allow the services we just enabled to toggle touch exploration.
        Settings.Secure.putStringForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, enabledServiceString, userId);
        // Enable touch exploration.
        if (enableTouchExploration) {
            Settings.Secure.putIntForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1, userId);
        }
        // Enable accessibility script injection (AndroidVox) for web content.
        Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 1, userId);
        // Turn on accessibility mode last.
        Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_ENABLED, 1, userId);
    } else if (keyguardLocked) {
        try {
            mAccessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved(componentName, enableTouchExploration);
        } catch (RemoteException re) {
        /* ignore */
        }
    }
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver)

Example 2 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerService method getQueryBridge.

private Service getQueryBridge() {
    if (mQueryBridge == null) {
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.setCapabilities(AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT);
        mQueryBridge = new Service(UserHandle.USER_NULL, sFakeAccessibilityServiceComponentName, info);
    }
    return mQueryBridge;
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityService(android.accessibilityservice.AccessibilityService) IStatusBarService(com.android.internal.statusbar.IStatusBarService)

Example 3 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerService method manageServicesLocked.

private void manageServicesLocked(UserState userState) {
    Map<ComponentName, Service> componentNameToServiceMap = userState.mComponentNameToServiceMap;
    boolean isEnabled = userState.mIsAccessibilityEnabled;
    for (int i = 0, count = userState.mInstalledServices.size(); i < count; i++) {
        AccessibilityServiceInfo installedService = userState.mInstalledServices.get(i);
        ComponentName componentName = ComponentName.unflattenFromString(installedService.getId());
        Service service = componentNameToServiceMap.get(componentName);
        if (isEnabled) {
            // Wait for the binding if it is in process.
            if (userState.mBindingServices.contains(componentName)) {
                continue;
            }
            if (userState.mEnabledServices.contains(componentName)) {
                if (service == null) {
                    service = new Service(userState.mUserId, componentName, installedService);
                } else if (userState.mBoundServices.contains(service)) {
                    continue;
                }
                service.bindLocked();
            } else {
                if (service != null) {
                    service.unbindLocked();
                }
            }
        } else {
            if (service != null) {
                service.unbindLocked();
            } else {
                userState.mBindingServices.remove(componentName);
            }
        }
    }
    // sending accessibility events with no recipient across processes.
    if (isEnabled && userState.mEnabledServices.isEmpty()) {
        userState.mIsAccessibilityEnabled = false;
        Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0, userState.mUserId);
    }
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityService(android.accessibilityservice.AccessibilityService) IStatusBarService(com.android.internal.statusbar.IStatusBarService) ComponentName(android.content.ComponentName) Point(android.graphics.Point)

Example 4 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerService method updateLegacyCapabilities.

private void updateLegacyCapabilities(UserState userState) {
    // Up to JB-MR1 we had a white list with services that can enable touch
    // exploration. When a service is first started we show a dialog to the
    // use to get a permission to white list the service.
    final int installedServiceCount = userState.mInstalledServices.size();
    for (int i = 0; i < installedServiceCount; i++) {
        AccessibilityServiceInfo serviceInfo = userState.mInstalledServices.get(i);
        ResolveInfo resolveInfo = serviceInfo.getResolveInfo();
        if ((serviceInfo.getCapabilities() & AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION) == 0 && resolveInfo.serviceInfo.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ComponentName componentName = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
            if (userState.mTouchExplorationGrantedServices.contains(componentName)) {
                serviceInfo.setCapabilities(serviceInfo.getCapabilities() | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION);
            }
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ComponentName(android.content.ComponentName) Point(android.graphics.Point)

Example 5 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault.

@LargeTest
public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault() throws Exception {
    // set the accessibility setting value
    ensureAccessibilityEnabled(mContext, true);
    // enable the mock accessibility services
    ensureOnlyMockServicesEnabled(mContext, true, true);
    // configure the first mock service
    MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance;
    AccessibilityServiceInfo firstInfo = MyFirstMockAccessibilityService.createDefaultInfo();
    firstInfo.flags = AccessibilityServiceInfo.DEFAULT;
    firstService.setServiceInfo(firstInfo);
    // configure the second mock service
    MockAccessibilityService secondService = MySecondMockAccessibilityService.sInstance;
    secondService.setServiceInfo(MySecondMockAccessibilityService.createDefaultInfo());
    // wait for the binder calls to #setService to complete
    Thread.sleep(TIMEOUT_BINDER_CALL);
    // create and populate an event to be sent
    AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
    fullyPopulateDefaultAccessibilityEvent(sentEvent);
    // set expectations for the first mock service
    firstService.replay();
    // set expectations for the second mock service
    secondService.expectEvent(sentEvent);
    secondService.replay();
    // send the event
    mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER);
    // verify if all expected methods have been called
    assertMockServiceVerifiedWithinTimeout(firstService);
    assertMockServiceVerifiedWithinTimeout(secondService);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)210 ServiceInfo (android.content.pm.ServiceInfo)69 ComponentName (android.content.ComponentName)64 AccessibilityManager (android.view.accessibility.AccessibilityManager)54 ArrayList (java.util.ArrayList)50 ResolveInfo (android.content.pm.ResolveInfo)45 Point (android.graphics.Point)30 LargeTest (android.test.suitebuilder.annotation.LargeTest)25 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)20 Bundle (android.os.Bundle)17 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)17 AccessibilityService (android.accessibilityservice.AccessibilityService)13 Drawable (android.graphics.drawable.Drawable)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)13 Intent (android.content.Intent)12 HashSet (java.util.HashSet)12 RemoteException (android.os.RemoteException)9 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)8 RestrictedPreference (com.android.settingslib.RestrictedPreference)8 IOException (java.io.IOException)8