Search in sources :

Example 86 with AccessibilityServiceInfo

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

the class AccessibilityManagerService method updateServicesLocked.

private void updateServicesLocked(UserState userState) {
    Map<ComponentName, Service> componentNameToServiceMap = userState.mComponentNameToServiceMap;
    boolean isUnlockingOrUnlocked = mContext.getSystemService(UserManager.class).isUserUnlockingOrUnlocked(userState.mUserId);
    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);
        // Ignore non-encryption-aware services until user is unlocked
        if (!isUnlockingOrUnlocked && !installedService.isDirectBootAware()) {
            Slog.d(LOG_TAG, "Ignoring non-encryption-aware service " + componentName);
            continue;
        }
        // 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();
            }
        }
    }
    updateAccessibilityEnabledSetting(userState);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) UserManager(android.os.UserManager) AccessibilityService(android.accessibilityservice.AccessibilityService) ComponentName(android.content.ComponentName) Point(android.graphics.Point)

Example 87 with AccessibilityServiceInfo

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

the class DevicePolicyManagerService method setPermittedAccessibilityServices.

@Override
public boolean setPermittedAccessibilityServices(ComponentName who, List packageList) {
    if (!mHasFeature) {
        return false;
    }
    Preconditions.checkNotNull(who, "ComponentName is null");
    if (packageList != null) {
        int userId = UserHandle.getCallingUserId();
        List<AccessibilityServiceInfo> enabledServices = null;
        long id = mInjector.binderClearCallingIdentity();
        try {
            UserInfo user = getUserInfo(userId);
            if (user.isManagedProfile()) {
                userId = user.profileGroupId;
            }
            AccessibilityManager accessibilityManager = getAccessibilityManagerForUser(userId);
            enabledServices = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
        } finally {
            mInjector.binderRestoreCallingIdentity(id);
        }
        if (enabledServices != null) {
            List<String> enabledPackages = new ArrayList<String>();
            for (AccessibilityServiceInfo service : enabledServices) {
                enabledPackages.add(service.getResolveInfo().serviceInfo.packageName);
            }
            if (!checkPackagesInPermittedListOrSystem(enabledPackages, packageList, userId)) {
                Slog.e(LOG_TAG, "Cannot set permitted accessibility services, " + "because it contains already enabled accesibility services.");
                return false;
            }
        }
    }
    synchronized (this) {
        ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
        admin.permittedAccessiblityServices = packageList;
        saveSettingsLocked(UserHandle.getCallingUserId());
    }
    return true;
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) ParcelableString(com.android.internal.util.ParcelableString)

Example 88 with AccessibilityServiceInfo

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

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_DiffFeedback.

@LargeTest
public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_DiffFeedback() throws Exception {
    // enable the mock accessibility services
    ensureOnlyMockServicesEnabled(mContext, true, true);
    // set the accessibility setting value
    ensureAccessibilityEnabled(mContext, true);
    // configure the first mock service
    MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance;
    AccessibilityServiceInfo firstInfo = MockAccessibilityService.createDefaultInfo();
    firstInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
    firstService.setServiceInfo(firstInfo);
    // configure the second mock service
    MockAccessibilityService secondService = MySecondMockAccessibilityService.sInstance;
    AccessibilityServiceInfo secondInfo = MockAccessibilityService.createDefaultInfo();
    secondInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_HAPTIC;
    secondService.setServiceInfo(secondInfo);
    // 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.expectEvent(sentEvent);
    firstService.replay();
    // set expectations for the second mock service
    secondService.expectEvent(sentEvent);
    secondService.replay();
    // send the event
    mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT);
    // 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)

Example 89 with AccessibilityServiceInfo

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

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault.

@LargeTest
public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault() throws Exception {
    // enable the mock accessibility services
    ensureOnlyMockServicesEnabled(mContext, true, true);
    // set the accessibility setting value
    ensureAccessibilityEnabled(mContext, 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_CURRENT);
    // 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)

Example 90 with AccessibilityServiceInfo

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

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 = new AccessibilityServiceInfo();
    accessibilityServiceInfo.packageNames = new String[] { "foo.bar" };
    expectedServices.add(accessibilityServiceInfo);
    // configure the mock service behavior
    when(mMockService.getInstalledAccessibilityServiceList(anyInt())).thenReturn(expectedServices);
    // invoke the method under test
    AccessibilityManager manager = createManager(true);
    List<AccessibilityServiceInfo> receivedServices = manager.getInstalledAccessibilityServiceList();
    verify(mMockService).getInstalledAccessibilityServiceList(UserHandle.USER_CURRENT);
    // check expected result (list equals() compares it contents as well)
    assertEquals("All expected services must be returned", expectedServices, receivedServices);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)123 ComponentName (android.content.ComponentName)30 Point (android.graphics.Point)30 ServiceInfo (android.content.pm.ServiceInfo)29 ArrayList (java.util.ArrayList)26 LargeTest (android.test.suitebuilder.annotation.LargeTest)25 ResolveInfo (android.content.pm.ResolveInfo)20 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)20 AccessibilityManager (android.view.accessibility.AccessibilityManager)19 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)17 AccessibilityService (android.accessibilityservice.AccessibilityService)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)13 RemoteException (android.os.RemoteException)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 UserInfo (android.content.pm.UserInfo)6 ParcelableString (com.android.internal.util.ParcelableString)6 IOException (java.io.IOException)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 UserManager (android.os.UserManager)5