From 8bc1a141b597df4ef8ba7e479efb86c8dfcea35d Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Mon, 25 Mar 2024 15:12:09 +0800 Subject: [PATCH] [Safer intents] Notifications To avoid implicit intents, make intents launch explicitly. Test: build Bug: 323061508 Change-Id: I68624ca7c913c473490f371409ae35acbb4f6fb2 --- .../app/BubbleCategoryPreferenceController.java | 1 + .../notification/app/BubbleLinkPreferenceController.java | 1 + .../notification/app/BubbleSummaryPreferenceController.java | 1 + .../notification/history/NotificationHistoryAdapter.java | 2 ++ .../notification/history/NotificationSbnAdapter.java | 1 + .../settings/notification/history/NotificationStation.java | 1 + .../AbstractZenModeAutomaticRulePreferenceController.java | 5 ++--- .../settings/notification/zen/ZenOnboardingActivity.java | 3 ++- .../settings/notification/zen/ZenPrioritySendersHelper.java | 5 +++++ .../zen/ZenRuleStarredContactsPreferenceController.java | 6 +++++- .../settings/notification/zen/ZenSuggestionActivity.java | 6 ++++-- 11 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java index 37baf8b7c38..13c4155595a 100644 --- a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java @@ -56,6 +56,7 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo if (mAppRow != null) { final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); + intent.setPackage(mContext.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, mAppRow.pkg); intent.putExtra(Settings.EXTRA_APP_UID, mAppRow.uid); preference.setIntent(intent); diff --git a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java index fcabe9b87af..9d954ce19a7 100644 --- a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java @@ -56,6 +56,7 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro if (mAppRow != null) { final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); + intent.setPackage(mContext.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, mAppRow.pkg); intent.putExtra(Settings.EXTRA_APP_UID, mAppRow.uid); preference.setIntent(intent); diff --git a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java index 888bd25c770..8c22f926e9b 100644 --- a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java @@ -77,6 +77,7 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon if (mAppRow != null) { final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); + intent.setPackage(mContext.getPackageName()); intent.putExtra(Settings.EXTRA_APP_PACKAGE, mAppRow.pkg); intent.putExtra(Settings.EXTRA_APP_UID, mAppRow.uid); preference.setIntent(intent); diff --git a/src/com/android/settings/notification/history/NotificationHistoryAdapter.java b/src/com/android/settings/notification/history/NotificationHistoryAdapter.java index 96bc14a6fb2..5368f25e76e 100644 --- a/src/com/android/settings/notification/history/NotificationHistoryAdapter.java +++ b/src/com/android/settings/notification/history/NotificationHistoryAdapter.java @@ -38,6 +38,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.internal.logging.UiEventLogger; import com.android.settings.R; +import com.android.settings.Utils; import java.util.ArrayList; import java.util.List; @@ -87,6 +88,7 @@ public class NotificationHistoryAdapter extends mUiEventLogger.logWithPosition(NotificationHistoryActivity.NotificationHistoryEvent .NOTIFICATION_HISTORY_OLDER_ITEM_CLICK, hn.getUid(), hn.getPackage(), position); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .setPackage(Utils.SETTINGS_PACKAGE_NAME) .putExtra(EXTRA_APP_PACKAGE, hn.getPackage()) .putExtra(EXTRA_CHANNEL_ID, hn.getChannelId()) .putExtra(EXTRA_CONVERSATION_ID, hn.getConversationId()); diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java index c556b55179e..0301d7b7fd5 100644 --- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java +++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java @@ -130,6 +130,7 @@ public class NotificationSbnAdapter extends mUiEventLogger); holder.itemView.setOnLongClickListener(v -> { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .setPackage(mContext.getPackageName()) .putExtra(EXTRA_APP_PACKAGE, sbn.getPackageName()) .putExtra(EXTRA_CHANNEL_ID, sbn.getNotification().getChannelId()) .putExtra(EXTRA_CONVERSATION_ID, sbn.getNotification().getShortcutId()); diff --git a/src/com/android/settings/notification/history/NotificationStation.java b/src/com/android/settings/notification/history/NotificationStation.java index 3b27e1947d2..e79a4ac58c6 100644 --- a/src/com/android/settings/notification/history/NotificationStation.java +++ b/src/com/android/settings/notification/history/NotificationStation.java @@ -751,6 +751,7 @@ public class NotificationStation extends SettingsPreferenceFragment { @Override public void performClick() { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .setPackage(mContext.getPackageName()) .putExtra(EXTRA_APP_PACKAGE, mInfo.pkg) .putExtra(EXTRA_CHANNEL_ID, mInfo.channel != null ? mInfo.channel.getId() : mInfo.channelId); diff --git a/src/com/android/settings/notification/zen/AbstractZenModeAutomaticRulePreferenceController.java b/src/com/android/settings/notification/zen/AbstractZenModeAutomaticRulePreferenceController.java index e8d132998ad..7f3567277b9 100644 --- a/src/com/android/settings/notification/zen/AbstractZenModeAutomaticRulePreferenceController.java +++ b/src/com/android/settings/notification/zen/AbstractZenModeAutomaticRulePreferenceController.java @@ -28,20 +28,18 @@ import android.content.pm.ActivityInfo; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; -import android.os.Binder; import android.provider.Settings; import android.service.notification.ConditionProviderService; import android.util.Log; -import android.util.Slog; import androidx.fragment.app.Fragment; import androidx.preference.Preference; +import com.android.settings.Utils; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.lifecycle.Lifecycle; import java.util.Map; -import java.util.Objects; abstract public class AbstractZenModeAutomaticRulePreferenceController extends AbstractZenModePreferenceController implements PreferenceControllerMixin { @@ -85,6 +83,7 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends intent.setComponent(configurationActivity); } else { intent.setAction(settingsAction); + intent.setPackage(Utils.SETTINGS_PACKAGE_NAME); } return intent; } diff --git a/src/com/android/settings/notification/zen/ZenOnboardingActivity.java b/src/com/android/settings/notification/zen/ZenOnboardingActivity.java index a6e78eb2068..151341cc4e8 100644 --- a/src/com/android/settings/notification/zen/ZenOnboardingActivity.java +++ b/src/com/android/settings/notification/zen/ZenOnboardingActivity.java @@ -116,7 +116,8 @@ public class ZenOnboardingActivity extends Activity { public void launchSettings(View button) { mMetrics.action(SettingsEnums.ACTION_ZEN_ONBOARDING_SETTINGS); - Intent settings = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS); + Intent settings = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS) + .setPackage(getPackageName()); settings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(settings); } diff --git a/src/com/android/settings/notification/zen/ZenPrioritySendersHelper.java b/src/com/android/settings/notification/zen/ZenPrioritySendersHelper.java index 5d0b71b7643..1280a221788 100644 --- a/src/com/android/settings/notification/zen/ZenPrioritySendersHelper.java +++ b/src/com/android/settings/notification/zen/ZenPrioritySendersHelper.java @@ -95,6 +95,11 @@ public class ZenPrioritySendersHelper { mNotificationBackend = notificationBackend; mSelectorClickListener = clickListener; + String contactsPackage = context.getString(R.string.config_contacts_package_name); + ALL_CONTACTS_INTENT.setPackage(contactsPackage); + STARRED_CONTACTS_INTENT.setPackage(contactsPackage); + FALLBACK_INTENT.setPackage(contactsPackage); + mPackageManager = mContext.getPackageManager(); if (!FALLBACK_INTENT.hasCategory(Intent.CATEGORY_APP_CONTACTS)) { FALLBACK_INTENT.addCategory(Intent.CATEGORY_APP_CONTACTS); diff --git a/src/com/android/settings/notification/zen/ZenRuleStarredContactsPreferenceController.java b/src/com/android/settings/notification/zen/ZenRuleStarredContactsPreferenceController.java index 3ac66337eb4..729c5b95518 100644 --- a/src/com/android/settings/notification/zen/ZenRuleStarredContactsPreferenceController.java +++ b/src/com/android/settings/notification/zen/ZenRuleStarredContactsPreferenceController.java @@ -25,6 +25,7 @@ import android.service.notification.ZenPolicy; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; +import com.android.settings.R; import com.android.settingslib.core.lifecycle.Lifecycle; public class ZenRuleStarredContactsPreferenceController extends @@ -43,10 +44,13 @@ public class ZenRuleStarredContactsPreferenceController extends mPriorityCategory = priorityCategory; mPackageManager = mContext.getPackageManager(); + String contactsPackage = context.getString(R.string.config_contacts_package_name); mStarredContactsIntent = new Intent(Contacts.Intents.UI.LIST_STARRED_ACTION) + .setPackage(contactsPackage) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - mFallbackIntent = new Intent(Intent.ACTION_MAIN); + mFallbackIntent = new Intent(Intent.ACTION_MAIN); + mFallbackIntent.setPackage(contactsPackage); mFallbackIntent.addCategory(Intent.CATEGORY_APP_CONTACTS); mFallbackIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); } diff --git a/src/com/android/settings/notification/zen/ZenSuggestionActivity.java b/src/com/android/settings/notification/zen/ZenSuggestionActivity.java index 728b1717f06..b535a3e900e 100644 --- a/src/com/android/settings/notification/zen/ZenSuggestionActivity.java +++ b/src/com/android/settings/notification/zen/ZenSuggestionActivity.java @@ -12,11 +12,13 @@ public class ZenSuggestionActivity extends Activity { super.onCreate(savedInstanceState); // start up zen settings activity - Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS); + Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS) + .setPackage(getPackageName()); startActivity(settingsIntent); // start up onboarding activity - Intent onboardingActivity = new Intent(Settings.ZEN_MODE_ONBOARDING); + Intent onboardingActivity = new Intent(Settings.ZEN_MODE_ONBOARDING) + .setPackage(getPackageName()); startActivity(onboardingActivity); finish();