From 9082f5b697132e639d7f534017bde9d71f264713 Mon Sep 17 00:00:00 2001 From: Kang Li Date: Fri, 2 Dec 2016 10:56:21 -0800 Subject: [PATCH] Log metrics for Smart-Sharing in ChooserActivity. Bug: 33051310, 30982298 Test: manually shared several images in Camera. Change-Id: I6b147ec89729815931e2b626b7533e1e5b95c819 --- .../android/internal/app/ChooserActivity.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index c314cae2f55c7..d85442fbf6303 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -96,6 +96,9 @@ public class ChooserActivity extends ResolverActivity { private Intent mReferrerFillInIntent; + private long mChooserShownTime; + private boolean mIsSuccessfullySelected; + private ChooserListAdapter mChooserListAdapter; private ChooserRowAdapter mChooserRowAdapter; @@ -155,6 +158,8 @@ public class ChooserActivity extends ResolverActivity { @Override protected void onCreate(Bundle savedInstanceState) { + final long intentReceivedTime = System.currentTimeMillis(); + mIsSuccessfullySelected = false; Intent intent = getIntent(); Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT); if (!(targetParcelable instanceof Intent)) { @@ -257,6 +262,13 @@ public class ChooserActivity extends ResolverActivity { null, false); MetricsLogger.action(this, MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN); + + mChooserShownTime = System.currentTimeMillis(); + final long systemCost = mChooserShownTime - intentReceivedTime; + MetricsLogger.histogram(null, "system_cost_for_smart_sharing", (int) systemCost); + if (DEBUG) { + Log.d(TAG, "System Time Cost is " + systemCost); + } } static SharedPreferences getPinnedSharedPrefs(Context context) { @@ -410,6 +422,7 @@ public class ChooserActivity extends ResolverActivity { @Override public void startSelected(int which, boolean always, boolean filtered) { + final long selectionCost = System.currentTimeMillis() - mChooserShownTime; super.startSelected(which, always, filtered); if (mChooserListAdapter != null) { @@ -435,6 +448,17 @@ public class ChooserActivity extends ResolverActivity { if (cat != 0) { MetricsLogger.action(this, cat, value); } + + if (mIsSuccessfullySelected) { + if (DEBUG) { + Log.d(TAG, "User Selection Time Cost is " + selectionCost); + Log.d(TAG, "position of selected app/service/caller is " + + Integer.toString(value)); + } + MetricsLogger.histogram(null, "user_selection_cost_for_smart_sharing", + (int) selectionCost); + MetricsLogger.histogram(null, "app_position_for_smart_sharing", value); + } } } @@ -570,6 +594,7 @@ public class ChooserActivity extends ResolverActivity { Log.d(TAG, "Can not log Chooser Counts of null ResovleInfo"); } } + mIsSuccessfullySelected = true; } void onRefinementResult(TargetInfo selectedTarget, Intent matchingIntent) {