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 */ 16 package com.android.internal.logging; 17 18 19 import android.content.Context; 20 import android.os.Build; 21 import android.view.View; 22 23 /** 24 * Log all the things. 25 * 26 * @hide 27 */ 28 public 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 visible(Context context, int category)33 public static void visible(Context context, int category) throws IllegalArgumentException { 34 if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { 35 throw new IllegalArgumentException("Must define metric category"); 36 } 37 EventLogTags.writeSysuiViewVisibility(category, 100); 38 } 39 hidden(Context context, int category)40 public static void hidden(Context context, int category) throws IllegalArgumentException { 41 if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { 42 throw new IllegalArgumentException("Must define metric category"); 43 } 44 EventLogTags.writeSysuiViewVisibility(category, 0); 45 } 46 visibility(Context context, int category, boolean visibile)47 public static void visibility(Context context, int category, boolean visibile) 48 throws IllegalArgumentException { 49 if (visibile) { 50 visible(context, category); 51 } else { 52 hidden(context, category); 53 } 54 } 55 visibility(Context context, int category, int vis)56 public static void visibility(Context context, int category, int vis) 57 throws IllegalArgumentException { 58 visibility(context, category, vis == View.VISIBLE); 59 } 60 action(Context context, int category)61 public static void action(Context context, int category) { 62 action(context, category, ""); 63 } 64 action(Context context, int category, int value)65 public static void action(Context context, int category, int value) { 66 action(context, category, Integer.toString(value)); 67 } 68 action(Context context, int category, boolean value)69 public static void action(Context context, int category, boolean value) { 70 action(context, category, Boolean.toString(value)); 71 } 72 action(Context context, int category, String pkg)73 public static void action(Context context, int category, String pkg) { 74 if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { 75 throw new IllegalArgumentException("Must define metric category"); 76 } 77 EventLogTags.writeSysuiAction(category, pkg); 78 } 79 80 /** Add an integer value to the monotonically increasing counter with the given name. */ count(Context context, String name, int value)81 public static void count(Context context, String name, int value) { 82 EventLogTags.writeSysuiCount(name, value); 83 } 84 85 /** Increment the bucket with the integer label on the histogram with the given name. */ histogram(Context context, String name, int bucket)86 public static void histogram(Context context, String name, int bucket) { 87 EventLogTags.writeSysuiHistogram(name, bucket); 88 } 89 } 90