blob: 83b96bfc4faf8a941a0baddb082be2f61a8f5145 [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;
24import com.android.systemui.EventLogConstants;
25import com.android.systemui.EventLogTags;
26
27/**
28 * Wrapper that emits both new- and old-style gesture logs.
29 * TODO: delete this once the old logs are no longer needed.
30 */
31public class LockscreenGestureLogger {
32 private ArrayMap<Integer, Integer> mLegacyMap;
33 private LogMaker mLogMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN)
34 .setType(MetricsEvent.TYPE_ACTION);
35
36 public LockscreenGestureLogger() {
37 mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length);
38 for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) {
39 mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i);
40 }
41 }
42
43 public void write(int gesture, int length, int velocity) {
44 MetricsLogger.action(mLogMaker.setCategory(gesture)
45 .setType(MetricsEvent.TYPE_ACTION)
46 .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length)
47 .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity));
48 // also write old-style logs for backward-0compatibility
49 EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity);
50 }
51
52 private int safeLookup(int gesture) {
53 Integer value = mLegacyMap.get(gesture);
54 if (value == null) {
55 return MetricsEvent.VIEW_UNKNOWN;
56 }
57 return value;
58 }
59}