1 /*
2  * 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.compatibility.common.deviceinfo
17 
18 import android.content.Context
19 import androidx.test.core.app.ApplicationProvider
20 import com.android.compatibility.common.util.DeviceConfigStateManager
21 import com.android.compatibility.common.util.DeviceInfoStore
22 
23 /**
24  * Input device info collector.
25  * Clarification: this collects input-related properties on the Android device under test.
26  * The name "InputDeviceInfo" should not be read as "InputDevice" "Info", but rather
27  * as "Input" "Device Info".
28  */
29 public final class InputDeviceInfo : DeviceInfo() {
30     private val LOG_TAG = "InputDeviceInfo"
31 
collectDeviceInfonull32     override fun collectDeviceInfo(store: DeviceInfoStore) {
33         collectInputInfo(store, "input")
34     }
35 
readDeviceConfignull36     private fun readDeviceConfig(namespace: String, name: String, default: String): String {
37         val context: Context = ApplicationProvider.getApplicationContext()
38         val stateManager = DeviceConfigStateManager(context, namespace, name)
39         val value = stateManager.get()
40         return if (value != null) value else default
41     }
42 
43     /**
44      * Collect info for input into a group.
45      */
collectInputInfonull46     private fun collectInputInfo(store: DeviceInfoStore, groupName: String) {
47         store.startGroup(groupName)
48 
49         val palmRejectionValue = readDeviceConfig("input_native_boot", "palm_rejection_enabled", "")
50         val palmRejectionEnabled = palmRejectionValue == "1" || palmRejectionValue == "true"
51         store.addResult("palm_rejection_enabled", palmRejectionEnabled)
52 
53         val velocityTrackerStrategyValue = readDeviceConfig(
54             "input_native_boot", "velocitytracker_strategy", "default"
55         )
56         store.addResult("velocitytracker_strategy", velocityTrackerStrategyValue)
57 
58         store.endGroup()
59     }
60 }
61