Home | History | Annotate | Download | only in analytics
      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     /** @deprecated Attachment Previews entirely removed from Conversation List */
     43     public static final int CD_INDEX_ATTACHMENT_PREVIEWS_ENABLED = 4;
     44 
     45     public static final int CD_INDEX_INBOX_TYPE = 5;
     46 
     47     public static final int CD_INDEX_INBOX_SECTIONS_ENABLED = 6;
     48 
     49     public static final int CD_INDEX_REPLY_ALL_SETTING = 7;
     50 
     51     public static final int CD_INDEX_AUTO_ADVANCE = 8;
     52 
     53     private static Tracker sInstance;
     54 
     55     private Analytics() {
     56     }
     57 
     58     public static Tracker getInstance() {
     59         synchronized (Analytics.class) {
     60             if (sInstance == null) {
     61                 sInstance = new StubTracker();
     62             }
     63         }
     64         return sInstance;
     65     }
     66 
     67     public static void setTracker(Tracker t) {
     68         synchronized (Analytics.class) {
     69             sInstance = t;
     70         }
     71     }
     72 
     73     public static boolean isLoggable() {
     74         return !ActivityManager.isUserAMonkey() && !ActivityManager.isRunningInTestHarness();
     75     }
     76 
     77     private static final class StubTracker implements Tracker {
     78 
     79         @Override
     80         public void activityStart(Activity a) {}
     81 
     82         @Override
     83         public void activityStop(Activity a) {}
     84 
     85         @Override
     86         public void sendEvent(String category, String action, String label, long value) {}
     87 
     88         @Override
     89         public void sendTiming(String category, long millis, String name, String label) {}
     90 
     91         @Override
     92         public void sendMenuItemEvent(String category, int itemResId, String label, long value) {}
     93 
     94         @Override
     95         public void sendView(String view) {}
     96 
     97         @Override
     98         public void setCustomDimension(int index, String value) {}
     99 
    100         @Override
    101         public void setCustomMetric(int index, Long value) {}
    102 
    103         @Override
    104         public void debugDispatchNow() {}
    105 
    106     }
    107 
    108 }
    109