Search in sources :

Example 81 with AccessibilityManager

use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by ParanoidAndroid.

the class NotificationManagerService method sendAccessibilityEvent.

private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
    AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
    if (!manager.isEnabled()) {
        return;
    }
    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
    event.setPackageName(packageName);
    event.setClassName(Notification.class.getName());
    event.setParcelableData(notification);
    CharSequence tickerText = notification.tickerText;
    if (!TextUtils.isEmpty(tickerText)) {
        event.getText().add(tickerText);
    }
    manager.sendAccessibilityEvent(event);
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Notification(android.app.Notification) ITransientNotification(android.app.ITransientNotification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 82 with AccessibilityManager

use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerTest method testSendAccessibilityEvent_AccessibilityDisabled.

@MediumTest
public void testSendAccessibilityEvent_AccessibilityDisabled() throws Exception {
    // create an event to be dispatched
    AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
    // configure the mock service behavior
    IAccessibilityManager mockServiceInterface = mMockServiceInterface;
    expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(), UserHandle.USER_OWNER)).andReturn(0);
    replay(mockServiceInterface);
    // invoke the method under test (accessibility disabled)
    AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface, UserHandle.USER_OWNER);
    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());
    }
    // verify the mock service was properly called
    verify(mockServiceInterface);
}
Also used : IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 83 with AccessibilityManager

use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerTest method testInterrupt.

@MediumTest
public void testInterrupt() throws Exception {
    // configure the mock service behavior
    IAccessibilityManager mockServiceInterface = mMockServiceInterface;
    expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(), UserHandle.USER_OWNER)).andReturn(AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
    mockServiceInterface.interrupt(UserHandle.USER_OWNER);
    replay(mockServiceInterface);
    // invoke the method under test
    AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface, UserHandle.USER_OWNER);
    manager.interrupt();
    // verify the mock service was properly called
    verify(mockServiceInterface);
}
Also used : IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 84 with AccessibilityManager

use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerTest method testSendAccessibilityEvent_AccessibilityEnabled.

@MediumTest
public void testSendAccessibilityEvent_AccessibilityEnabled() throws Exception {
    // create an event to be dispatched
    AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
    // configure the mock service behavior
    IAccessibilityManager mockServiceInterface = mMockServiceInterface;
    expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(), UserHandle.USER_OWNER)).andReturn(AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
    expect(mockServiceInterface.sendAccessibilityEvent(eqAccessibilityEvent(sentEvent), UserHandle.USER_OWNER)).andReturn(true);
    expect(mockServiceInterface.sendAccessibilityEvent(eqAccessibilityEvent(sentEvent), UserHandle.USER_OWNER)).andReturn(false);
    replay(mockServiceInterface);
    // invoke the method under test (manager and service in different processes)
    AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface, UserHandle.USER_OWNER);
    manager.sendAccessibilityEvent(sentEvent);
    // check expected result
    AccessibilityEvent nextEventDifferentProcesses = AccessibilityEvent.obtain();
    assertSame("The manager and the service are in different processes, so the event must be " + "recycled", sentEvent, nextEventDifferentProcesses);
    // invoke the method under test (manager and service in the same process)
    manager.sendAccessibilityEvent(sentEvent);
    // check expected result
    AccessibilityEvent nextEventSameProcess = AccessibilityEvent.obtain();
    assertNotSame("The manager and the service are in the same process, so the event must not" + "be recycled", sentEvent, nextEventSameProcess);
    // verify the mock service was properly called
    verify(mockServiceInterface);
}
Also used : IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 85 with AccessibilityManager

use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by ParanoidAndroid.

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;
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Aggregations

AccessibilityManager (android.view.accessibility.AccessibilityManager)170 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)54 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)49 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)43 ArrayList (java.util.ArrayList)26 ServiceInfo (android.content.pm.ServiceInfo)20 MediumTest (android.test.suitebuilder.annotation.MediumTest)20 ComponentName (android.content.ComponentName)16 Drawable (android.graphics.drawable.Drawable)10 Bundle (android.os.Bundle)9 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)8 RestrictedPreference (com.android.settingslib.RestrictedPreference)8 SuppressLint (android.annotation.SuppressLint)7 Context (android.content.Context)7 SwitchPreference (android.support.v14.preference.SwitchPreference)7 ListPreference (android.support.v7.preference.ListPreference)7 Preference (android.support.v7.preference.Preference)7 AccessibilityNodeProvider (android.view.accessibility.AccessibilityNodeProvider)7 ITransientNotification (android.app.ITransientNotification)6 Notification (android.app.Notification)6