Retry fixed activity launch for any package update

- Even if car is ON, related packages can be updated and fixed activity
  app can be stopped. So try relaunch for any package update.
- Also include a new package install / removal as that may also
  fix existing stopping or crash.

Bug: 170039348
Test: Run the test
      install, remove, update packages and ckeck re-check is running.
Change-Id: I13e6765fddd56c9d459167bc65b6e5b4facb3677
diff --git a/service/src/com/android/car/am/FixedActivityService.java b/service/src/com/android/car/am/FixedActivityService.java
index 5e5454b..81bc470 100644
--- a/service/src/com/android/car/am/FixedActivityService.java
+++ b/service/src/com/android/car/am/FixedActivityService.java
@@ -153,8 +153,9 @@
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
             if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
-                    || Intent.ACTION_PACKAGE_REPLACED.equals(
-                    action)) {
+                    || Intent.ACTION_PACKAGE_REPLACED.equals(action)
+                    || Intent.ACTION_PACKAGE_ADDED.equals(action)
+                    || Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
                 Uri packageData = intent.getData();
                 if (packageData == null) {
                     Log.w(TAG_AM, "null packageData");
@@ -171,15 +172,15 @@
                 synchronized (mLock) {
                     for (int i = 0; i < mRunningActivities.size(); i++) {
                         RunningActivityInfo info = mRunningActivities.valueAt(i);
-                        ComponentName component = info.intent.getComponent();
-                        // should do this for all activities as the same package can cover multiple
-                        // displays.
-                        if (packageName.equals(component.getPackageName())
-                                && info.userId == userId) {
-                            Log.i(TAG_AM, "Package updated:" + packageName
-                                    + ",user:" + userId);
+                        // Should do this for all activities as it can happen for multiple
+                        // displays. Package name is ignored as one package can affect
+                        // others.
+                        if (info.userId == userId) {
+                            Log.i(TAG_AM, "Package changed:" + packageName
+                                    + ",user:" + userId + ",action:" + action);
                             info.resetCrashCounterLocked();
                             tryLaunch = true;
+                            break;
                         }
                     }
                 }
@@ -384,6 +385,8 @@
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
         filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
+        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
         filter.addDataScheme("package");
         mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter,
                 /* broadcastPermission= */ null, /* scheduler= */ null);
diff --git a/tests/carservice_unit_test/src/com/android/car/am/FixedActivityServiceTest.java b/tests/carservice_unit_test/src/com/android/car/am/FixedActivityServiceTest.java
index 9432cae..c3f57ad 100644
--- a/tests/carservice_unit_test/src/com/android/car/am/FixedActivityServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/am/FixedActivityServiceTest.java
@@ -223,7 +223,7 @@
         int appId = 987;
         BroadcastReceiver receiver = receiverCaptor.getValue();
         Intent packageIntent = new Intent(Intent.ACTION_PACKAGE_CHANGED);
-        packageIntent.setData(new Uri.Builder().path(packageName).build());
+        packageIntent.setData(new Uri.Builder().path("Any package").build());
         packageIntent.putExtra(Intent.EXTRA_UID, UserHandle.getUid(userId, appId));
         receiver.onReceive(mContext, packageIntent);
         verify(mContext).startActivityAsUser(eq(intent), any(Bundle.class),