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 
17 package com.android.systemui.shade
18 
19 import android.view.MotionEvent
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
22 import com.android.systemui.log.dagger.ShadeLog
23 import com.android.systemui.shade.ShadeViewController.Companion.FLING_COLLAPSE
24 import com.android.systemui.shade.ShadeViewController.Companion.FLING_EXPAND
25 import com.android.systemui.shade.ShadeViewController.Companion.FLING_HIDE
26 import com.google.errorprone.annotations.CompileTimeConstant
27 import javax.inject.Inject
28 
29 private const val TAG = "systemui.shade"
30 
31 /** Lightweight logging utility for the Shade. */
32 class ShadeLogger @Inject constructor(@ShadeLog private val buffer: LogBuffer) {
vnull33     fun v(@CompileTimeConstant msg: String) {
34         buffer.log(TAG, LogLevel.VERBOSE, msg)
35     }
36 
dnull37     fun d(@CompileTimeConstant msg: String) {
38         buffer.log(TAG, LogLevel.DEBUG, msg)
39     }
40 
onQsInterceptMoveQsTrackingEnablednull41     fun onQsInterceptMoveQsTrackingEnabled(h: Float) {
42         buffer.log(
43             TAG,
44             LogLevel.VERBOSE,
45             { double1 = h.toDouble() },
46             { "onQsIntercept: move action, QS tracking enabled. h = $double1" }
47         )
48     }
49 
logQsTrackingNotStartednull50     fun logQsTrackingNotStarted(
51         initialTouchY: Float,
52         y: Float,
53         h: Float,
54         touchSlop: Float,
55         qsExpanded: Boolean,
56         keyguardShowing: Boolean,
57         qsExpansionEnabled: Boolean,
58         downTime: Long
59     ) {
60         buffer.log(
61             TAG,
62             LogLevel.VERBOSE,
63             {
64                 int1 = initialTouchY.toInt()
65                 int2 = y.toInt()
66                 long1 = h.toLong()
67                 double1 = touchSlop.toDouble()
68                 bool1 = qsExpanded
69                 bool2 = keyguardShowing
70                 bool3 = qsExpansionEnabled
71                 str1 = downTime.toString()
72             },
73             {
74                 "QsTrackingNotStarted: downTime=$str1,initTouchY=$int1,y=$int2,h=$long1," +
75                         "slop=$double1,qsExpanded=$bool1,keyguardShowing=$bool2,qsExpansion=$bool3"
76             }
77         )
78     }
79 
logMotionEventnull80     fun logMotionEvent(event: MotionEvent, message: String) {
81         buffer.log(
82                 TAG,
83                 LogLevel.VERBOSE,
84                 {
85                     str1 = message
86                     long1 = event.eventTime
87                     long2 = event.downTime
88                     int1 = event.action
89                     int2 = event.classification
90                 },
91                 {
92                     "$str1: eventTime=$long1,downTime=$long2,action=$int1,class=$int2"
93                 }
94         )
95     }
96 
97     /** Logs motion event dispatch results from NotificationShadeWindowViewController. */
logShadeWindowDispatchnull98     fun logShadeWindowDispatch(event: MotionEvent, message: String, result: Boolean?) {
99         buffer.log(
100                 TAG,
101                 LogLevel.VERBOSE,
102                 {
103                     str1 = message
104                     long1 = event.eventTime
105                     long2 = event.downTime
106                 },
107                 {
108                     val prefix = when (result) {
109                         true -> "SHADE TOUCH REROUTED"
110                         false -> "SHADE TOUCH BLOCKED"
111                         null -> "SHADE TOUCH DISPATCHED"
112                     }
113                     "$prefix: eventTime=$long1,downTime=$long2, reason=$str1"
114                 }
115         )
116     }
117 
logMotionEventStatusBarStatenull118     fun logMotionEventStatusBarState(event: MotionEvent, statusBarState: Int, message: String) {
119         buffer.log(
120                 TAG,
121                 LogLevel.VERBOSE,
122                 {
123                     str1 = message
124                     long1 = event.eventTime
125                     long2 = event.downTime
126                     int1 = event.action
127                     int2 = statusBarState
128                     double1 = event.y.toDouble()
129                 },
130                 {
131                     "$str1\neventTime=$long1,downTime=$long2,y=$double1,action=$int1," +
132                             "statusBarState=${when (int2) {
133                                 0 -> "SHADE"
134                                 1 -> "KEYGUARD"
135                                 2 -> "SHADE_LOCKED"
136                                 else -> "UNKNOWN:$int2"
137                             }}"
138                 }
139         )
140     }
141 
logExpansionChangednull142     fun logExpansionChanged(
143             message: String,
144             fraction: Float,
145             expanded: Boolean,
146             tracking: Boolean,
147             dragDownPxAmount: Float,
148     ) {
149         buffer.log(
150             TAG,
151             LogLevel.VERBOSE,
152             {
153                 str1 = message
154                 double1 = fraction.toDouble()
155                 bool1 = expanded
156                 bool2 = tracking
157                 long1 = dragDownPxAmount.toLong()
158             },
159             {
160                 "$str1 fraction=$double1,expanded=$bool1," +
161                     "tracking=$bool2," + "dragDownPxAmount=$dragDownPxAmount"
162             }
163         )
164     }
165 
logHasVibratednull166     fun logHasVibrated(hasVibratedOnOpen: Boolean, fraction: Float) {
167         buffer.log(
168             TAG,
169             LogLevel.VERBOSE,
170             {
171                 bool1 = hasVibratedOnOpen
172                 double1 = fraction.toDouble()
173             },
174             { "hasVibratedOnOpen=$bool1, expansionFraction=$double1" }
175         )
176     }
177 
logQsExpandImmediateChangednull178     fun logQsExpandImmediateChanged(newValue: Boolean) {
179         buffer.log(
180             TAG,
181             LogLevel.VERBOSE,
182             {
183                 bool1 = newValue
184             },
185             { "qsExpandImmediate=$bool1" }
186         )
187     }
188 
logQsExpansionChangednull189     fun logQsExpansionChanged(
190             message: String,
191             qsExpanded: Boolean,
192             qsMinExpansionHeight: Int,
193             qsMaxExpansionHeight: Int,
194             stackScrollerOverscrolling: Boolean,
195             qsAnimatorExpand: Boolean,
196             animatingQs: Boolean
197     ) {
198         buffer.log(
199             TAG,
200             LogLevel.VERBOSE,
201             {
202                 str1 = message
203                 bool1 = qsExpanded
204                 int1 = qsMinExpansionHeight
205                 int2 = qsMaxExpansionHeight
206                 bool2 = stackScrollerOverscrolling
207                 bool3 = qsAnimatorExpand
208                 // 0 = false, 1 = true
209                 long1 = animatingQs.compareTo(false).toLong()
210             },
211             {
212                 "$str1 qsExpanded=$bool1,qsMinExpansionHeight=$int1,qsMaxExpansionHeight=$int2," +
213                     "stackScrollerOverscrolling=$bool2,qsAnimatorExpand=$bool3," +
214                     "animatingQs=$long1"
215             }
216         )
217     }
218 
logSingleTapUpnull219     fun logSingleTapUp(isDozing: Boolean, singleTapEnabled: Boolean, isNotDocked: Boolean) {
220         buffer.log(
221             TAG,
222             LogLevel.DEBUG,
223             {
224                 bool1 = isDozing
225                 bool2 = singleTapEnabled
226                 bool3 = isNotDocked
227             },
228             {
229                 "PulsingGestureListener#onSingleTapUp all of this must true for single " +
230                "tap to be detected: isDozing: $bool1, singleTapEnabled: $bool2, isNotDocked: $bool3"
231         })
232     }
233 
logSingleTapUpFalsingStatenull234     fun logSingleTapUpFalsingState(proximityIsNotNear: Boolean, isNotFalseTap: Boolean) {
235         buffer.log(
236             TAG,
237             LogLevel.DEBUG,
238             {
239                 bool1 = proximityIsNotNear
240                 bool2 = isNotFalseTap
241             },
242             {
243                 "PulsingGestureListener#onSingleTapUp all of this must true for single " +
244                     "tap to be detected: proximityIsNotNear: $bool1, isNotFalseTap: $bool2"
245             }
246         )
247     }
248 
logNotInterceptingTouchInstantExpandingnull249     fun logNotInterceptingTouchInstantExpanding(
250             instantExpanding: Boolean,
251             notificationsDragEnabled: Boolean,
252             touchDisabled: Boolean
253     ) {
254         buffer.log(
255             TAG,
256             LogLevel.VERBOSE,
257             {
258                 bool1 = instantExpanding
259                 bool2 = notificationsDragEnabled
260                 bool3 = touchDisabled
261             },
262             {
263                 "NPVC not intercepting touch, instantExpanding: $bool1, " +
264                     "!notificationsDragEnabled: $bool2, touchDisabled: $bool3"
265             }
266         )
267     }
268 
logLastFlingWasExpandingnull269     fun logLastFlingWasExpanding(expand: Boolean) {
270         buffer.log(
271             TAG,
272             LogLevel.VERBOSE,
273             { bool1 = expand },
274             { "NPVC mLastFlingWasExpanding set to: $bool1" }
275         )
276     }
277 
logFlingExpandsnull278     fun logFlingExpands(
279             vel: Float,
280             vectorVel: Float,
281             interactionType: Int,
282             minVelocityPxPerSecond: Float,
283             expansionOverHalf: Boolean,
284             allowExpandForSmallExpansion: Boolean
285     ) {
286         buffer.log(
287             TAG,
288             LogLevel.VERBOSE,
289             {
290                 int1 = interactionType
291                 long1 = vel.toLong()
292                 long2 = vectorVel.toLong()
293                 double1 = minVelocityPxPerSecond.toDouble()
294                 bool1 = expansionOverHalf
295                 bool2 = allowExpandForSmallExpansion
296             },
297             { "NPVC flingExpands called with vel: $long1, vectorVel: $long2, " +
298                     "interactionType: $int1, minVelocityPxPerSecond: $double1 " +
299                     "expansionOverHalf: $bool1, allowExpandForSmallExpansion: $bool2" }
300         )
301     }
302 
logEndMotionEventnull303     fun logEndMotionEvent(
304         msg: String,
305         forceCancel: Boolean,
306         expand: Boolean,
307     ) {
308         buffer.log(
309             TAG,
310             LogLevel.VERBOSE,
311             {
312                 str1 = msg
313                 bool1 = forceCancel
314                 bool2 = expand
315             },
316             { "$str1; force=$bool1; expand=$bool2" }
317         )
318     }
319 
logPanelClosedOnDownnull320     fun logPanelClosedOnDown(
321         msg: String,
322         panelClosedOnDown: Boolean,
323         expandFraction: Float,
324     ) {
325         buffer.log(
326             TAG,
327             LogLevel.VERBOSE,
328             {
329                 str1 = msg
330                 bool1 = panelClosedOnDown
331                 double1 = expandFraction.toDouble()
332             },
333             { "$str1; mPanelClosedOnDown=$bool1; mExpandedFraction=$double1" }
334         )
335     }
336 
logPanelStateChangednull337     fun logPanelStateChanged(@PanelState panelState: Int) {
338         buffer.log(
339             TAG,
340             LogLevel.VERBOSE,
341             {
342                 str1 = panelState.panelStateToString()
343             },
344             { "New panel State: $str1" }
345         )
346     }
347 
flingQsnull348     fun flingQs(flingType: Int, isClick: Boolean) {
349         buffer.log(
350             TAG,
351             LogLevel.VERBOSE,
352             {
353                 str1 = flingTypeToString(flingType)
354                 bool1 = isClick
355             },
356             { "QS fling with type $str1, originated from click: $isClick" }
357         )
358     }
359 
flingTypeToStringnull360     private fun flingTypeToString(flingType: Int) = when (flingType) {
361         FLING_EXPAND -> "FLING_EXPAND"
362         FLING_COLLAPSE -> "FLING_COLLAPSE"
363         FLING_HIDE -> "FLING_HIDE"
364         else -> "UNKNOWN"
365     }
366 
logSplitShadeChangednull367     fun logSplitShadeChanged(splitShadeEnabled: Boolean) {
368         buffer.log(
369             TAG,
370             LogLevel.VERBOSE,
371             { bool1 = splitShadeEnabled },
372             { "Split shade state changed: split shade ${if (bool1) "enabled" else "disabled"}" }
373         )
374     }
375 
logUpdateNotificationPanelTouchStatenull376     fun logUpdateNotificationPanelTouchState(
377         disabled: Boolean,
378         isGoingToSleep: Boolean,
379         shouldControlScreenOff: Boolean,
380         deviceInteractive: Boolean,
381         isPulsing: Boolean,
382     ) {
383         buffer.log(
384             TAG,
385             LogLevel.VERBOSE,
386             {
387                 bool1 = disabled
388                 bool2 = isGoingToSleep
389                 bool3 = shouldControlScreenOff
390                 bool4 = deviceInteractive
391                 str1 = isPulsing.toString()
392             },
393             {
394                 "CentralSurfaces updateNotificationPanelTouchState set disabled to: $bool1\n" +
395                         "isGoingToSleep: $bool2, !shouldControlScreenOff: $bool3," +
396                         "!mDeviceInteractive: $bool4, !isPulsing: $str1"
397             }
398         )
399     }
400 }
401