1 /******************************************************************************* 2 * Copyright (C) 2013 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 *******************************************************************************/ 17 18 package com.android.mail.analytics; 19 20 import android.app.Activity; 21 import android.app.ActivityManager; 22 23 /** 24 * Mail wrapper for analytics libraries. Libraries should implement {@link Tracker}, and app 25 * configurations that want to enable analytics should call {@link #setTracker(Tracker)} as soon 26 * as possible upon application start. 27 * <p> 28 * {@link #getInstance()} will always return an object, but if the app has not yet (or will not 29 * ever) set its own tracker instance, method calls on that tracker will be stubbed out. 30 * 31 */ 32 public final class Analytics { 33 34 public static final String EVENT_CATEGORY_MENU_ITEM = "menu_item"; 35 36 public static final int CD_INDEX_ACCOUNT_TYPE = 1; 37 38 public static final int CD_INDEX_ACCOUNT_COUNT = 2; 39 40 public static final int CD_INDEX_SENDER_IMAGES_ENABLED = 3; 41 42 public static final int CD_INDEX_ATTACHMENT_PREVIEWS_ENABLED = 4; 43 44 public static final int CD_INDEX_INBOX_TYPE = 5; 45 46 public static final int CD_INDEX_INBOX_SECTIONS_ENABLED = 6; 47 48 public static final int CD_INDEX_REPLY_ALL_SETTING = 7; 49 50 private static Tracker sInstance; 51 52 private Analytics() { 53 } 54 55 public static Tracker getInstance() { 56 synchronized (Analytics.class) { 57 if (sInstance == null) { 58 sInstance = new StubTracker(); 59 } 60 } 61 return sInstance; 62 } 63 64 public static void setTracker(Tracker t) { 65 synchronized (Analytics.class) { 66 sInstance = t; 67 } 68 } 69 70 public static boolean isLoggable() { 71 return !ActivityManager.isUserAMonkey() && !ActivityManager.isRunningInTestHarness(); 72 } 73 74 private static final class StubTracker implements Tracker { 75 76 @Override 77 public void activityStart(Activity a) {} 78 79 @Override 80 public void activityStop(Activity a) {} 81 82 @Override 83 public void sendEvent(String category, String action, String label, long value) {} 84 85 @Override 86 public void sendMenuItemEvent(String category, int itemResId, String label, long value) {} 87 88 @Override 89 public void sendView(String view) {} 90 91 @Override 92 public void setCustomDimension(int index, String value) {} 93 94 @Override 95 public void setCustomMetric(int index, Long value) {} 96 97 @Override 98 public void debugDispatchNow() {} 99 100 } 101 102 } 103