Don't cancel PendingIntents unless the stay_stopped flag is on.

This change should be accompanied by other enhancements needed
to harden the stopped state. So, only cancel PendingIntents for
stopped apps when the flag is enabled.

Bug: 332922400
Test: atest tests/app/src/android/app/cts/ForceStopTest.java
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:63d699245f19338d63f320d2b80b4a3bcbd7ae21)
Merged-In: I186f43ca0736072ab8f235e448deff304dda84cb
Change-Id: I186f43ca0736072ab8f235e448deff304dda84cb
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 663ba8a..7f5a865 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -4451,7 +4451,9 @@
             }
         }
 
-        if (packageName == null || uninstalling || packageStateStopped) {
+        final boolean clearPendingIntentsForStoppedApp = (android.content.pm.Flags.stayStopped()
+                && packageStateStopped);
+        if (packageName == null || uninstalling || clearPendingIntentsForStoppedApp) {
             didSomething |= mPendingIntentController.removePendingIntentsForPackage(
                     packageName, userId, appId, doit);
         }