Migrate testAppCrashOccurred
Bug: 163546661
Test: atest UidAtomTests#testAppCrashOccurred
Change-Id: I74a0fdbe1e8191f1506e87b212521c367351aad0
diff --git a/hostsidetests/statsd/apps/statsdapp/src/com/android/server/cts/device/statsd/StatsdCtsForegroundActivity.java b/hostsidetests/statsd/apps/statsdapp/src/com/android/server/cts/device/statsd/StatsdCtsForegroundActivity.java
index c8c02fc..1f14c3a 100644
--- a/hostsidetests/statsd/apps/statsdapp/src/com/android/server/cts/device/statsd/StatsdCtsForegroundActivity.java
+++ b/hostsidetests/statsd/apps/statsdapp/src/com/android/server/cts/device/statsd/StatsdCtsForegroundActivity.java
@@ -46,7 +46,6 @@
public static final String ACTION_LONG_SLEEP_WHILE_TOP = "action.long_sleep_top";
public static final String ACTION_SHOW_APPLICATION_OVERLAY = "action.show_application_overlay";
public static final String ACTION_SHOW_NOTIFICATION = "action.show_notification";
- public static final String ACTION_CRASH = "action.crash";
public static final String ACTION_CREATE_CHANNEL_GROUP = "action.create_channel_group";
public static final String ACTION_POLL_NETWORK_STATS = "action.poll_network_stats";
@@ -83,9 +82,6 @@
case ACTION_SHOW_NOTIFICATION:
doShowNotification();
break;
- case ACTION_CRASH:
- doCrash();
- break;
case ACTION_CREATE_CHANNEL_GROUP:
doCreateChannelGroup();
break;
@@ -193,9 +189,4 @@
finish();
}
}
-
- @SuppressWarnings("ConstantOverflow")
- private void doCrash() {
- Log.e(TAG, "About to crash the app with 1/0 " + (long) 1 / 0);
- }
}
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 f4ab509..6e64a3b 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
@@ -31,6 +31,7 @@
private static final String TAG = StatsdCtsForegroundActivity.class.getSimpleName();
public static final String KEY_ACTION = "action";
+ public static final String ACTION_CRASH = "action.crash";
public static final String ACTION_SHOW_NOTIFICATION = "action.show_notification";
@Override
@@ -50,6 +51,9 @@
case ACTION_SHOW_NOTIFICATION:
doShowNotification();
break;
+ case ACTION_CRASH:
+ doCrash();
+ break;
default:
Log.e(TAG, "Intent had invalid action " + action);
finish();
@@ -76,4 +80,9 @@
nm.cancel(notificationId);
finish();
}
+
+ @SuppressWarnings("ConstantOverflow")
+ private void doCrash() {
+ Log.e(TAG, "About to crash the app with 1/0 " + (long) 1 / 0);
+ }
}
diff --git a/hostsidetests/statsdatom/src/android/cts/statsdatom/statsd/UidAtomTests.java b/hostsidetests/statsdatom/src/android/cts/statsdatom/statsd/UidAtomTests.java
index a137cd7..c39c74a 100644
--- a/hostsidetests/statsdatom/src/android/cts/statsdatom/statsd/UidAtomTests.java
+++ b/hostsidetests/statsdatom/src/android/cts/statsdatom/statsd/UidAtomTests.java
@@ -232,22 +232,27 @@
public void testAppCrashOccurred() throws Exception {
final int atomTag = Atom.APP_CRASH_OCCURRED_FIELD_NUMBER;
- createAndUploadConfig(atomTag, false);
+ StatsdConfig.Builder config = ConfigUtils.createConfigBuilder(
+ DeviceUtils.STATSD_ATOM_TEST_PKG);
+ ConfigUtils.addEventMetricForUidAtom(config, atomTag, /*uidInAttributionChain=*/false,
+ DeviceUtils.STATSD_ATOM_TEST_PKG);
+ ConfigUtils.uploadConfig(getDevice(), config);
Thread.sleep(WAIT_TIME_SHORT);
- runActivity("StatsdCtsForegroundActivity", "action", "action.crash");
+ DeviceUtils.runActivity(getDevice(), DeviceUtils.STATSD_ATOM_TEST_PKG,
+ "StatsdCtsForegroundActivity", "action", "action.crash");
- Thread.sleep(WAIT_TIME_SHORT);
// Sorted list of events in order in which they occurred.
- List<EventMetricData> data = getEventMetricDataList();
+ List<EventMetricData> data = ReportUtils.getEventMetricDataList(getDevice());
+ assertThat(data).hasSize(1);
AppCrashOccurred atom = data.get(0).getAtom().getAppCrashOccurred();
assertThat(atom.getEventType()).isEqualTo("crash");
assertThat(atom.getIsInstantApp().getNumber())
- .isEqualTo(AppCrashOccurred.InstantApp.FALSE_VALUE);
+ .isEqualTo(AppCrashOccurred.InstantApp.FALSE_VALUE);
assertThat(atom.getForegroundState().getNumber())
- .isEqualTo(AppCrashOccurred.ForegroundState.FOREGROUND_VALUE);
- assertThat(atom.getPackageName()).isEqualTo(TEST_PACKAGE_NAME);
+ .isEqualTo(AppCrashOccurred.ForegroundState.FOREGROUND_VALUE);
+ assertThat(atom.getPackageName()).isEqualTo(DeviceUtils.STATSD_ATOM_TEST_PKG);
}
public void testAppStartOccurred() throws Exception {