1 /*
2  * Copyright (C) 2024 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 com.android.quickstep
18 
19 import com.android.quickstep.util.DeviceConfigHelper
20 import com.android.quickstep.util.DeviceConfigHelper.PropReader
21 import java.io.PrintWriter
22 
23 /** Various configurations specific to nav-bar functionalities */
24 class DeviceConfigWrapper private constructor(propReader: PropReader) {
25 
26     val customLpnhThresholds =
27         propReader.get(
28             "CUSTOM_LPNH_THRESHOLDS",
29             true,
30             "Add dev options and server side control to customize the LPNH trigger slop and milliseconds"
31         )
32 
33     val customLphThresholds =
34         propReader.get(
35             "CUSTOM_LPH_THRESHOLDS",
36             true,
37             "Server side control to customize LPH timeout and touch slop"
38         )
39 
40     val customLpaaThresholds =
41         propReader.get(
42             "CUSTOM_LPAA_THRESHOLDS",
43             false,
44             "Server side control to customize LPAA timeout and touch slop"
45         )
46 
47     val overrideLpnhLphThresholds =
48         propReader.get(
49             "OVERRIDE_LPNH_LPH_THRESHOLDS",
50             false,
51             "Enable AGSA override for LPNH and LPH timeout and touch slop"
52         )
53 
54     val lpnhTimeoutMs =
55         propReader.get(
56             "LPNH_TIMEOUT_MS",
57             DEFAULT_LPNH_TIMEOUT_MS,
58             "Controls lpnh timeout in milliseconds"
59         )
60 
61     val lpnhSlopPercentage =
62         propReader.get("LPNH_SLOP_PERCENTAGE", 100, "Controls touch slop percentage for lpnh")
63 
64     val enableLpnhTwoStages =
65         propReader.get(
66             "ENABLE_LPNH_TWO_STAGES",
67             false,
68             "Enable two stage for LPNH duration and touch slop"
69         )
70 
71     val twoStageDurationPercentage =
72         propReader.get(
73             "TWO_STAGE_DURATION_PERCENTAGE",
74             200,
75             "Extends the duration to trigger a long press after a fraction of the gesture " +
76                 "slop is passed, expressed as a percentage (i.e. 200 = 2x)."
77         )
78 
79     val twoStageSlopPercentage =
80         propReader.get(
81             "TWO_STAGE_SLOP_PERCENTAGE",
82             50,
83             "Percentage of gesture slop region to trigger the extended long press duration."
84         )
85 
86     val animateLpnh = propReader.get("ANIMATE_LPNH", false, "Animates navbar when long pressing")
87 
88     val shrinkNavHandleOnPress =
89         propReader.get(
90             "SHRINK_NAV_HANDLE_ON_PRESS",
91             false,
92             "Shrinks navbar when long pressing if ANIMATE_LPNH is enabled"
93         )
94 
95     val enableLongPressNavHandle =
96         propReader.get(
97             "ENABLE_LONG_PRESS_NAV_HANDLE",
98             true,
99             "Enables long pressing on the bottom bar nav handle to trigger events."
100         )
101 
102     val enableSearchHapticHint =
103         propReader.get(
104             "ENABLE_SEARCH_HAPTIC_HINT",
105             true,
106             "Enables haptic hint while long pressing on the bottom bar nav handle."
107         )
108 
109     val enableSearchHapticCommit =
110         propReader.get(
111             "ENABLE_SEARCH_HAPTIC_COMMIT",
112             true,
113             "Enables haptic hint at end of long pressing on the bottom bar nav handle."
114         )
115 
116     val lpnhHapticHintStartScalePercent =
117         propReader.get("LPNH_HAPTIC_HINT_START_SCALE_PERCENT", 0, "Haptic hint start scale.")
118 
119     val lpnhHapticHintEndScalePercent =
120         propReader.get("LPNH_HAPTIC_HINT_END_SCALE_PERCENT", 100, "Haptic hint end scale.")
121 
122     val lpnhHapticHintScaleExponent =
123         propReader.get("LPNH_HAPTIC_HINT_SCALE_EXPONENT", 1, "Haptic hint scale exponent.")
124 
125     val lpnhHapticHintIterations =
126         propReader.get("LPNH_HAPTIC_HINT_ITERATIONS", 50, "Haptic hint number of iterations.")
127 
128     val enableLpnhDeepPress =
129         propReader.get(
130             "ENABLE_LPNH_DEEP_PRESS",
131             true,
132             "Long press of nav handle is instantly triggered if deep press is detected."
133         )
134 
135     val lpnhHapticHintDelay =
136         propReader.get("LPNH_HAPTIC_HINT_DELAY", 0, "Delay before haptic hint starts.")
137 
138     val lpnhExtraTouchWidthDp =
139         propReader.get(
140             "LPNH_EXTRA_TOUCH_WIDTH_DP",
141             0,
142             "Controls extra dp on the nav bar sides to trigger LPNH. Can be negative for a smaller touch region."
143         )
144 
145     /** Dump config values. */
dumpnull146     fun dump(prefix: String, writer: PrintWriter) {
147         writer.println("$prefix DeviceConfigWrapper:")
148         writer.println("$prefix\tcustomLpnhThresholds=$customLpnhThresholds")
149         writer.println("$prefix\tcustomLphThresholds=$customLphThresholds")
150         writer.println("$prefix\toverrideLpnhLphThresholds=$overrideLpnhLphThresholds")
151         writer.println("$prefix\tlpnhSlopPercentage=$lpnhSlopPercentage")
152         writer.println("$prefix\tanimateLpnh=$animateLpnh")
153         writer.println("$prefix\tshrinkNavHandleOnPress=$shrinkNavHandleOnPress")
154         writer.println("$prefix\tlpnhTimeoutMs=$lpnhTimeoutMs")
155         writer.println("$prefix\tenableLongPressNavHandle=$enableLongPressNavHandle")
156         writer.println("$prefix\tenableSearchHapticHint=$enableSearchHapticHint")
157         writer.println("$prefix\tenableSearchHapticCommit=$enableSearchHapticCommit")
158         writer.println("$prefix\tlpnhHapticHintStartScalePercent=$lpnhHapticHintStartScalePercent")
159         writer.println("$prefix\tlpnhHapticHintEndScalePercent=$lpnhHapticHintEndScalePercent")
160         writer.println("$prefix\tlpnhHapticHintScaleExponent=$lpnhHapticHintScaleExponent")
161         writer.println("$prefix\tlpnhHapticHintIterations=$lpnhHapticHintIterations")
162         writer.println("$prefix\tenableLpnhDeepPress=$enableLpnhDeepPress")
163         writer.println("$prefix\tlpnhHapticHintDelay=$lpnhHapticHintDelay")
164         writer.println("$prefix\tlpnhExtraTouchWidthDp=$lpnhExtraTouchWidthDp")
165     }
166 
167     companion object {
<lambda>null168         @JvmStatic val configHelper by lazy { DeviceConfigHelper(::DeviceConfigWrapper) }
169 
getnull170         @JvmStatic fun get() = configHelper.config
171 
172         const val DEFAULT_LPNH_TIMEOUT_MS = 450
173     }
174 }
175