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 /** 37 * The email provider for this account. 38 */ 39 public static final int CD_INDEX_ACCOUNT_EMAIL_PROVIDER = 1; 40 41 public static final int CD_INDEX_ACCOUNT_COUNT = 2; 42 43 public static final int CD_INDEX_SENDER_IMAGES_ENABLED = 3; 44 45 /** @deprecated Attachment Previews entirely removed from Conversation List */ 46 public static final int CD_INDEX_ATTACHMENT_PREVIEWS_ENABLED = 4; 47 48 public static final int CD_INDEX_INBOX_TYPE = 5; 49 50 public static final int CD_INDEX_INBOX_SECTIONS_ENABLED = 6; 51 52 public static final int CD_INDEX_REPLY_ALL_SETTING = 7; 53 54 public static final int CD_INDEX_AUTO_ADVANCE = 8; 55 56 /** 57 * Custom dimension in analytics to describe if the user already interacted with the app. 58 * The value is one of 59 * <ul> 60 * <li>{@link #CD_VALUE_USER_RETENTION_TYPE_NEW},</li> 61 * <li>{@link #CD_VALUE_USER_RETENTION_TYPE_UPGRADING} or</li> 62 * <li>{@link @CD_VALUE_USER_RETENTION_TYPE_RETURNING}</li> 63 * </ul> 64 */ 65 public static final int CD_INDEX_USER_RETENTION_TYPE = 9; 66 67 /** 68 * Value for {@link #CD_INDEX_USER_RETENTION_TYPE} meaning that the user has never used the 69 * Mail app anywhere before. 70 */ 71 public static final String CD_VALUE_USER_RETENTION_TYPE_NEW = "new"; 72 /** 73 * Value for {@link #CD_INDEX_USER_RETENTION_TYPE} meaning that the user has used an older 74 * version of the Mail app before. 75 */ 76 public static final String CD_VALUE_USER_RETENTION_TYPE_UPGRADING = "upgrading"; 77 78 /** 79 * Value for {@link #CD_INDEX_USER_RETENTION_TYPE} meaning that the user has already this 80 * version of the Mail app before. 81 */ 82 public static final String CD_VALUE_USER_RETENTION_TYPE_RETURNING = "returning"; 83 84 private static Tracker sInstance; 85 86 private Analytics() { 87 } 88 89 public static Tracker getInstance() { 90 synchronized (Analytics.class) { 91 if (sInstance == null) { 92 sInstance = new StubTracker(); 93 } 94 } 95 return sInstance; 96 } 97 98 public static void setTracker(Tracker t) { 99 synchronized (Analytics.class) { 100 sInstance = t; 101 } 102 } 103 104 public static boolean isLoggable() { 105 return !ActivityManager.isUserAMonkey() && !ActivityManager.isRunningInTestHarness(); 106 } 107 108 private static final class StubTracker implements Tracker { 109 110 @Override 111 public void activityStart(Activity a) {} 112 113 @Override 114 public void activityStop(Activity a) {} 115 116 @Override 117 public void sendEvent(String category, String action, String label, long value) {} 118 119 @Override 120 public void sendTiming(String category, long millis, String name, String label) {} 121 122 @Override 123 public void sendMenuItemEvent(String category, int itemResId, String label, long value) {} 124 125 @Override 126 public void sendView(String view) {} 127 128 @Override 129 public void setCustomDimension(int index, String value) {} 130 131 @Override 132 public void setCustomMetric(int index, Long value) {} 133 134 @Override 135 public void debugDispatchNow() {} 136 137 @Override 138 public void setEmail(String emailAddress, String accountManagerType) {} 139 } 140 141 } 142