use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.
the class KeyboardView method sendAccessibilityEventForUnicodeCharacter.
private void sendAccessibilityEventForUnicodeCharacter(int eventType, int code) {
if (mAccessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
onInitializeAccessibilityEvent(event);
String text = null;
// This is very efficient since the properties are cached.
final boolean speakPassword = Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0, UserHandle.USER_CURRENT_OR_SELF) != 0;
// used to avoid leaking passwords.
if (speakPassword || mAudioManager.isBluetoothA2dpOn() || mAudioManager.isWiredHeadsetOn()) {
switch(code) {
case Keyboard.KEYCODE_ALT:
text = mContext.getString(R.string.keyboardview_keycode_alt);
break;
case Keyboard.KEYCODE_CANCEL:
text = mContext.getString(R.string.keyboardview_keycode_cancel);
break;
case Keyboard.KEYCODE_DELETE:
text = mContext.getString(R.string.keyboardview_keycode_delete);
break;
case Keyboard.KEYCODE_DONE:
text = mContext.getString(R.string.keyboardview_keycode_done);
break;
case Keyboard.KEYCODE_MODE_CHANGE:
text = mContext.getString(R.string.keyboardview_keycode_mode_change);
break;
case Keyboard.KEYCODE_SHIFT:
text = mContext.getString(R.string.keyboardview_keycode_shift);
break;
case '\n':
text = mContext.getString(R.string.keyboardview_keycode_enter);
break;
default:
text = String.valueOf((char) code);
}
} else if (!mHeadsetRequiredToHearPasswordsAnnounced) {
// hover enter and hover exit event, so set the flag after the exit.
if (eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
mHeadsetRequiredToHearPasswordsAnnounced = true;
}
text = mContext.getString(R.string.keyboard_headset_required_to_hear_password);
} else {
text = mContext.getString(R.string.keyboard_password_character_no_headset);
}
event.getText().add(text);
mAccessibilityManager.sendAccessibilityEvent(event);
}
}
use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.
the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_OneService_NotifivationAfterTimeout.
@LargeTest
public void testSendAccessibilityEvent_OneService_NotifivationAfterTimeout() throws Exception {
// enable the mock accessibility service
ensureOnlyMockServicesEnabled(mContext, true, false);
// set the accessibility setting value
ensureAccessibilityEnabled(mContext, true);
// configure the mock service
MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance;
AccessibilityServiceInfo info = MockAccessibilityService.createDefaultInfo();
info.notificationTimeout = TIMEOUT_TEST_NOTIFICATION_TIMEOUT;
service.setServiceInfo(info);
// wait for the binder call to #setService to complete
Thread.sleep(TIMEOUT_BINDER_CALL);
// create and populate the first event to be sent
AccessibilityEvent firstEvent = AccessibilityEvent.obtain();
fullyPopulateDefaultAccessibilityEvent(firstEvent);
// create and populate the second event to be sent
AccessibilityEvent secondEvent = AccessibilityEvent.obtain();
fullyPopulateDefaultAccessibilityEvent(secondEvent);
// set expectations
service.expectEvent(secondEvent);
service.replay();
// send the events
mManagerService.sendAccessibilityEvent(firstEvent, UserHandle.USER_CURRENT);
mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_CURRENT);
// wait for #sendAccessibilityEvent to reach the backing service
Thread.sleep(TIMEOUT_BINDER_CALL);
try {
service.verify();
fail("No events must be dispatched before the expiration of the notification timeout.");
} catch (IllegalStateException ise) {
/* expected */
}
// wait for the configured notification timeout to expire
Thread.sleep(TIMEOUT_TEST_NOTIFICATION_TIMEOUT);
// verify if all expected methods have been called
assertMockServiceVerifiedWithinTimeout(service);
}
use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.
the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_OneService_MatchingPackageAndEventType.
@LargeTest
public void testSendAccessibilityEvent_OneService_MatchingPackageAndEventType() throws Exception {
// enable the mock accessibility service
ensureOnlyMockServicesEnabled(mContext, true, false);
// set the accessibility setting value
ensureAccessibilityEnabled(mContext, true);
// configure the mock service
MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance;
service.setServiceInfo(MockAccessibilityService.createDefaultInfo());
// wait for the binder call 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
service.expectEvent(sentEvent);
service.replay();
// send the event
mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT);
// verify if all expected methods have been called
assertMockServiceVerifiedWithinTimeout(service);
}
use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.
the class AccessibilityManagerTest method testSendAccessibilityEvent_AccessibilityEnabled.
@MediumTest
public void testSendAccessibilityEvent_AccessibilityEnabled() throws Exception {
AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
when(mMockService.sendAccessibilityEvent(eq(sentEvent), anyInt())).thenReturn(true).thenReturn(false);
AccessibilityManager manager = createManager(true);
manager.sendAccessibilityEvent(sentEvent);
assertSame("The event should be recycled.", sentEvent, AccessibilityEvent.obtain());
manager.sendAccessibilityEvent(sentEvent);
assertNotSame("The event should not be recycled.", sentEvent, AccessibilityEvent.obtain());
}
use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.
the class NotificationManagerService method sendAccessibilityEvent.
void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
AccessibilityManager manager = AccessibilityManager.getInstance(getContext());
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);
}
try {
manager.sendAccessibilityEvent(event);
} catch (IllegalStateException e) {
Slog.e(TAG, "sendAccessibilityEvent failed.", e);
}
}
Aggregations