Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 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; |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 24 | import com.android.systemui.Dependency; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 25 | import com.android.systemui.EventLogConstants; |
| 26 | import com.android.systemui.EventLogTags; |
| 27 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 28 | import javax.inject.Inject; |
| 29 | import javax.inject.Singleton; |
| 30 | |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 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 | */ |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 35 | @Singleton |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 36 | public class LockscreenGestureLogger { |
| 37 | private ArrayMap<Integer, Integer> mLegacyMap; |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 38 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 39 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 40 | @Inject |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 41 | public LockscreenGestureLogger() { |
| 42 | mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length); |
| 43 | for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) { |
| 44 | mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public void write(int gesture, int length, int velocity) { |
Will Brockman | 469963c | 2019-12-18 10:46:26 -0500 | [diff] [blame] | 49 | mMetricsLogger.write(new LogMaker(gesture) |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 50 | .setType(MetricsEvent.TYPE_ACTION) |
| 51 | .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length) |
| 52 | .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity)); |
| 53 | // also write old-style logs for backward-0compatibility |
| 54 | EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity); |
| 55 | } |
| 56 | |
Evan Laird | 404a85c | 2018-02-28 15:31:29 -0500 | [diff] [blame] | 57 | /** |
| 58 | * Record the location of a swipe gesture, expressed as percentages of the whole screen |
| 59 | * @param category the action |
| 60 | * @param xPercent x-location / width * 100 |
| 61 | * @param yPercent y-location / height * 100 |
| 62 | */ |
| 63 | public void writeAtFractionalPosition( |
| 64 | int category, int xPercent, int yPercent, int rotation) { |
Will Brockman | 469963c | 2019-12-18 10:46:26 -0500 | [diff] [blame] | 65 | mMetricsLogger.write(new LogMaker(category) |
Evan Laird | 404a85c | 2018-02-28 15:31:29 -0500 | [diff] [blame] | 66 | .setType(MetricsEvent.TYPE_ACTION) |
| 67 | .addTaggedData(MetricsEvent.FIELD_GESTURE_X_PERCENT, xPercent) |
| 68 | .addTaggedData(MetricsEvent.FIELD_GESTURE_Y_PERCENT, yPercent) |
| 69 | .addTaggedData(MetricsEvent.FIELD_DEVICE_ROTATION, rotation)); |
| 70 | } |
| 71 | |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 72 | private int safeLookup(int gesture) { |
| 73 | Integer value = mLegacyMap.get(gesture); |
| 74 | if (value == null) { |
| 75 | return MetricsEvent.VIEW_UNKNOWN; |
| 76 | } |
| 77 | return value; |
| 78 | } |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 79 | } |