From b337e1c5ddc7b253f1a497ad7c20dde5efc5c7d7 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 18 Jan 2019 13:06:17 -0800 Subject: [PATCH] Added trace points for ContentCapture. Test: ./external/chromium-trace/systrace.py -o ~/tmp/trace.html -a android.contentcaptureservice.cts -t 1 view am Fixes: 120440520 Change-Id: Ic6ad506ac88a9d04b096d58f568d04904b72fb04 --- core/java/android/app/Activity.java | 66 ++++++++++++++++++++--------- core/java/android/view/View.java | 22 +++++++++- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 836627efb3795..1063be4c5c7db 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -74,6 +74,7 @@ import android.os.RemoteException; import android.os.ServiceManager.ServiceNotFoundException; import android.os.StrictMode; import android.os.SystemProperties; +import android.os.Trace; import android.os.UserHandle; import android.text.Selection; import android.text.SpannableStringBuilder; @@ -1049,33 +1050,56 @@ public class Activity extends ContextThemeWrapper @Retention(RetentionPolicy.SOURCE) @interface ContentCaptureNotificationType{} - - private void notifyContentCaptureManagerIfNeeded(@ContentCaptureNotificationType int type) { - final ContentCaptureManager cm = getContentCaptureManager(); - if (cm == null) return; - + private String getContentCaptureTypeAsString(@ContentCaptureNotificationType int type) { switch (type) { case CONTENT_CAPTURE_START: - //TODO(b/111276913): decide whether the InteractionSessionId should be - // saved / restored in the activity bundle - probably not - int flags = 0; - if ((getWindow().getAttributes().flags - & WindowManager.LayoutParams.FLAG_SECURE) != 0) { - flags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE; - } - cm.onActivityStarted(mToken, getComponentName(), flags); - break; + return "START"; case CONTENT_CAPTURE_PAUSE: - cm.flush(ContentCaptureSession.FLUSH_REASON_ACTIVITY_PAUSED); - break; + return "PAUSE"; case CONTENT_CAPTURE_RESUME: - cm.flush(ContentCaptureSession.FLUSH_REASON_ACTIVITY_RESUMED); - break; + return "RESUME"; case CONTENT_CAPTURE_STOP: - cm.onActivityStopped(); - break; + return "STOP"; default: - Log.wtf(TAG, "Invalid @ContentCaptureNotificationType: " + type); + return "UNKNOW-" + type; + } + } + + private void notifyContentCaptureManagerIfNeeded(@ContentCaptureNotificationType int type) { + if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { + Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, + "notifyContentCapture(" + getContentCaptureTypeAsString(type) + ") for " + + mComponent.toShortString()); + } + try { + final ContentCaptureManager cm = getContentCaptureManager(); + if (cm == null) return; + + switch (type) { + case CONTENT_CAPTURE_START: + //TODO(b/111276913): decide whether the InteractionSessionId should be + // saved / restored in the activity bundle - probably not + int flags = 0; + if ((getWindow().getAttributes().flags + & WindowManager.LayoutParams.FLAG_SECURE) != 0) { + flags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE; + } + cm.onActivityStarted(mToken, getComponentName(), flags); + break; + case CONTENT_CAPTURE_PAUSE: + cm.flush(ContentCaptureSession.FLUSH_REASON_ACTIVITY_PAUSED); + break; + case CONTENT_CAPTURE_RESUME: + cm.flush(ContentCaptureSession.FLUSH_REASON_ACTIVITY_RESUMED); + break; + case CONTENT_CAPTURE_STOP: + cm.onActivityStopped(); + break; + default: + Log.wtf(TAG, "Invalid @ContentCaptureNotificationType: " + type); + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); } } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 32974acdcbbd6..2553c59029661 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -8222,7 +8222,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * */ public void onProvideContentCaptureStructure(@NonNull ViewStructure structure, int flags) { - onProvideStructure(structure, VIEW_STRUCTURE_FOR_CONTENT_CAPTURE, flags); + if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) { + Trace.traceBegin(Trace.TRACE_TAG_VIEW, + "onProvideContentCaptureStructure() for " + getClass().getSimpleName()); + } + try { + onProvideStructure(structure, VIEW_STRUCTURE_FOR_CONTENT_CAPTURE, flags); + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW); + } } /** @hide */ @@ -9013,6 +9021,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * */ private void notifyAppearedOrDisappearedForContentCaptureIfNeeded(boolean appeared) { + if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) { + Trace.traceBegin(Trace.TRACE_TAG_VIEW, + "notifyContentCapture(" + appeared + ") for " + getClass().getSimpleName()); + } + try { + notifyAppearedOrDisappearedForContentCaptureIfNeededNoTrace(appeared); + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW); + } + } + + private void notifyAppearedOrDisappearedForContentCaptureIfNeededNoTrace(boolean appeared) { // First check if context has client, so it saves a service lookup when it doesn't if (!mContext.isContentCaptureSupported()) return;