1 /*
2  * Copyright (C) 2021 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.controls
18 
19 import android.service.controls.DeviceTypes.DeviceType
20 
21 import com.android.internal.logging.UiEvent
22 import com.android.internal.logging.UiEventLogger
23 import com.android.systemui.controls.ui.ControlViewHolder
24 
25 /**
26  * Interface for logging UI events related to controls
27  */
28 interface ControlsMetricsLogger {
29 
30     /**
31      * Assign a new instance id for this controls session, defined as when the controls area is
32      * made visible to when it is closed.
33      */
assignInstanceIdnull34     fun assignInstanceId()
35 
36     fun touch(cvh: ControlViewHolder, isLocked: Boolean) {
37         log(ControlsEvents.CONTROL_TOUCH.id, cvh.deviceType, cvh.uid, isLocked)
38     }
39 
dragnull40     fun drag(cvh: ControlViewHolder, isLocked: Boolean) {
41         log(ControlsEvents.CONTROL_DRAG.id, cvh.deviceType, cvh.uid, isLocked)
42     }
43 
longPressnull44     fun longPress(cvh: ControlViewHolder, isLocked: Boolean) {
45         log(ControlsEvents.CONTROL_LONG_PRESS.id, cvh.deviceType, cvh.uid, isLocked)
46     }
47 
refreshBeginnull48     fun refreshBegin(uid: Int, isLocked: Boolean) {
49         assignInstanceId()
50         log(ControlsEvents.CONTROL_REFRESH_BEGIN.id, 0, uid, isLocked)
51     }
52 
refreshEndnull53     fun refreshEnd(cvh: ControlViewHolder, isLocked: Boolean) {
54         log(ControlsEvents.CONTROL_REFRESH_END.id, cvh.deviceType, cvh.uid, isLocked)
55     }
56 
57     /**
58      * Logs a controls-related event
59      *
60      * @param eventId Main UIEvent to capture
61      * @param deviceType One of {@link android.service.controls.DeviceTypes}
62      * @param packageName Package name of the service that receives the request
63      * @param isLocked Is the device locked at the start of the action?
64      */
lognull65     fun log(
66         eventId: Int,
67         @DeviceType deviceType: Int,
68         uid: Int,
69         isLocked: Boolean
70     )
71 
72     private enum class ControlsEvents(val metricId: Int) : UiEventLogger.UiEventEnum {
73         @UiEvent(doc = "User touched a control")
74         CONTROL_TOUCH(714),
75 
76         @UiEvent(doc = "User dragged a control")
77         CONTROL_DRAG(713),
78 
79         @UiEvent(doc = "User long-pressed a control")
80         CONTROL_LONG_PRESS(715),
81 
82         @UiEvent(doc = "User has opened controls, and a state refresh has begun")
83         CONTROL_REFRESH_BEGIN(716),
84 
85         @UiEvent(doc = "User has opened controls, and a state refresh has ended")
86         CONTROL_REFRESH_END(717);
87 
88         override fun getId() = metricId
89     }
90 }
91