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.statusbar.phone
18 
19 import android.util.DisplayMetrics
20 import android.view.View
21 import com.android.internal.logging.nano.MetricsProto.MetricsEvent
22 import com.android.systemui.log.LogBuffer
23 import com.android.systemui.log.LogLevel
24 import com.android.systemui.log.dagger.LSShadeTransitionLog
25 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
26 import com.android.systemui.statusbar.notification.row.ExpandableView
27 import javax.inject.Inject
28 
29 private const val TAG = "LockscreenShadeTransitionController"
30 
31 class LSShadeTransitionLogger @Inject constructor(
32     @LSShadeTransitionLog private val buffer: LogBuffer,
33     private val lockscreenGestureLogger: LockscreenGestureLogger,
34     private val displayMetrics: DisplayMetrics
35 ) {
36     fun logUnSuccessfulDragDown(startingChild: View?) {
37         val entry = (startingChild as? ExpandableNotificationRow)?.entry
38         buffer.log(TAG, LogLevel.INFO, {
39             str1 = entry?.key ?: "no entry"
40         }, {
41             "Tried to drag down but can't drag down on $str1"
42         })
43     }
44 
45     fun logDragDownAborted() {
46         buffer.log(TAG, LogLevel.INFO, {}, {
47             "The drag down was reset"
48         })
49     }
50 
51     fun logDragDownStarted(startingChild: ExpandableView?) {
52         val entry = (startingChild as? ExpandableNotificationRow)?.entry
53         buffer.log(TAG, LogLevel.INFO, {
54             str1 = entry?.key ?: "no entry"
55         }, {
56             "The drag down has started on $str1"
57         })
58     }
59 
60     fun logDraggedDownLockDownShade(startingChild: View?) {
61         val entry = (startingChild as? ExpandableNotificationRow)?.entry
62         buffer.log(TAG, LogLevel.INFO, {
63             str1 = entry?.key ?: "no entry"
64         }, {
65             "Dragged down in locked down shade on $str1"
66         })
67     }
68 
69     fun logDraggedDown(startingChild: View?, dragLengthY: Int) {
70         val entry = (startingChild as? ExpandableNotificationRow)?.entry
71         buffer.log(TAG, LogLevel.INFO, {
72             str1 = entry?.key ?: "no entry"
73         }, {
74             "Drag down succeeded on $str1"
75         })
76         // Do logging to event log not just our own buffer
77         lockscreenGestureLogger.write(
78             MetricsEvent.ACTION_LS_SHADE,
79             (dragLengthY / displayMetrics.density).toInt(),
80             0 /* velocityDp */)
81         lockscreenGestureLogger.log(
82             LockscreenGestureLogger.LockscreenUiEvent.LOCKSCREEN_PULL_SHADE_OPEN)
83     }
84 
85     fun logDefaultGoToFullShadeAnimation(delay: Long) {
86         buffer.log(TAG, LogLevel.DEBUG, {
87             long1 = delay
88         }, {
89             "Default animation started to full shade with delay $long1"
90         })
91     }
92 
93     fun logTryGoToLockedShade(keyguard: Boolean) {
94         buffer.log(TAG, LogLevel.INFO, {
95             bool1 = keyguard
96         }, {
97             "Trying to go to locked shade " + if (bool1) "from keyguard" else "not from keyguard"
98         })
99     }
100 
101     fun logShadeDisabledOnGoToLockedShade() {
102         buffer.log(TAG, LogLevel.WARNING, {}, {
103             "The shade was disabled when trying to go to the locked shade"
104         })
105     }
106 
107     fun logShowBouncerOnGoToLockedShade() {
108         buffer.log(TAG, LogLevel.INFO, {}, {
109             "Showing bouncer when trying to go to the locked shade"
110         })
111     }
112 
113     fun logGoingToLockedShade(customAnimationHandler: Boolean) {
114         buffer.log(TAG, LogLevel.INFO, {
115             bool1 = customAnimationHandler
116         }, {
117             "Going to locked shade " + if (customAnimationHandler) "with" else "without" +
118                 " a custom handler"
119         })
120     }
121 
122     fun logOnHideKeyguard() {
123         buffer.log(TAG, LogLevel.INFO, {}, {
124             "Notified that the keyguard is being hidden"
125         })
126     }
127 
128     fun logPulseExpansionStarted() {
129         buffer.log(TAG, LogLevel.INFO, {}, {
130             "Pulse Expansion has started"
131         })
132     }
133 
134     fun logPulseExpansionFinished(cancelled: Boolean) {
135         if (cancelled) {
136             buffer.log(TAG, LogLevel.INFO, {}, {
137                 "Pulse Expansion is requested to cancel"
138             })
139         } else {
140             buffer.log(TAG, LogLevel.INFO, {}, {
141                 "Pulse Expansion is requested to finish"
142             })
143         }
144     }
145 
146     fun logDragDownAnimation(target: Float) {
147         buffer.log(TAG, LogLevel.DEBUG, {
148             double1 = target.toDouble()
149         }, {
150             "Drag down amount animating to " + double1
151         })
152     }
153 
154     fun logAnimationCancelled(isPulse: Boolean) {
155         if (isPulse) {
156             buffer.log(TAG, LogLevel.DEBUG, {}, {
157                 "Pulse animation cancelled"
158             })
159         } else {
160             buffer.log(TAG, LogLevel.DEBUG, {}, {
161                 "drag down animation cancelled"
162             })
163         }
164     }
165 
166     fun logDragDownAmountResetWhenFullyCollapsed() {
167         buffer.log(TAG, LogLevel.WARNING, {}, {
168             "Drag down amount stuck and reset after shade was fully collapsed"
169         })
170     }
171 
172     fun logPulseHeightNotResetWhenFullyCollapsed() {
173         buffer.log(TAG, LogLevel.WARNING, {}, {
174             "Pulse height stuck and reset after shade was fully collapsed"
175         })
176     }
177 
178     fun logGoingToLockedShadeAborted() {
179         buffer.log(TAG, LogLevel.INFO, {}, {
180             "Going to the Locked Shade has been aborted"
181         })
182     }
183 }
184