Verify AppStartFullyDrawn in app start tests.

Bug: 212815020
Test: atest hostsidetests/statsdatom/src/android/cts/statsdatom/appstart/AppStartStatsTests.java
Change-Id: I0cc6a0993ea2917bd7687f7848be2458104158b7
diff --git a/hostsidetests/statsdatom/apps/statsdapp/src/com/android/server/cts/device/statsdatom/StatsdCtsForegroundActivity.java b/hostsidetests/statsdatom/apps/statsdapp/src/com/android/server/cts/device/statsdatom/StatsdCtsForegroundActivity.java
index df11114..0f1569e 100644
--- a/hostsidetests/statsdatom/apps/statsdapp/src/com/android/server/cts/device/statsdatom/StatsdCtsForegroundActivity.java
+++ b/hostsidetests/statsdatom/apps/statsdapp/src/com/android/server/cts/device/statsdatom/StatsdCtsForegroundActivity.java
@@ -125,6 +125,7 @@
 
             @Override
             protected void onPostExecute(Void nothing) {
+                reportFullyDrawn();
                 finish();
             }
         }.execute();
diff --git a/hostsidetests/statsdatom/src/android/cts/statsdatom/appstart/AppStartStatsTests.java b/hostsidetests/statsdatom/src/android/cts/statsdatom/appstart/AppStartStatsTests.java
index 6701860..b6c2439 100644
--- a/hostsidetests/statsdatom/src/android/cts/statsdatom/appstart/AppStartStatsTests.java
+++ b/hostsidetests/statsdatom/src/android/cts/statsdatom/appstart/AppStartStatsTests.java
@@ -24,6 +24,7 @@
 import android.cts.statsdatom.lib.ReportUtils;
 
 import com.android.annotations.Nullable;
+import com.android.internal.os.StatsdConfigProto.StatsdConfig;
 import com.android.os.AtomsProto;
 import com.android.os.StatsLog;
 import com.android.tradefed.build.IBuildInfo;
@@ -107,11 +108,19 @@
 
     private void runTestAppStartOccurredCommon(@Nullable RunnableWithException prolog,
             @Nullable ConsumerWithException<AtomsProto.AppStartOccurred> epilog) throws Exception {
-        final int atomTag = AtomsProto.Atom.APP_START_OCCURRED_FIELD_NUMBER;
-        ConfigUtils.uploadConfigForPushedAtomWithUid(getDevice(), DeviceUtils.STATSD_ATOM_TEST_PKG,
-                atomTag,  /*uidInAttributionChain=*/false);
-        getDevice().executeShellCommand(getGlobalHibernationCommand(
-                DeviceUtils.STATSD_ATOM_TEST_PKG, false));
+        StatsdConfig.Builder config =
+                ConfigUtils.createConfigBuilder(DeviceUtils.STATSD_ATOM_TEST_PKG);
+        ConfigUtils.addEventMetricForUidAtom(
+                config,
+                AtomsProto.Atom.APP_START_OCCURRED_FIELD_NUMBER,
+                /*uidInAttributionChain=*/false,
+                DeviceUtils.STATSD_ATOM_TEST_PKG);
+        ConfigUtils.addEventMetricForUidAtom(
+                config,
+                AtomsProto.Atom.APP_START_FULLY_DRAWN_FIELD_NUMBER,
+                /*uidInAttributionChain=*/false,
+                DeviceUtils.STATSD_ATOM_TEST_PKG);
+        ConfigUtils.uploadConfig(getDevice(), config);
 
         if (prolog != null) {
             prolog.run();
@@ -123,7 +132,7 @@
         // Sorted list of events in order in which they occurred.
         List<StatsLog.EventMetricData> data = ReportUtils.getEventMetricDataList(getDevice());
 
-        assertThat(data).hasSize(1);
+        assertThat(data).hasSize(2);
         AtomsProto.AppStartOccurred atom = data.get(0).getAtom().getAppStartOccurred();
         assertThat(atom.getPkgName()).isEqualTo(DeviceUtils.STATSD_ATOM_TEST_PKG);
         assertThat(atom.getActivityName())
@@ -132,6 +141,16 @@
         assertThat(atom.getActivityStartTimestampMillis()).isGreaterThan(0L);
         assertThat(atom.getTransitionDelayMillis()).isGreaterThan(0);
         assertThat(atom.getIsHibernating()).isFalse();
+
+        AtomsProto.AppStartFullyDrawn fullyDrawnAtom =
+                data.get(1).getAtom().getAppStartFullyDrawn();
+        assertThat(fullyDrawnAtom.getPkgName()).isEqualTo(DeviceUtils.STATSD_ATOM_TEST_PKG);
+        assertThat(fullyDrawnAtom.getActivityName())
+                .isEqualTo("com.android.server.cts.device.statsdatom.StatsdCtsForegroundActivity");
+        // Both events should have the same trigger timestamp so they can be joined.
+        assertThat(fullyDrawnAtom.getActivityStartTimestampMillis())
+                .isEqualTo(atom.getActivityStartTimestampMillis());
+
         if (epilog != null) {
             epilog.accept(atom);
         }