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 @UiEvent(doc = "Lockscreen > Tap on switch user icon") 78 LOCKSCREEN_SWITCH_USER_TAP(934); 79 80 private final int mId; 81 LockscreenUiEvent(int id)82 LockscreenUiEvent(int id) { 83 mId = id; 84 } 85 86 @Override getId()87 public int getId() { 88 return mId; 89 } 90 } 91 92 private ArrayMap<Integer, Integer> mLegacyMap; 93 private final MetricsLogger mMetricsLogger; 94 95 @Inject LockscreenGestureLogger(MetricsLogger metricsLogger)96 public LockscreenGestureLogger(MetricsLogger metricsLogger) { 97 mMetricsLogger = metricsLogger; 98 mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length); 99 for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) { 100 mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i); 101 } 102 } 103 write(int gesture, int length, int velocity)104 public void write(int gesture, int length, int velocity) { 105 mMetricsLogger.write(new LogMaker(gesture) 106 .setType(MetricsEvent.TYPE_ACTION) 107 .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length) 108 .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity)); 109 // also write old-style logs for backward-0compatibility 110 EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity); 111 } 112 113 /** 114 * Logs {@link LockscreenUiEvent}. 115 */ log(LockscreenUiEvent lockscreenUiEvent)116 public void log(LockscreenUiEvent lockscreenUiEvent) { 117 new UiEventLoggerImpl().log(lockscreenUiEvent); 118 } 119 120 /** 121 * Record the location of a swipe gesture, expressed as percentages of the whole screen 122 * @param category the action 123 * @param xPercent x-location / width * 100 124 * @param yPercent y-location / height * 100 125 */ writeAtFractionalPosition( int category, int xPercent, int yPercent, int rotation)126 public void writeAtFractionalPosition( 127 int category, int xPercent, int yPercent, int rotation) { 128 mMetricsLogger.write(new LogMaker(category) 129 .setType(MetricsEvent.TYPE_ACTION) 130 .addTaggedData(MetricsEvent.FIELD_GESTURE_X_PERCENT, xPercent) 131 .addTaggedData(MetricsEvent.FIELD_GESTURE_Y_PERCENT, yPercent) 132 .addTaggedData(MetricsEvent.FIELD_DEVICE_ROTATION, rotation)); 133 } 134 safeLookup(int gesture)135 private int safeLookup(int gesture) { 136 Integer value = mLegacyMap.get(gesture); 137 if (value == null) { 138 return MetricsEvent.VIEW_UNKNOWN; 139 } 140 return value; 141 } 142 } 143