1 /* 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 17 package com.android.systemui.statusbar.phone; 18 19 import android.metrics.LogMaker; 20 import android.util.ArrayMap; 21 22 import com.android.internal.logging.MetricsLogger; 23 import com.android.internal.logging.UiEvent; 24 import com.android.internal.logging.UiEventLogger; 25 import com.android.internal.logging.UiEventLoggerImpl; 26 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 27 import com.android.systemui.EventLogConstants; 28 import com.android.systemui.EventLogTags; 29 import com.android.systemui.dagger.SysUISingleton; 30 31 import javax.inject.Inject; 32 33 /** 34 * Wrapper that emits both new- and old-style gesture logs. 35 * TODO: delete this once the old logs are no longer needed. 36 */ 37 @SysUISingleton 38 public class LockscreenGestureLogger { 39 40 /** 41 * Contains Lockscreen related statsd UiEvent enums. 42 */ 43 public enum LockscreenUiEvent implements UiEventLogger.UiEventEnum { 44 @UiEvent(doc = "Lockscreen > Pull shade open") 45 LOCKSCREEN_PULL_SHADE_OPEN(539), 46 47 @UiEvent(doc = "Lockscreen > Tap on lock, locks phone") 48 LOCKSCREEN_LOCK_TAP(540), 49 50 @UiEvent(doc = "Lockscreen > Swipe down to open quick settings") 51 LOCKSCREEN_QUICK_SETTINGS_OPEN(541), 52 53 @UiEvent(doc = "Swipe down to open quick settings when unlocked") 54 LOCKSCREEN_UNLOCKED_QUICK_SETTINGS_OPEN(542), 55 56 @UiEvent(doc = "Lockscreen > Tap on lock, shows hint") 57 LOCKSCREEN_LOCK_SHOW_HINT(543), 58 59 @UiEvent(doc = "Notification shade > Tap to open quick settings") 60 LOCKSCREEN_NOTIFICATION_SHADE_QUICK_SETTINGS_OPEN(544), 61 62 @UiEvent(doc = "Lockscreen > Dialer") 63 LOCKSCREEN_DIALER(545), 64 65 @UiEvent(doc = "Lockscreen > Camera") 66 LOCKSCREEN_CAMERA(546), 67 68 @UiEvent(doc = "Lockscreen > Unlock gesture") 69 LOCKSCREEN_UNLOCK(547), 70 71 @UiEvent(doc = "Lockscreen > Tap on notification, false touch rejection") 72 LOCKSCREEN_NOTIFICATION_FALSE_TOUCH(548), 73 74 @UiEvent(doc = "Expand the notification panel while unlocked") 75 LOCKSCREEN_UNLOCKED_NOTIFICATION_PANEL_EXPAND(549); 76 77 private final int mId; 78 LockscreenUiEvent(int id)79 LockscreenUiEvent(int id) { 80 mId = id; 81 } 82 83 @Override getId()84 public int getId() { 85 return mId; 86 } 87 } 88 89 private ArrayMap<Integer, Integer> mLegacyMap; 90 private final MetricsLogger mMetricsLogger; 91 92 @Inject LockscreenGestureLogger(MetricsLogger metricsLogger)93 public LockscreenGestureLogger(MetricsLogger metricsLogger) { 94 mMetricsLogger = metricsLogger; 95 mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length); 96 for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) { 97 mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i); 98 } 99 } 100 write(int gesture, int length, int velocity)101 public void write(int gesture, int length, int velocity) { 102 mMetricsLogger.write(new LogMaker(gesture) 103 .setType(MetricsEvent.TYPE_ACTION) 104 .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length) 105 .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity)); 106 // also write old-style logs for backward-0compatibility 107 EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity); 108 } 109 110 /** 111 * Logs {@link LockscreenUiEvent}. 112 */ log(LockscreenUiEvent lockscreenUiEvent)113 public void log(LockscreenUiEvent lockscreenUiEvent) { 114 new UiEventLoggerImpl().log(lockscreenUiEvent); 115 } 116 117 /** 118 * Record the location of a swipe gesture, expressed as percentages of the whole screen 119 * @param category the action 120 * @param xPercent x-location / width * 100 121 * @param yPercent y-location / height * 100 122 */ writeAtFractionalPosition( int category, int xPercent, int yPercent, int rotation)123 public void writeAtFractionalPosition( 124 int category, int xPercent, int yPercent, int rotation) { 125 mMetricsLogger.write(new LogMaker(category) 126 .setType(MetricsEvent.TYPE_ACTION) 127 .addTaggedData(MetricsEvent.FIELD_GESTURE_X_PERCENT, xPercent) 128 .addTaggedData(MetricsEvent.FIELD_GESTURE_Y_PERCENT, yPercent) 129 .addTaggedData(MetricsEvent.FIELD_DEVICE_ROTATION, rotation)); 130 } 131 safeLookup(int gesture)132 private int safeLookup(int gesture) { 133 Integer value = mLegacyMap.get(gesture); 134 if (value == null) { 135 return MetricsEvent.VIEW_UNKNOWN; 136 } 137 return value; 138 } 139 } 140