1 /*
<lambda>null2  * Copyright (C) 2022 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 package com.android.bedstead.nene.accessibility
17 
18 import android.accessibilityservice.AccessibilityServiceInfo
19 import android.view.accessibility.AccessibilityManager
20 import com.android.bedstead.nene.TestApis
21 import com.android.bedstead.nene.annotations.Experimental
22 
23 /** Test APIs related to accessibility.  */
24 @Experimental
25 object Accessibility {
26 
27     private val accessibilityManager =
28             TestApis.context().instrumentedContext()
29                     .getSystemService(AccessibilityManager::class.java)!!
30 
31     /**
32      * Get installed accessibility services.
33      *
34      *
35      * See [AccessibilityManager.getInstalledAccessibilityServiceList].
36      */
37     fun installedAccessibilityServices(): Set<AccessibilityService> =
38         accessibilityManager
39                 .installedAccessibilityServiceList.asSequence()
40                 .map { serviceInfo -> AccessibilityService(serviceInfo) }
41                 .toSet()
42 
43     /**
44      * Get enabled accessibility services.
45      *
46      *
47      * See [AccessibilityManager.getEnabledAccessibilityServiceList].
48      */
49     fun enabledAccessibilityServices(): Set<AccessibilityService> =
50             accessibilityManager
51                     .getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK)
52                     .asSequence()
53                     .map { serviceInfo -> AccessibilityService(serviceInfo) }
54                     .toSet()
55 }
56