Home | History | Annotate | Download | only in phone
      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.annotations.VisibleForTesting;
     23 import com.android.internal.logging.MetricsLogger;
     24 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     25 import com.android.systemui.Dependency;
     26 import com.android.systemui.EventLogConstants;
     27 import com.android.systemui.EventLogTags;
     28 
     29 /**
     30  * Wrapper that emits both new- and old-style gesture logs.
     31  * TODO: delete this once the old logs are no longer needed.
     32  */
     33 public class LockscreenGestureLogger {
     34     private ArrayMap<Integer, Integer> mLegacyMap;
     35     private LogMaker mLogMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN)
     36             .setType(MetricsEvent.TYPE_ACTION);
     37     private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
     38 
     39     public LockscreenGestureLogger() {
     40         mLegacyMap = new ArrayMap<>(EventLogConstants.METRICS_GESTURE_TYPE_MAP.length);
     41         for (int i = 0; i < EventLogConstants.METRICS_GESTURE_TYPE_MAP.length ; i++) {
     42             mLegacyMap.put(EventLogConstants.METRICS_GESTURE_TYPE_MAP[i], i);
     43         }
     44     }
     45 
     46     public void write(int gesture, int length, int velocity) {
     47         mMetricsLogger.write(mLogMaker.setCategory(gesture)
     48                 .setType(MetricsEvent.TYPE_ACTION)
     49                 .addTaggedData(MetricsEvent.FIELD_GESTURE_LENGTH, length)
     50                 .addTaggedData(MetricsEvent.FIELD_GESTURE_VELOCITY, velocity));
     51         // also write old-style logs for backward-0compatibility
     52         EventLogTags.writeSysuiLockscreenGesture(safeLookup(gesture), length, velocity);
     53     }
     54 
     55     private int safeLookup(int gesture) {
     56         Integer value = mLegacyMap.get(gesture);
     57         if (value == null) {
     58             return MetricsEvent.VIEW_UNKNOWN;
     59         }
     60         return value;
     61     }
     62 }
     63