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.Dependency; 28 import com.android.systemui.EventLogConstants; 29 import com.android.systemui.EventLogTags; 30 31 import javax.inject.Inject; 32 import javax.inject.Singleton; 33 34 /** 35 * Wrapper that emits both new- and old-style gesture logs. 36 * TODO: delete this once the old logs are no longer needed. 37 */ 38 @Singleton 39 public class LockscreenGestureLogger { 40 41 /** 42 * Contains Lockscreen related statsd UiEvent enums. 43 */ 44 public enum LockscreenUiEvent implements UiEventLogger.UiEventEnum { 45 @UiEvent(doc = "Lockscreen > Pull shade open") 46 LOCKSCREEN_PULL_SHADE_OPEN(539), 47 48 @UiEvent(doc = "Lockscreen > Tap on lock, locks phone") 49 LOCKSCREEN_LOCK_TAP(540), 50 51 @UiEvent(doc = "Lockscreen > Swipe down to open quick settings") 52 LOCKSCREEN_QUICK_SETTINGS_OPEN(541), 53 54 @UiEvent(doc = "Swipe down to open quick settings when unlocked") 55 LOCKSCREEN_UNLOCKED_QUICK_SETTINGS_OPEN(542), 56 57 @UiEvent(doc = "Lockscreen > Tap on lock, shows hint") 58 LOCKSCREEN_LOCK_SHOW_HINT(543), 59 60 @UiEvent(doc = "Notification shade > Tap to open quick settings") 61 LOCKSCREEN_NOTIFICATION_SHADE_QUICK_SETTINGS_OPEN(544), 62 63 @UiEvent(doc = "Lockscreen > Dialer") 64 LOCKSCREEN_DIALER(545), 65 66 @UiEvent(doc = "Lockscreen > Camera") 67 LOCKSCREEN_CAMERA(546), 68 69 @UiEvent(doc = "Lockscreen > Unlock gesture") 70 LOCKSCREEN_UNLOCK(547), 71 72 @UiEvent(doc = "Lockscreen > Tap on notification, false touch rejection") 73 LOCKSCREEN_NOTIFICATION_FALSE_TOUCH(548), 74 75 @UiEvent(doc = "Expand the notification panel while unlocked") 76 LOCKSCREEN_UNLOCKED_NOTIFICATION_PANEL_EXPAND(549); 77 78 private final int mId; 79 LockscreenUiEvent(int id)80 LockscreenUiEvent(int id) { 81 mId = id; 82 } 83 84 @Override getId()85 public int getId() { 86 return mId; 87 } 88 } 89 90 private ArrayMap<Integer, Integer> mLegacyMap; 91 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); 92 93 @Inject LockscreenGestureLogger()94 public LockscreenGestureLogger() { 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