From 6e0fd6b77759baf43cb37d407041be051b4856b5 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Wed, 4 Nov 2015 20:44:25 -0800 Subject: Route all existing screen view events through the Logger * The logger is responsible for sending it to its logging implementation, and also to AnalyicsUtil. * Standardize logic for creating a tagged version of a screen name Bug: 23164804 Change-Id: I9b817fba5359f78340f2d9fdba54af9ea73cdb37 --- src/com/android/dialer/DialtactsActivity.java | 7 ++- .../android/dialer/calllog/CallLogActivity.java | 3 +- src/com/android/dialer/list/ListsFragment.java | 10 +++-- .../android/dialer/list/RegularSearchFragment.java | 3 +- src/com/android/dialer/logging/Logger.java | 51 +++++++++++++++++++--- 5 files changed, 60 insertions(+), 14 deletions(-) (limited to 'src/com') diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index dabe590ad..4fa4bc2d7 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -81,6 +81,7 @@ import com.android.dialer.list.RegularSearchFragment; import com.android.dialer.list.SearchFragment; import com.android.dialer.list.SmartDialSearchFragment; import com.android.dialer.list.SpeedDialFragment; +import com.android.dialer.logging.Logger; import com.android.dialer.settings.DialerSettingsActivity; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.IntentUtil; @@ -526,7 +527,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O // This is only called when the activity goes from resumed -> paused -> resumed, so it // will not cause an extra view to be sent out on rotation if (mIsDialpadShown) { - AnalyticsUtil.sendScreenView(mDialpadFragment, this); + Logger.logFragmentView(mDialpadFragment); } mIsRestarting = false; } @@ -741,7 +742,9 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } mDialpadFragment.setAnimate(animate); - AnalyticsUtil.sendScreenView(mDialpadFragment); + // logScreenView is used here explicitly to provide the activity as the DialpadFragment + // might not have been attached yet. + Logger.logScreenView(DialpadFragment.class.getSimpleName(), this, null); ft.commit(); if (animate) { diff --git a/src/com/android/dialer/calllog/CallLogActivity.java b/src/com/android/dialer/calllog/CallLogActivity.java index c1923b2e4..f6defcfd9 100644 --- a/src/com/android/dialer/calllog/CallLogActivity.java +++ b/src/com/android/dialer/calllog/CallLogActivity.java @@ -40,6 +40,7 @@ import com.android.contacts.commonbind.analytics.AnalyticsUtil; import com.android.dialer.DialtactsActivity; import com.android.dialer.R; import com.android.dialer.TransactionSafeActivity; +import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; public class CallLogActivity extends TransactionSafeActivity implements ViewPager.OnPageChangeListener { @@ -222,7 +223,7 @@ public class CallLogActivity extends TransactionSafeActivity implements ViewPage } private void sendScreenViewForChildFragment(int position) { - AnalyticsUtil.sendScreenView(CallLogFragment.class.getSimpleName(), this, + Logger.logScreenView(CallLogFragment.class.getSimpleName(), this, getFragmentTagForPosition(position)); } diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 934792cdd..08a23732f 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -45,6 +45,7 @@ import com.android.dialer.R; import com.android.dialer.calllog.CallLogFragment; import com.android.dialer.calllog.CallLogQueryHandler; import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; import com.android.dialer.voicemail.VoicemailStatusHelper; import com.android.dialer.voicemail.VoicemailStatusHelperImpl; @@ -403,21 +404,24 @@ public class ListsFragment extends Fragment } String fragmentName; + String tag = null; switch (getCurrentTabIndex()) { case TAB_INDEX_SPEED_DIAL: fragmentName = SpeedDialFragment.class.getSimpleName(); break; case TAB_INDEX_HISTORY: - fragmentName = CallLogFragment.class.getSimpleName() + "#History"; + fragmentName = CallLogFragment.class.getSimpleName(); + tag = "History"; break; case TAB_INDEX_ALL_CONTACTS: fragmentName = AllContactsFragment.class.getSimpleName(); break; case TAB_INDEX_VOICEMAIL: - fragmentName = CallLogFragment.class.getSimpleName() + "#Voicemail"; + fragmentName = CallLogFragment.class.getSimpleName(); + tag = "Voicemail"; default: return; } - AnalyticsUtil.sendScreenView(fragmentName, getActivity(), null); + Logger.logScreenView(fragmentName, getActivity(), tag); } } diff --git a/src/com/android/dialer/list/RegularSearchFragment.java b/src/com/android/dialer/list/RegularSearchFragment.java index ed88d8355..c0807c35c 100644 --- a/src/com/android/dialer/list/RegularSearchFragment.java +++ b/src/com/android/dialer/list/RegularSearchFragment.java @@ -30,6 +30,7 @@ import com.android.dialerbind.ObjectFactory; import com.android.incallui.Call.LogState; import com.android.dialer.R; +import com.android.dialer.logging.Logger; import com.android.dialer.service.CachedNumberLookupService; import com.android.dialer.widget.EmptyContentView; import com.android.dialer.widget.EmptyContentView.OnEmptyViewActionButtonClickedListener; @@ -57,7 +58,7 @@ public class RegularSearchFragment extends SearchFragment @Override public void onStart() { super.onStart(); - AnalyticsUtil.sendScreenView(this); + Logger.logFragmentView(this); } public void configureDirectorySearch() { diff --git a/src/com/android/dialer/logging/Logger.java b/src/com/android/dialer/logging/Logger.java index 300707779..ee23dc8e7 100644 --- a/src/com/android/dialer/logging/Logger.java +++ b/src/com/android/dialer/logging/Logger.java @@ -17,11 +17,18 @@ package com.android.dialer.logging; import android.app.Activity; +import android.app.Fragment; +import android.text.TextUtils; +import com.android.contacts.commonbind.analytics.AnalyticsUtil; import com.android.dialerbind.ObjectFactory; import com.android.incallui.Call; +/** + * Single entry point for all logging/analytics-related work for all user interactions. + */ public abstract class Logger { + public static final String FRAGMENT_TAG_SEPARATOR = "#"; public static Logger getInstance() { return ObjectFactory.getLoggerInstance(); @@ -40,19 +47,49 @@ public abstract class Logger { } /** - * Logs an event indicating that a screen/fragment was displayed. + * Logs an event indicating that a fragment was displayed. + * + * @param fragment to log an event for. + */ + public static void logFragmentView(Fragment fragment) { + if (fragment == null) { + return; + } + + logScreenView(fragment.getClass().getSimpleName(), fragment.getActivity(), null); + } + + /** + * Logs an event indicating that a screen was displayed. * - * @param fragmentName of the displayed fragment. - * @param activity Parent activity of the fragment. - * @param tag Optional string used to provide additional information about the fragment. + * @param screenName of the displayed screen. + * @param activity Parent activity of the displayed screen. + * @param tag Optional string used to provide additional information about the screen. */ - public static void logScreenView(String fragmentName, Activity activity, String tag) { + public static void logScreenView(String screenName, Activity activity, String tag) { final Logger logger = getInstance(); if (logger != null) { - logger.logScreenViewImpl(fragmentName, activity, tag); + logger.logScreenViewImpl(getScreenNameWithTag(screenName, tag)); + } + + AnalyticsUtil.sendScreenView(screenName, activity, tag); + } + + /** + * Build a tagged version of the provided screenName if the tag is non-empty. + * + * @param screenName Name of the screen. + * @param tag Optional tag describing the screen. + * @return the unchanged screenName if the tag is {@code null} or empty, the tagged version of + * the screenName otherwise. + */ + public static String getScreenNameWithTag(String screenName, String tag) { + if (TextUtils.isEmpty(tag)) { + return screenName; } + return screenName + FRAGMENT_TAG_SEPARATOR + tag; } public abstract void logCallImpl(Call call); - public abstract void logScreenViewImpl(String fragmentName, Activity activity, String tag); + public abstract void logScreenViewImpl(String screenName); } -- cgit v1.2.3