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