1 /* 2 * Copyright 2016, 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.managedprovisioning.analytics; 18 19 import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.VIEW_UNKNOWN; 20 21 import android.content.Context; 22 23 import com.android.internal.logging.MetricsLogger; 24 import com.android.managedprovisioning.common.ProvisionLogger; 25 26 /** 27 * Utility class to log metrics using MetricsLogger. 28 */ 29 public class MetricsLoggerWrapper { 30 31 public static final boolean LOG_ENABLED = false; 32 MetricsLoggerWrapper()33 public MetricsLoggerWrapper() {} 34 35 /** 36 * Wrapper to log action with string values. 37 * 38 * @param context Context passed to MetricsLogger. 39 * @param category Metrics category to be logged. 40 * @param value String value to be logged 41 */ logAction(Context context, int category, String value)42 public void logAction(Context context, int category, String value) { 43 logd("MetricsLoggerWrapper, category:" + category + ", value: " + value); 44 if (category != VIEW_UNKNOWN) { 45 MetricsLogger.action(context, category, value); 46 } 47 } 48 49 /** 50 * Wrapper to log action with integer values. 51 * 52 * @param context Context passed to MetricsLogger. 53 * @param category Metrics category to be logged. 54 * @param value Int value to be logged. 55 */ logAction(Context context, int category, int value)56 public void logAction(Context context, int category, int value) { 57 logd("MetricsLoggerWrapper, category:" + category + ", value: " + value); 58 if (category != VIEW_UNKNOWN) { 59 MetricsLogger.action(context, category, value); 60 } 61 } 62 63 /** 64 * Wrapper to log action. 65 * 66 * @param context Context passed to MetricsLogger. 67 * @param category Metrics category to be logged. 68 */ logAction(Context context, int category)69 public void logAction(Context context, int category) { 70 logd("MetricsLoggerWrapper, category:" + category); 71 if (category != VIEW_UNKNOWN) { 72 MetricsLogger.action(context, category); 73 } 74 } 75 logd(String logText)76 private void logd(String logText) { 77 if (LOG_ENABLED) { 78 ProvisionLogger.logd(logText); 79 } 80 } 81 } 82