127a52fa86bd279407575192fc9842b6a54624cfbChris Wren/* 227a52fa86bd279407575192fc9842b6a54624cfbChris Wren * Copyright (C) 2017 The Android Open Source Project 327a52fa86bd279407575192fc9842b6a54624cfbChris Wren * 427a52fa86bd279407575192fc9842b6a54624cfbChris Wren * Licensed under the Apache License, Version 2.0 (the "License"); 527a52fa86bd279407575192fc9842b6a54624cfbChris Wren * you may not use this file except in compliance with the License. 627a52fa86bd279407575192fc9842b6a54624cfbChris Wren * You may obtain a copy of the License at 727a52fa86bd279407575192fc9842b6a54624cfbChris Wren * 827a52fa86bd279407575192fc9842b6a54624cfbChris Wren * http://www.apache.org/licenses/LICENSE-2.0 927a52fa86bd279407575192fc9842b6a54624cfbChris Wren * 1027a52fa86bd279407575192fc9842b6a54624cfbChris Wren * Unless required by applicable law or agreed to in writing, software 1127a52fa86bd279407575192fc9842b6a54624cfbChris Wren * distributed under the License is distributed on an "AS IS" BASIS, 1227a52fa86bd279407575192fc9842b6a54624cfbChris Wren * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1327a52fa86bd279407575192fc9842b6a54624cfbChris Wren * See the License for the specific language governing permissions and 1427a52fa86bd279407575192fc9842b6a54624cfbChris Wren * limitations under the License 1527a52fa86bd279407575192fc9842b6a54624cfbChris Wren */ 1627a52fa86bd279407575192fc9842b6a54624cfbChris Wren 1727a52fa86bd279407575192fc9842b6a54624cfbChris Wrenpackage com.android.systemui.statusbar.phone; 1827a52fa86bd279407575192fc9842b6a54624cfbChris Wren 1927a52fa86bd279407575192fc9842b6a54624cfbChris Wrenimport android.metrics.LogMaker; 2027a52fa86bd279407575192fc9842b6a54624cfbChris Wrenimport android.util.ArrayMap; 2127a52fa86bd279407575192fc9842b6a54624cfbChris Wren 22fd57db6ead1b990ed000c5cd15d8fd1d1668f13eChris Wrenimport com.android.internal.annotations.VisibleForTesting; 2327a52fa86bd279407575192fc9842b6a54624cfbChris Wrenimport com.android.internal.logging.MetricsLogger; 2427a52fa86bd279407575192fc9842b6a54624cfbChris Wrenimport com.android.internal.logging.nano.MetricsProto.MetricsEvent; 258c09ac7435c62a8ba2e34d57a7ac3be2ddf23adcJason Monkimport com.android.systemui.Dependency; 2627a52fa86bd279407575192fc9842b6a54624cfbChris Wrenimport com.android.systemui.EventLogConstants; 2727a52fa86bd279407575192fc9842b6a54624cfbChris Wrenimport com.android.systemui.EventLogTags; 2827a52fa86bd279407575192fc9842b6a54624cfbChris Wren 2927a52fa86bd279407575192fc9842b6a54624cfbChris Wren/** 3027a52fa86bd279407575192fc9842b6a54624cfbChris Wren * Wrapper that emits both new- and old-style gesture logs. 3127a52fa86bd279407575192fc9842b6a54624cfbChris Wren * TODO: delete this once the old logs are no longer needed. 3227a52fa86bd279407575192fc9842b6a54624cfbChris Wren */ 3327a52fa86bd279407575192fc9842b6a54624cfbChris Wrenpublic class LockscreenGestureLogger { 3427a52fa86bd279407575192fc9842b6a54624cfbChris Wren private ArrayMap<Integer, Integer> mLegacyMap; 3527a52fa86bd279407575192fc9842b6a54624cfbChris Wren private LogMaker mLogMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN) 3627a52fa86bd279407575192fc9842b6a54624cfbChris Wren .setType(MetricsEvent.TYPE_ACTION); 378c09ac7435c62a8ba2e34d57a7ac3be2ddf23adcJason Monk private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); 3827a52fa86bd279407575192fc9842b6a54624cfbChris Wren 3927a52fa86bd279407575192fc9842b6a54624cfbChris Wren public LockscreenGestureLogger() { 4027a52fa86bd279407575192fc9842b6a54624cfbChris Wren mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length); 4127a52fa86bd279407575192fc9842b6a54624cfbChris Wren for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) { 4227a52fa86bd279407575192fc9842b6a54624cfbChris Wren mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i); 4327a52fa86bd279407575192fc9842b6a54624cfbChris Wren } 4427a52fa86bd279407575192fc9842b6a54624cfbChris Wren } 4527a52fa86bd279407575192fc9842b6a54624cfbChris Wren 4627a52fa86bd279407575192fc9842b6a54624cfbChris Wren public void write(int gesture, int length, int velocity) { 47fd57db6ead1b990ed000c5cd15d8fd1d1668f13eChris Wren mMetricsLogger.write(mLogMaker.setCategory(gesture) 4827a52fa86bd279407575192fc9842b6a54624cfbChris Wren .setType(MetricsEvent.TYPE_ACTION) 4927a52fa86bd279407575192fc9842b6a54624cfbChris Wren .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length) 5027a52fa86bd279407575192fc9842b6a54624cfbChris Wren .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity)); 5127a52fa86bd279407575192fc9842b6a54624cfbChris Wren // also write old-style logs for backward-0compatibility 5227a52fa86bd279407575192fc9842b6a54624cfbChris Wren EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity); 5327a52fa86bd279407575192fc9842b6a54624cfbChris Wren } 5427a52fa86bd279407575192fc9842b6a54624cfbChris Wren 5527a52fa86bd279407575192fc9842b6a54624cfbChris Wren private int safeLookup(int gesture) { 5627a52fa86bd279407575192fc9842b6a54624cfbChris Wren Integer value = mLegacyMap.get(gesture); 5727a52fa86bd279407575192fc9842b6a54624cfbChris Wren if (value == null) { 5827a52fa86bd279407575192fc9842b6a54624cfbChris Wren return MetricsEvent.VIEW_UNKNOWN; 5927a52fa86bd279407575192fc9842b6a54624cfbChris Wren } 6027a52fa86bd279407575192fc9842b6a54624cfbChris Wren return value; 6127a52fa86bd279407575192fc9842b6a54624cfbChris Wren } 6227a52fa86bd279407575192fc9842b6a54624cfbChris Wren} 63