Ensure force-stopped process do not start again during cleanup

By setting all activities of the removed process as finishing,
those activities haven’t been removed won't be the candidate of
top or visible activity.

Also adjust the conditions to set ProcessRecord.removed to fit the
original meaning a bit. That should be used to indicate the process
is killed for the change of package state. Now ProcessRecord.removed
will only be set when force-stop or crash too many times.

Fixes: 114117787
Fixes: 37070733
Test: atest ActivityManagerTest#testForceStopPackageWontRestartProcess
Test: atest ActivityStackTests

Change-Id: Ia2975c2e4ece8600307b317f124354ecdca55d31
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 054c830..8d8cf1e 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -264,7 +264,9 @@
     boolean forceCrashReport;   // suppress normal auto-dismiss of crash dialog & report UI?
     private boolean mNotResponding; // does the app have a not responding dialog?
     Dialog anrDialog;           // dialog being displayed due to app not resp.
-    boolean removed;            // has app package been removed from device?
+    volatile boolean removed;   // Whether this process should be killed and removed from process
+                                // list. It is set when the package is force-stopped or the process
+                                // has crashed too many times.
     private boolean mDebugging; // was app launched for debugging?
     boolean waitedForDebugger;  // has process show wait for debugger dialog?
     Dialog waitDialog;          // current wait for debugger dialog
@@ -1228,10 +1230,8 @@
     }
 
     @Override
-    public void setRemoved(boolean removed) {
-        synchronized (mService) {
-            this.removed = removed;
-        }
+    public boolean isRemoved() {
+        return removed;
     }
 
     /**