Merge "Add latency instrument for loading share sheet" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-18 15:45:53 +00:00
committed by Android (Google) Code Review
6 changed files with 54 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ import android.content.Intent;
import android.content.pm.IPackageManager; import android.content.pm.IPackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.stats.devicepolicy.DevicePolicyEnums; import android.stats.devicepolicy.DevicePolicyEnums;
@@ -286,7 +287,10 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
* <p>Returns {@code true} if rebuild has completed. * <p>Returns {@code true} if rebuild has completed.
*/ */
boolean rebuildActiveTab(boolean doPostProcessing) { boolean rebuildActiveTab(boolean doPostProcessing) {
return rebuildTab(getActiveListAdapter(), doPostProcessing); Trace.beginSection("MultiProfilePagerAdapter#rebuildActiveTab");
boolean result = rebuildTab(getActiveListAdapter(), doPostProcessing);
Trace.endSection();
return result;
} }
/** /**
@@ -294,10 +298,14 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
* <p>Returns {@code true} if rebuild has completed. * <p>Returns {@code true} if rebuild has completed.
*/ */
boolean rebuildInactiveTab(boolean doPostProcessing) { boolean rebuildInactiveTab(boolean doPostProcessing) {
Trace.beginSection("MultiProfilePagerAdapter#rebuildInactiveTab");
if (getItemCount() == 1) { if (getItemCount() == 1) {
Trace.endSection();
return false; return false;
} }
return rebuildTab(getInactiveListAdapter(), doPostProcessing); boolean result = rebuildTab(getInactiveListAdapter(), doPostProcessing);
Trace.endSection();
return result;
} }
private int userHandleToPageIndex(UserHandle userHandle) { private int userHandleToPageIndex(UserHandle userHandle) {

View File

@@ -16,6 +16,8 @@
package com.android.internal.app; package com.android.internal.app;
import static com.android.internal.util.LatencyTracker.ACTION_LOAD_SHARE_SHEET;
import static java.lang.annotation.RetentionPolicy.SOURCE; import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.animation.Animator; import android.animation.Animator;
@@ -509,6 +511,8 @@ public class ChooserActivity extends ResolverActivity implements
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
final long intentReceivedTime = System.currentTimeMillis(); final long intentReceivedTime = System.currentTimeMillis();
mLatencyTracker.onActionStart(ACTION_LOAD_SHARE_SHEET);
getChooserActivityLogger().logSharesheetTriggered(); getChooserActivityLogger().logSharesheetTriggered();
// This is the only place this value is being set. Effectively final. // This is the only place this value is being set. Effectively final.
mIsAppPredictorComponentAvailable = isAppPredictionServiceAvailable(); mIsAppPredictorComponentAvailable = isAppPredictionServiceAvailable();
@@ -1538,6 +1542,10 @@ public class ChooserActivity extends ResolverActivity implements
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
if (isFinishing()) {
mLatencyTracker.onActionCancel(ACTION_LOAD_SHARE_SHEET);
}
if (mRefinementResultReceiver != null) { if (mRefinementResultReceiver != null) {
mRefinementResultReceiver.destroy(); mRefinementResultReceiver.destroy();
mRefinementResultReceiver = null; mRefinementResultReceiver = null;
@@ -2665,6 +2673,7 @@ public class ChooserActivity extends ResolverActivity implements
if (rebuildComplete) { if (rebuildComplete) {
getChooserActivityLogger().logSharesheetAppLoadComplete(); getChooserActivityLogger().logSharesheetAppLoadComplete();
maybeQueryAdditionalPostProcessingTargets(chooserListAdapter); maybeQueryAdditionalPostProcessingTargets(chooserListAdapter);
mLatencyTracker.onActionEnd(ACTION_LOAD_SHARE_SHEET);
} }
} }

View File

@@ -31,6 +31,7 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
@@ -667,8 +668,10 @@ public class ChooserListAdapter extends ResolverListAdapter {
@Override @Override
protected List<ResolvedComponentInfo> doInBackground( protected List<ResolvedComponentInfo> doInBackground(
List<ResolvedComponentInfo>... params) { List<ResolvedComponentInfo>... params) {
Trace.beginSection("ChooserListAdapter#SortingTask");
mResolverListController.topK(params[0], mResolverListController.topK(params[0],
mChooserListCommunicator.getMaxRankedTargets()); mChooserListCommunicator.getMaxRankedTargets());
Trace.endSection();
return params[0]; return params[0];
} }
@Override @Override

View File

@@ -61,6 +61,7 @@ import android.os.Bundle;
import android.os.PatternMatcher; import android.os.PatternMatcher;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.MediaStore; import android.provider.MediaStore;
@@ -98,6 +99,7 @@ import com.android.internal.app.chooser.TargetInfo;
import com.android.internal.content.PackageMonitor; import com.android.internal.content.PackageMonitor;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.util.LatencyTracker;
import com.android.internal.widget.ResolverDrawerLayout; import com.android.internal.widget.ResolverDrawerLayout;
import com.android.internal.widget.ViewPager; import com.android.internal.widget.ViewPager;
@@ -214,7 +216,11 @@ public class ResolverActivity extends Activity implements
private UserHandle mWorkProfileUserHandle; private UserHandle mWorkProfileUserHandle;
protected final LatencyTracker mLatencyTracker = getLatencyTracker();
private LatencyTracker getLatencyTracker() {
return LatencyTracker.getInstance(this);
}
/** /**
* Get the string resource to be used as a label for the link to the resolver activity for an * Get the string resource to be used as a label for the link to the resolver activity for an
@@ -1433,6 +1439,7 @@ public class ResolverActivity extends Activity implements
throw new IllegalStateException("mMultiProfilePagerAdapter.getCurrentListAdapter() " throw new IllegalStateException("mMultiProfilePagerAdapter.getCurrentListAdapter() "
+ "cannot be null."); + "cannot be null.");
} }
Trace.beginSection("configureContentView");
// We partially rebuild the inactive adapter to determine if we should auto launch // We partially rebuild the inactive adapter to determine if we should auto launch
// isTabLoaded will be true here if the empty state screen is shown instead of the list. // isTabLoaded will be true here if the empty state screen is shown instead of the list.
boolean rebuildCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true) boolean rebuildCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true)
@@ -1445,6 +1452,7 @@ public class ResolverActivity extends Activity implements
if (shouldUseMiniResolver()) { if (shouldUseMiniResolver()) {
configureMiniResolverContent(); configureMiniResolverContent();
Trace.endSection();
return false; return false;
} }
@@ -1455,7 +1463,9 @@ public class ResolverActivity extends Activity implements
} }
setContentView(mLayoutId); setContentView(mLayoutId);
mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager)); mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager));
return postRebuildList(rebuildCompleted); boolean result = postRebuildList(rebuildCompleted);
Trace.endSection();
return result;
} }
/** /**

View File

@@ -38,6 +38,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.text.TextUtils; import android.text.TextUtils;
@@ -188,6 +189,7 @@ public class ResolverListAdapter extends BaseAdapter {
* Otherwise the callback is only queued once, with {@code rebuildCompleted} true. * Otherwise the callback is only queued once, with {@code rebuildCompleted} true.
*/ */
protected boolean rebuildList(boolean doPostProcessing) { protected boolean rebuildList(boolean doPostProcessing) {
Trace.beginSection("ResolverListAdapter#rebuildList");
mDisplayList.clear(); mDisplayList.clear();
mIsTabLoaded = false; mIsTabLoaded = false;
mLastChosenPosition = -1; mLastChosenPosition = -1;
@@ -241,8 +243,10 @@ public class ResolverListAdapter extends BaseAdapter {
mUnfilteredResolveList = originalList; mUnfilteredResolveList = originalList;
} }
boolean result =
return finishRebuildingListWithFilteredResults(currentResolveList, doPostProcessing); finishRebuildingListWithFilteredResults(currentResolveList, doPostProcessing);
Trace.endSection();
return result;
} }
/** /**
@@ -402,8 +406,9 @@ public class ResolverListAdapter extends BaseAdapter {
protected void processSortedList(List<ResolvedComponentInfo> sortedComponents, protected void processSortedList(List<ResolvedComponentInfo> sortedComponents,
boolean doPostProcessing) { boolean doPostProcessing) {
int n; final int n = sortedComponents != null ? sortedComponents.size() : 0;
if (sortedComponents != null && (n = sortedComponents.size()) != 0) { Trace.beginSection("ResolverListAdapter#processSortedList:" + n);
if (n != 0) {
// First put the initial items at the top. // First put the initial items at the top.
if (mInitialIntents != null) { if (mInitialIntents != null) {
for (int i = 0; i < mInitialIntents.length; i++) { for (int i = 0; i < mInitialIntents.length; i++) {
@@ -451,6 +456,7 @@ public class ResolverListAdapter extends BaseAdapter {
mResolverListCommunicator.sendVoiceChoicesIfNeeded(); mResolverListCommunicator.sendVoiceChoicesIfNeeded();
postListReadyRunnable(doPostProcessing, /* rebuildCompleted */ true); postListReadyRunnable(doPostProcessing, /* rebuildCompleted */ true);
mIsTabLoaded = true; mIsTabLoaded = true;
Trace.endSection();
} }
/** /**

View File

@@ -137,6 +137,11 @@ public class LatencyTracker {
*/ */
public static final int ACTION_SHOW_BACK_ARROW = 15; public static final int ACTION_SHOW_BACK_ARROW = 15;
/**
* Time it takes for loading share sheet.
*/
public static final int ACTION_LOAD_SHARE_SHEET = 16;
private static final int[] ACTIONS_ALL = { private static final int[] ACTIONS_ALL = {
ACTION_EXPAND_PANEL, ACTION_EXPAND_PANEL,
ACTION_TOGGLE_RECENTS, ACTION_TOGGLE_RECENTS,
@@ -154,6 +159,7 @@ public class LatencyTracker {
ACTION_SWITCH_DISPLAY_UNFOLD, ACTION_SWITCH_DISPLAY_UNFOLD,
ACTION_UDFPS_ILLUMINATE, ACTION_UDFPS_ILLUMINATE,
ACTION_SHOW_BACK_ARROW, ACTION_SHOW_BACK_ARROW,
ACTION_LOAD_SHARE_SHEET,
}; };
/** @hide */ /** @hide */
@@ -173,7 +179,8 @@ public class LatencyTracker {
ACTION_USER_SWITCH, ACTION_USER_SWITCH,
ACTION_SWITCH_DISPLAY_UNFOLD, ACTION_SWITCH_DISPLAY_UNFOLD,
ACTION_UDFPS_ILLUMINATE, ACTION_UDFPS_ILLUMINATE,
ACTION_SHOW_BACK_ARROW ACTION_SHOW_BACK_ARROW,
ACTION_LOAD_SHARE_SHEET,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface Action { public @interface Action {
@@ -196,6 +203,7 @@ public class LatencyTracker {
FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SWITCH_DISPLAY_UNFOLD, FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SWITCH_DISPLAY_UNFOLD,
FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_UDFPS_ILLUMINATE, FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_UDFPS_ILLUMINATE,
FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SHOW_BACK_ARROW, FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SHOW_BACK_ARROW,
FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_LOAD_SHARE_SHEET,
}; };
private static LatencyTracker sLatencyTracker; private static LatencyTracker sLatencyTracker;
@@ -287,6 +295,8 @@ public class LatencyTracker {
return "ACTION_UDFPS_ILLUMINATE"; return "ACTION_UDFPS_ILLUMINATE";
case 16: case 16:
return "ACTION_SHOW_BACK_ARROW"; return "ACTION_SHOW_BACK_ARROW";
case 17:
return "ACTION_LOAD_SHARE_SHEET";
default: default:
throw new IllegalArgumentException("Invalid action"); throw new IllegalArgumentException("Invalid action");
} }