Reduce flakiness of testForceStopPackageWontRestartProcess

Other tests may not clean up the launched activity. If there is
an activity record of the same package without process (died in
background), when force-stopping the package, the null process
cannot match the current died process to clear the activity. And
because resume-top will be executed when a visible activity is died,
that leads to restart the process of the previous dead activity.

Bug: 160236531
Test: atest CtsAppTestCases: \
      ActivityManagerTest#testForceStopPackageWontRestartProcess
Change-Id: Id4a4492c1e8d39e2518e30a81118aed6c6fb7635
diff --git a/tests/app/src/android/app/cts/ActivityManagerTest.java b/tests/app/src/android/app/cts/ActivityManagerTest.java
index 1be2930..22884fd 100644
--- a/tests/app/src/android/app/cts/ActivityManagerTest.java
+++ b/tests/app/src/android/app/cts/ActivityManagerTest.java
@@ -706,6 +706,9 @@
      * activities, the process of the package should not be alive (restarted).
      */
     public void testForceStopPackageWontRestartProcess() throws Exception {
+        // Ensure that there are no remaining component records of the test app package.
+        SystemUtil.runWithShellPermissionIdentity(
+                () -> mActivityManager.forceStopPackage(SIMPLE_PACKAGE_NAME));
         ActivityReceiverFilter appStartedReceiver = new ActivityReceiverFilter(
                 ACTIVITY_LAUNCHED_ACTION);
         // Start an activity of another APK.