1 /*
2  * Copyright (C) 2010 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.accessibilityservice.cts;
18 
19 import static androidx.test.InstrumentationRegistry.getContext;
20 
21 import static org.junit.Assert.assertTrue;
22 
23 import android.accessibility.cts.common.AccessibilityDumpOnFailureRule;
24 import android.content.Intent;
25 import android.content.pm.PackageManager;
26 import android.content.pm.ResolveInfo;
27 import android.platform.test.annotations.AppModeFull;
28 import android.platform.test.annotations.Presubmit;
29 import android.provider.Settings;
30 
31 import androidx.test.filters.MediumTest;
32 import androidx.test.runner.AndroidJUnit4;
33 
34 import com.android.compatibility.common.util.CddTest;
35 
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 
40 import java.util.List;
41 
42 /**
43  * This test case is responsible to verify that the intent for launching
44  * accessibility settings has an activity that handles it.
45  */
46 @Presubmit
47 @RunWith(AndroidJUnit4.class)
48 @CddTest(requirements = {"3.10/C-1-1,C-1-2"})
49 public class AccessibilitySettingsTest {
50 
51     @Rule
52     public final AccessibilityDumpOnFailureRule mDumpOnFailureRule =
53             new AccessibilityDumpOnFailureRule();
54 
55     @MediumTest
56     @AppModeFull
57     @Test
testAccessibilitySettingsIntentHandled()58     public void testAccessibilitySettingsIntentHandled() throws Throwable {
59         PackageManager packageManager = getContext().getPackageManager();
60         Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
61         List<ResolveInfo> resolvedActivities = packageManager.queryIntentActivities(intent,
62                 PackageManager.MATCH_DEFAULT_ONLY);
63 
64         // make sure accessibility settings exist
65         String message = "Accessibility settings activity must be launched via Intent " +
66                 "Settings.ACTION_ACCESSIBILITY_SETTINGS";
67         assertTrue(message, !resolvedActivities.isEmpty());
68     }
69 }
70 
71