Adjusted tracing of reportFullyDrawn() API call.

This patch adjusts how the reportFullyDrawn() API call records this
information in the tracing system.  Instead of an asynch slice that may
or may not be ended by reportFullyDrawn() we now emit a slice around the
function used to handle this callback.  This slice name now also
includes the name of the package that made the callback.

Test: Built and loaded the image; launched Photos
Change-Id: I8d55be73303133a8a1e4648b1fc9eb7938a453ab
diff --git a/services/core/java/com/android/server/am/ActivityMetricsLogger.java b/services/core/java/com/android/server/am/ActivityMetricsLogger.java
index 18cdb05..0c51a39 100644
--- a/services/core/java/com/android/server/am/ActivityMetricsLogger.java
+++ b/services/core/java/com/android/server/am/ActivityMetricsLogger.java
@@ -155,7 +155,6 @@
     private final H mHandler;
 
     private ArtManagerInternal mArtManagerInternal;
-    private boolean mDrawingTraceActive;
     private final StringBuilder mStringBuilder = new StringBuilder();
 
     private final class H extends Handler {
@@ -496,7 +495,6 @@
                 if (mWindowingModeTransitionInfo.size() == 0) {
                     reset(true /* abort */, info);
                 }
-                stopFullyDrawnTraceIfNeeded();
             }
         }
     }
@@ -694,6 +692,13 @@
         if (info == null) {
             return null;
         }
+
+        // Record the handling of the reportFullyDrawn callback in the trace system. This is not
+        // actually used to trace this function, but instead the logical task that this function
+        // fullfils (handling reportFullyDrawn() callbacks).
+        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,
+                "ActivityManager:ReportingFullyDrawn " + info.launchedActivity.packageName);
+
         final LogMaker builder = new LogMaker(APP_TRANSITION_REPORTED_DRAWN);
         builder.setPackageName(r.packageName);
         builder.addTaggedData(FIELD_CLASS_NAME, r.info.name);
@@ -715,7 +720,11 @@
                 info.launchedActivity.info.name,
                 info.currentTransitionProcessRunning,
                 startupTimeMs);
-        stopFullyDrawnTraceIfNeeded();
+
+        // Ends the trace started at the beginning of this function. This is located here to allow
+        // the trace slice to have a noticable duration.
+        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
+
         final WindowingModeTransitionInfoSnapshot infoSnapshot =
                 new WindowingModeTransitionInfoSnapshot(info, r, (int) startupTimeMs);
         BackgroundThread.getHandler().post(() -> logAppFullyDrawn(infoSnapshot));
@@ -882,10 +891,7 @@
     }
 
     /**
-     * Starts traces for app launch and draw times. We stop the fully drawn trace if its already
-     * active since the app may not have reported fully drawn in the previous launch.
-     *
-     * See {@link android.app.Activity#reportFullyDrawn()}
+     * Starts traces for app launch.
      *
      * @param info
      * */
@@ -893,14 +899,11 @@
         if (info == null) {
             return;
         }
-        stopFullyDrawnTraceIfNeeded();
         int transitionType = getTransitionType(info);
         if (!info.launchTraceActive && transitionType == TYPE_TRANSITION_WARM_LAUNCH
                 || transitionType == TYPE_TRANSITION_COLD_LAUNCH) {
             Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: "
                     + info.launchedActivity.packageName, 0);
-            Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
-            mDrawingTraceActive = true;
             info.launchTraceActive = true;
         }
     }
@@ -915,11 +918,4 @@
             info.launchTraceActive = false;
         }
     }
-
-    void stopFullyDrawnTraceIfNeeded() {
-        if (mDrawingTraceActive) {
-            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
-            mDrawingTraceActive = false;
-        }
-    }
 }
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 6388423..648752c 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -1509,8 +1509,6 @@
         prev.getTask().touchActiveTime();
         clearLaunchTime(prev);
 
-        mStackSupervisor.getActivityMetricsLogger().stopFullyDrawnTraceIfNeeded();
-
         mService.updateCpuStats();
 
         if (prev.attachedToProcess()) {