use of android.view.accessibility.AccessibilityManager 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.view.accessibility.AccessibilityManager in project android_frameworks_base by DirtyUnicorns.
the class AccessibilityManagerTest method testSendAccessibilityEvent_AccessibilityDisabled.
@MediumTest
public void testSendAccessibilityEvent_AccessibilityDisabled() throws Exception {
AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
AccessibilityManager manager = createManager(false);
try {
manager.sendAccessibilityEvent(sentEvent);
fail("No accessibility events are sent if accessibility is disabled");
} catch (IllegalStateException ise) {
// check expected result
assertEquals("Accessibility off. Did you forget to check that?", ise.getMessage());
}
}
use of android.view.accessibility.AccessibilityManager 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);
}
use of android.view.accessibility.AccessibilityManager in project XobotOS by xamarin.
the class TwoStatePreference method sendAccessibilityEvent.
void sendAccessibilityEvent(View view) {
// Since the view is still not attached we create, populate,
// and send the event directly since we do not know when it
// will be attached and posting commands is not as clean.
AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getContext());
if (mSendClickAccessibilityEvent && accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
event.setEventType(AccessibilityEvent.TYPE_VIEW_CLICKED);
view.onInitializeAccessibilityEvent(event);
view.dispatchPopulateAccessibilityEvent(event);
accessibilityManager.sendAccessibilityEvent(event);
}
mSendClickAccessibilityEvent = false;
}
use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by AOSPA.
the class View method requestAccessibilityFocus.
/**
* Call this to try to give accessibility focus to this view.
*
* A view will not actually take focus if {@link AccessibilityManager#isEnabled()}
* returns false or the view is no visible or the view already has accessibility
* focus.
*
* See also {@link #focusSearch(int)}, which is what you call to say that you
* have focus, and you want your parent to look for the next one.
*
* @return Whether this view actually took accessibility focus.
*
* @hide
*/
public boolean requestAccessibilityFocus() {
AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) {
return false;
}
if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) {
return false;
}
if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) == 0) {
mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_FOCUSED;
ViewRootImpl viewRootImpl = getViewRootImpl();
if (viewRootImpl != null) {
viewRootImpl.setAccessibilityFocus(this, null);
}
invalidate();
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
return true;
}
return false;
}
Aggregations