[Safer intents] Notifications

To avoid implicit intents, make intents launch explicitly.

Test: build
Bug: 323061508
Change-Id: I68624ca7c913c473490f371409ae35acbb4f6fb2
This commit is contained in:
Jason Chiu
2024-03-25 15:12:09 +08:00
parent 37f992aecc
commit 8bc1a141b5
11 changed files with 25 additions and 7 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -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());

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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.setPackage(contactsPackage);
mFallbackIntent.addCategory(Intent.CATEGORY_APP_CONTACTS);
mFallbackIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

View File

@@ -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();