From 361020dfdcd71c4deb0d429ee8872013f74cc223 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Wed, 26 Jun 2024 08:54:21 +0000 Subject: [PATCH] Allow the background activity start from legacy suggestion cards There's a restriction on starting activities from PendingIntents. Opt-in required when starting activities from PendingIntents. (https://goo.gle/android-bal#opt-in-required) Bug: 346690654 Change-Id: I0525ebe5a49e7a7f5b07236e01cd3ababce1da4d Test: manual --- .../LegacySuggestionContextualCardController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java index b0061fa8557..122cb6df179 100644 --- a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java +++ b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java @@ -16,6 +16,7 @@ package com.android.settings.homepage.contextualcards.legacysuggestion; +import android.app.ActivityOptions; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; @@ -79,7 +80,10 @@ public class LegacySuggestionContextualCardController implements ContextualCardC @Override public void onPrimaryClick(ContextualCard card) { try { - ((LegacySuggestionContextualCard) card).getPendingIntent().send(); + ActivityOptions options = ActivityOptions.makeBasic() + .setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); + ((LegacySuggestionContextualCard) card).getPendingIntent().send(options.toBundle()); } catch (PendingIntent.CanceledException e) { Log.w(TAG, "Failed to start suggestion " + card.getTitleText()); }