Open activities from notif actions properly

Previously, because the action's PendingIntent was not directly
starting the Activity, the notification shade would remain open. The
Activity was being opened, but it was hidden and this was poor UX.

Non-resolving actions don't need to be routed via the
SafetyCenterNotificationReceiver because they do not have the same
requirements as resolving actions (timeouts, setting "in-flight",
etc.)

The down-side of this approach is that we will lose the ability to log
an event when this kind of non-resolving action is clicked.

Bug: 266561097
Change-Id: I1bee46dd71f6d59033b611f4f83788499d61de52
diff --git a/service/java/com/android/safetycenter/SafetyCenterNotificationFactory.java b/service/java/com/android/safetycenter/SafetyCenterNotificationFactory.java
index edf6189..7c11660 100644
--- a/service/java/com/android/safetycenter/SafetyCenterNotificationFactory.java
+++ b/service/java/com/android/safetycenter/SafetyCenterNotificationFactory.java
@@ -54,11 +54,15 @@
 
     private final Context mContext;
     private final SafetyCenterNotificationChannels mNotificationChannels;
+    private final PendingIntentFactory mPendingIntentFactory;
 
     SafetyCenterNotificationFactory(
-            Context context, SafetyCenterNotificationChannels notificationChannels) {
+            Context context,
+            SafetyCenterNotificationChannels notificationChannels,
+            PendingIntentFactory pendingIntentFactory) {
         mContext = context;
         mNotificationChannels = notificationChannels;
+        mPendingIntentFactory = pendingIntentFactory;
     }
 
     /**
@@ -136,6 +140,21 @@
 
     private Notification.Action toNotificationAction(
             SafetyCenterIssueKey issueKey, SafetySourceIssue.Action issueAction) {
+        PendingIntent pendingIntent = getPendingIntentForAction(issueKey, issueAction);
+        return new Notification.Action.Builder(null, issueAction.getLabel(), pendingIntent).build();
+    }
+
+    private PendingIntent getPendingIntentForAction(
+            SafetyCenterIssueKey issueKey, SafetySourceIssue.Action issueAction) {
+        if (issueAction.willResolve()) {
+            return getReceiverPendingIntentForResolvingAction(issueKey, issueAction);
+        } else {
+            return getDirectPendingIntentForNonResolvingAction(issueKey, issueAction);
+        }
+    }
+
+    private PendingIntent getReceiverPendingIntentForResolvingAction(
+            SafetyCenterIssueKey issueKey, SafetySourceIssue.Action issueAction) {
         // We do not use the action's PendingIntent directly here instead we build a new PI which
         // will be handled by our SafetyCenterNotificationReceiver which will in turn dispatch
         // the source-provided action PI. This ensures that action execution is consistent across
@@ -146,10 +165,13 @@
                         .setSafetyCenterIssueKey(issueKey)
                         .setSafetySourceIssueActionId(issueAction.getId())
                         .build();
-        PendingIntent receiverPendingIntent =
-                SafetyCenterNotificationReceiver.newNotificationActionClickedIntent(
-                        mContext, issueActionId);
-        return new Notification.Action.Builder(null, issueAction.getLabel(), receiverPendingIntent)
-                .build();
+        return SafetyCenterNotificationReceiver.newNotificationActionClickedIntent(
+                mContext, issueActionId);
+    }
+
+    private PendingIntent getDirectPendingIntentForNonResolvingAction(
+            SafetyCenterIssueKey issueKey, SafetySourceIssue.Action issueAction) {
+        return mPendingIntentFactory.maybeOverridePendingIntent(
+                issueKey.getSafetySourceId(), issueAction.getPendingIntent(), false);
     }
 }
diff --git a/service/java/com/android/safetycenter/SafetyCenterService.java b/service/java/com/android/safetycenter/SafetyCenterService.java
index 109a6b7..4abbc19 100644
--- a/service/java/com/android/safetycenter/SafetyCenterService.java
+++ b/service/java/com/android/safetycenter/SafetyCenterService.java
@@ -172,8 +172,8 @@
                         context,
                         new SafetyCenterNotificationFactory(
                                 context,
-                                new SafetyCenterNotificationChannels(
-                                        mSafetyCenterResourcesContext)),
+                                new SafetyCenterNotificationChannels(mSafetyCenterResourcesContext),
+                                mPendingIntentFactory),
                         mSafetyCenterDataManager);
         mSafetyCenterBroadcastDispatcher =
                 new SafetyCenterBroadcastDispatcher(