1/* 2 * Copyright (C) 2015 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 */ 16package com.android.internal.logging; 17 18 19import android.content.Context; 20import android.os.Build; 21import android.view.View; 22 23/** 24 * Log all the things. 25 * 26 * @hide 27 */ 28public class MetricsLogger implements MetricsConstants { 29 // Temporary constants go here, to await migration to MetricsConstants. 30 // next value is 239; 31 public static final int ACTION_ASSIST_LONG_PRESS = 239; 32 public static final int FINGERPRINT_ENROLLING = 240; 33 public static final int FINGERPRINT_FIND_SENSOR = 241; 34 public static final int FINGERPRINT_ENROLL_FINISH = 242; 35 public static final int FINGERPRINT_ENROLL_INTRO = 243; 36 public static final int FINGERPRINT_ENROLL_ONBOARD = 244; 37 public static final int FINGERPRINT_ENROLL_SIDECAR = 245; 38 public static final int FINGERPRINT_ENROLLING_SETUP = 246; 39 public static final int FINGERPRINT_FIND_SENSOR_SETUP = 247; 40 public static final int FINGERPRINT_ENROLL_FINISH_SETUP = 248; 41 public static final int FINGERPRINT_ENROLL_INTRO_SETUP = 249; 42 public static final int FINGERPRINT_ENROLL_ONBOARD_SETUP = 250; 43 public static final int ACTION_FINGERPRINT_ENROLL = 251; 44 public static final int ACTION_FINGERPRINT_AUTH = 252; 45 public static final int ACTION_FINGERPRINT_DELETE = 253; 46 public static final int ACTION_FINGERPRINT_RENAME = 254; 47 public static final int ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE = 255; 48 public static final int ACTION_WIGGLE_CAMERA_GESTURE = 256; 49 50 public static void visible(Context context, int category) throws IllegalArgumentException { 51 if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { 52 throw new IllegalArgumentException("Must define metric category"); 53 } 54 EventLogTags.writeSysuiViewVisibility(category, 100); 55 } 56 57 public static void hidden(Context context, int category) throws IllegalArgumentException { 58 if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { 59 throw new IllegalArgumentException("Must define metric category"); 60 } 61 EventLogTags.writeSysuiViewVisibility(category, 0); 62 } 63 64 public static void visibility(Context context, int category, boolean visibile) 65 throws IllegalArgumentException { 66 if (visibile) { 67 visible(context, category); 68 } else { 69 hidden(context, category); 70 } 71 } 72 73 public static void visibility(Context context, int category, int vis) 74 throws IllegalArgumentException { 75 visibility(context, category, vis == View.VISIBLE); 76 } 77 78 public static void action(Context context, int category) { 79 action(context, category, ""); 80 } 81 82 public static void action(Context context, int category, int value) { 83 action(context, category, Integer.toString(value)); 84 } 85 86 public static void action(Context context, int category, boolean value) { 87 action(context, category, Boolean.toString(value)); 88 } 89 90 public static void action(Context context, int category, String pkg) { 91 if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { 92 throw new IllegalArgumentException("Must define metric category"); 93 } 94 EventLogTags.writeSysuiAction(category, pkg); 95 } 96 97 /** Add an integer value to the monotonically increasing counter with the given name. */ 98 public static void count(Context context, String name, int value) { 99 EventLogTags.writeSysuiCount(name, value); 100 } 101 102 /** Increment the bucket with the integer label on the histogram with the given name. */ 103 public static void histogram(Context context, String name, int bucket) { 104 EventLogTags.writeSysuiHistogram(name, bucket); 105 } 106} 107