1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.accessibility.cts; 18 19 import android.accessibilityservice.AccessibilityServiceInfo; 20 import android.app.Service; 21 import android.test.InstrumentationTestCase; 22 import android.test.suitebuilder.annotation.MediumTest; 23 import android.view.accessibility.AccessibilityEvent; 24 import android.view.accessibility.AccessibilityManager; 25 26 import java.util.List; 27 28 /** 29 * Tests whether accessibility service infos are properly reported. Logically, 30 * this test belongs to cts/test/test/accessibilityservice but the tests there 31 * are using the new UiAutomation API which disables all currently active 32 * accessibility service and the fake service used for implementing the UI 33 * automation is not reported through the APIs. 34 */ 35 public class AccessibilityServiceInfoTest extends InstrumentationTestCase { 36 37 @Override 38 public void setUp() throws Exception { 39 ServiceControlUtils.enableSpeakingAndVibratingServices(getInstrumentation()); 40 } 41 42 @Override 43 public void tearDown() { 44 ServiceControlUtils.turnAccessibilityOff(getInstrumentation()); 45 } 46 47 /** 48 * Tests whether a service can that requested it can retrieve 49 * window content. 50 */ 51 @MediumTest 52 @SuppressWarnings("deprecation") 53 public void testAccessibilityServiceInfoForEnabledService() { 54 AccessibilityManager accessibilityManager = (AccessibilityManager) 55 getInstrumentation().getContext().getSystemService(Service.ACCESSIBILITY_SERVICE); 56 List<AccessibilityServiceInfo> enabledServices = 57 accessibilityManager.getEnabledAccessibilityServiceList( 58 AccessibilityServiceInfo.FEEDBACK_SPOKEN); 59 assertSame("There should be one speaking service.", 1, enabledServices.size()); 60 AccessibilityServiceInfo speakingService = enabledServices.get(0); 61 assertSame(AccessibilityEvent.TYPES_ALL_MASK, speakingService.eventTypes); 62 assertSame(AccessibilityServiceInfo.FEEDBACK_SPOKEN, speakingService.feedbackType); 63 assertSame(AccessibilityServiceInfo.DEFAULT 64 | AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS 65 | AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE 66 | AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS 67 | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS, 68 speakingService.flags); 69 assertSame(0l, speakingService.notificationTimeout); 70 assertEquals("Some description", speakingService.getDescription()); 71 assertNull(speakingService.packageNames /*all packages*/); 72 assertNotNull(speakingService.getId()); 73 assertSame(speakingService.getCapabilities(), 74 AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS 75 | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION 76 | AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT); 77 assertEquals("foo.bar.Activity", speakingService.getSettingsActivityName()); 78 assertEquals("Some description", speakingService.loadDescription( 79 getInstrumentation().getContext().getPackageManager())); 80 assertEquals("Some summary", speakingService.loadSummary( 81 getInstrumentation().getContext().getPackageManager())); 82 assertNotNull(speakingService.getResolveInfo()); 83 } 84 } 85