blob: 8c3420a522ecea8d4fd841f28cc1f8ea112ff2a9 [file] [log] [blame]
Chris Wren27a52fa2017-02-01 14:21:43 -05001/*
2 * Copyright (C) 2017 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
17package com.android.systemui.statusbar.phone;
18
19import android.metrics.LogMaker;
20import android.util.ArrayMap;
21
22import com.android.internal.logging.MetricsLogger;
23import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monk8c09ac72017-03-16 11:53:40 -040024import com.android.systemui.Dependency;
Chris Wren27a52fa2017-02-01 14:21:43 -050025import com.android.systemui.EventLogConstants;
26import com.android.systemui.EventLogTags;
27
Jason Monk196d6392018-12-20 13:25:34 -050028import javax.inject.Inject;
29import javax.inject.Singleton;
30
Chris Wren27a52fa2017-02-01 14:21:43 -050031/**
32 * Wrapper that emits both new- and old-style gesture logs.
33 * TODO: delete this once the old logs are no longer needed.
34 */
Jason Monk196d6392018-12-20 13:25:34 -050035@Singleton
Chris Wren27a52fa2017-02-01 14:21:43 -050036public class LockscreenGestureLogger {
37 private ArrayMap<Integer, Integer> mLegacyMap;
Jason Monk8c09ac72017-03-16 11:53:40 -040038 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Chris Wren27a52fa2017-02-01 14:21:43 -050039
Jason Monk196d6392018-12-20 13:25:34 -050040 @Inject
Chris Wren27a52fa2017-02-01 14:21:43 -050041 public LockscreenGestureLogger() {
42 mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length);
43 for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) {
44 mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i);
45 }
46 }
47
48 public void write(int gesture, int length, int velocity) {
Will Brockman469963c2019-12-18 10:46:26 -050049 mMetricsLogger.write(new LogMaker(gesture)
Chris Wren27a52fa2017-02-01 14:21:43 -050050 .setType(MetricsEvent.TYPE_ACTION)
51 .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length)
52 .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity));
53 // also write old-style logs for backward-0compatibility
54 EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity);
55 }
56
Evan Laird404a85c2018-02-28 15:31:29 -050057 /**
58 * Record the location of a swipe gesture, expressed as percentages of the whole screen
59 * @param category the action
60 * @param xPercent x-location / width * 100
61 * @param yPercent y-location / height * 100
62 */
63 public void writeAtFractionalPosition(
64 int category, int xPercent, int yPercent, int rotation) {
Will Brockman469963c2019-12-18 10:46:26 -050065 mMetricsLogger.write(new LogMaker(category)
Evan Laird404a85c2018-02-28 15:31:29 -050066 .setType(MetricsEvent.TYPE_ACTION)
67 .addTaggedData(MetricsEvent.FIELD_GESTURE_X_PERCENT, xPercent)
68 .addTaggedData(MetricsEvent.FIELD_GESTURE_Y_PERCENT, yPercent)
69 .addTaggedData(MetricsEvent.FIELD_DEVICE_ROTATION, rotation));
70 }
71
Chris Wren27a52fa2017-02-01 14:21:43 -050072 private int safeLookup(int gesture) {
73 Integer value = mLegacyMap.get(gesture);
74 if (value == null) {
75 return MetricsEvent.VIEW_UNKNOWN;
76 }
77 return value;
78 }
Chris Wren27a52fa2017-02-01 14:21:43 -050079}