AccessibilityServices { public boolean isSwitchAccessEnabled() { return isAccessibilityServiceEnabled(SWITCH_ACCESS.flattenedComponentName()); } AccessibilityServices(AccessibilityManager accessibilityManager, CaptionManager captionManager); static AccessibilityServices newInstance(Context context); boolean isSpokenFeedbackEnabled(); boolean isClosedCaptioningEnabled(); boolean isSwitchAccessEnabled();  }
@Test public void givenEnabledServicesListIncludesSwitchAccess_thenReportsSwitchAccessIsEnabled() { AccessibilityServiceInfo switchAccessServiceInfo = accessibilityServiceInfoWithId(Service.SWITCH_ACCESS.flattenedComponentName()); given(accessibilityManager.getEnabledAccessibilityServiceList(FEEDBACK_ALL_MASK)) .willReturn(Collections.singletonList(switchAccessServiceInfo)); boolean switchAccessEnabled = accessibilityServices.isSwitchAccessEnabled(); assertThat(switchAccessEnabled).isTrue(); }
@Test public void givenEnabledServicesListDoesNotIncludeSwitchAccess_thenReportsSwitchAccessIsDisabled() { AccessibilityServiceInfo anyOtherServiceInfo = accessibilityServiceInfoWithId("not switch access"); given(accessibilityManager.getEnabledAccessibilityServiceList(FEEDBACK_ALL_MASK)) .willReturn(Collections.singletonList(anyOtherServiceInfo)); boolean switchAccessEnabled = accessibilityServices.isSwitchAccessEnabled(); assertThat(switchAccessEnabled).isFalse(); }