summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java75
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/Metrics.java12
2 files changed, 53 insertions, 34 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
index 29110275716e..73b3509ebee2 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
@@ -58,6 +58,7 @@ import com.android.documentsui.model.RootInfo;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.concurrent.Executor;
@@ -79,6 +80,7 @@ public abstract class BaseActivity extends Activity
private int mLayoutId;
private boolean mNavDrawerHasFocus;
+ private long mStartTime;
public abstract void onDocumentPicked(DocumentInfo doc, Model model);
public abstract void onDocumentsPicked(List<DocumentInfo> docs);
@@ -96,16 +98,14 @@ public abstract class BaseActivity extends Activity
@CallSuper
@Override
public void onCreate(Bundle icicle) {
+ // Record the time when onCreate is invoked for metric.
+ mStartTime = new Date().getTime();
+
super.onCreate(icicle);
final Intent intent = getIntent();
- // If startup benchmark is requested by a whitelisted testing package, then close the
- // activity once idle, and notify the testing activity.
- if (intent.getBooleanExtra(EXTRA_BENCHMARK, false) &&
- BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
- closeOnIdleForTesting();
- }
+ addListenerForLaunchCompletion();
setContentView(mLayoutId);
@@ -604,12 +604,10 @@ public abstract class BaseActivity extends Activity
return super.onKeyDown(keyCode, event);
}
- @VisibleForTesting
public void addEventListener(EventListener listener) {
mEventListeners.add(listener);
}
- @VisibleForTesting
public void removeEventListener(EventListener listener) {
mEventListeners.remove(listener);
}
@@ -673,31 +671,10 @@ public abstract class BaseActivity extends Activity
return false;
}
- private static final class PickRootTask extends PairedTask<BaseActivity, Void, DocumentInfo> {
- private RootInfo mRoot;
-
- public PickRootTask(BaseActivity activity, RootInfo root) {
- super(activity);
- mRoot = root;
- }
-
- @Override
- protected DocumentInfo run(Void... params) {
- return mOwner.getRootDocumentBlocking(mRoot);
- }
-
- @Override
- protected void finish(DocumentInfo result) {
- if (result != null) {
- mOwner.openContainerDocument(result);
- }
- }
- }
-
/**
- * Closes the activity when it's idle. Used only for tests.
+ * Closes the activity when it's idle.
*/
- private void closeOnIdleForTesting() {
+ private void addListenerForLaunchCompletion() {
addEventListener(new EventListener() {
@Override
public void onDirectoryNavigated(Uri uri) {
@@ -705,11 +682,22 @@ public abstract class BaseActivity extends Activity
@Override
public void onDirectoryLoaded(Uri uri) {
+ removeEventListener(this);
getMainLooper().getQueue().addIdleHandler(new IdleHandler() {
@Override
public boolean queueIdle() {
- setResult(RESULT_OK);
- finish();
+ // If startup benchmark is requested by a whitelisted testing package, then
+ // close the activity once idle, and notify the testing activity.
+ if (getIntent().getBooleanExtra(EXTRA_BENCHMARK, false) &&
+ BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
+ setResult(RESULT_OK);
+ finish();
+ }
+
+ Metrics.logStartupMs(
+ BaseActivity.this, (int) (new Date().getTime() - mStartTime));
+
+ // Remove the idle handler.
return false;
}
});
@@ -721,6 +709,27 @@ public abstract class BaseActivity extends Activity
});
}
+ private static final class PickRootTask extends PairedTask<BaseActivity, Void, DocumentInfo> {
+ private RootInfo mRoot;
+
+ public PickRootTask(BaseActivity activity, RootInfo root) {
+ super(activity);
+ mRoot = root;
+ }
+
+ @Override
+ protected DocumentInfo run(Void... params) {
+ return mOwner.getRootDocumentBlocking(mRoot);
+ }
+
+ @Override
+ protected void finish(DocumentInfo result) {
+ if (result != null) {
+ mOwner.openContainerDocument(result);
+ }
+ }
+ }
+
private static final class HandleRootsChangedTask
extends PairedTask<BaseActivity, RootInfo, RootInfo> {
DocumentInfo mDownloadsDocument;
diff --git a/packages/DocumentsUI/src/com/android/documentsui/Metrics.java b/packages/DocumentsUI/src/com/android/documentsui/Metrics.java
index 929d1e0d0ac6..e6b22e6ed73f 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/Metrics.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/Metrics.java
@@ -64,6 +64,7 @@ public final class Metrics {
private static final String COUNT_FILEOP_SYSTEM = "docsui_fileop_system";
private static final String COUNT_FILEOP_EXTERNAL = "docsui_fileop_external";
private static final String COUNT_FILEOP_CANCELED = "docsui_fileop_canceled";
+ private static final String COUNT_STARTUP_MS = "docsui_startup_ms";
// Indices for bucketing roots in the roots histogram. "Other" is the catch-all index for any
// root that is not explicitly recognized by the Metrics code (see {@link
@@ -347,7 +348,7 @@ public final class Metrics {
}
/**
- * Log the cancellation of a file operation. Call this when a Job is canceled.
+ * Logs the cancellation of a file operation. Call this when a Job is canceled.
* @param context
* @param operationType
*/
@@ -355,6 +356,15 @@ public final class Metrics {
logHistogram(context, COUNT_FILEOP_CANCELED, toMetricsOpType(operationType));
}
+ /**
+ * Logs startup time in milliseconds.
+ * @param context
+ * @param startupMs Startup time in milliseconds.
+ */
+ public static void logStartupMs(Context context, int startupMs) {
+ logHistogram(context, COUNT_STARTUP_MS, startupMs);
+ }
+
private static void logInterProviderFileOps(
Context context,
String histogram,