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.nano.MetricsProto.MetricsEvent; 24 import com.android.systemui.Dependency; 25 import com.android.systemui.EventLogConstants; 26 import com.android.systemui.EventLogTags; 27 28 import javax.inject.Inject; 29 import javax.inject.Singleton; 30 31 /** 32 * Wrapper that emits both new- and old-style gesture logs. 33 * TODO: delete this once the old logs are no longer needed. 34 */ 35 @Singleton 36 public class LockscreenGestureLogger { 37 private ArrayMap<Integer, Integer> mLegacyMap; 38 private LogMaker mLogMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN) 39 .setType(MetricsEvent.TYPE_ACTION); 40 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); 41 42 @Inject LockscreenGestureLogger()43 public LockscreenGestureLogger() { 44 mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length); 45 for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) { 46 mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i); 47 } 48 } 49 write(int gesture, int length, int velocity)50 public void write(int gesture, int length, int velocity) { 51 mMetricsLogger.write(mLogMaker.setCategory(gesture) 52 .setType(MetricsEvent.TYPE_ACTION) 53 .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length) 54 .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity)); 55 // also write old-style logs for backward-0compatibility 56 EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity); 57 } 58 59 /** 60 * Record the location of a swipe gesture, expressed as percentages of the whole screen 61 * @param category the action 62 * @param xPercent x-location / width * 100 63 * @param yPercent y-location / height * 100 64 */ writeAtFractionalPosition( int category, int xPercent, int yPercent, int rotation)65 public void writeAtFractionalPosition( 66 int category, int xPercent, int yPercent, int rotation) { 67 mMetricsLogger.write(mLogMaker.setCategory(category) 68 .setType(MetricsEvent.TYPE_ACTION) 69 .addTaggedData(MetricsEvent.FIELD_GESTURE_X_PERCENT, xPercent) 70 .addTaggedData(MetricsEvent.FIELD_GESTURE_Y_PERCENT, yPercent) 71 .addTaggedData(MetricsEvent.FIELD_DEVICE_ROTATION, rotation)); 72 } 73 safeLookup(int gesture)74 private int safeLookup(int gesture) { 75 Integer value = mLegacyMap.get(gesture); 76 if (value == null) { 77 return MetricsEvent.VIEW_UNKNOWN; 78 } 79 return value; 80 } 81 } 82