From 7b20a8f6c7ffe261ce980fecda717a86b37f62bb Mon Sep 17 00:00:00 2001 From: Ashwini Oruganti Date: Fri, 13 Nov 2020 13:40:29 -0800 Subject: [PATCH] StorageNotification.java: Apply FLAG_IMMUTABLE to various PIs An explicit mutability flag is soon going to be required for any created PendingIntent. go/immutable-pendingintents has context on this new requirement. In this commit it seems reasonable to apply FLAG_IMMUTABLE to these PIs for the following cases: -- Simple notification content clicks are immutable; there's no need to communicate customized data back to the creator -- Simple notification action clicks are immutable; there's no need to communicate customized data back to the creator Bug: 173158147 Test: TH Change-Id: I0525c067a3f18ae72edb52767b7d6807f2318444 --- .../systemui/usb/StorageNotification.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java index b36b53125f2f4..570202845e869 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java +++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java @@ -631,7 +631,8 @@ public class StorageNotification extends SystemUI { final int requestKey = disk.getId().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private PendingIntent buildInitPendingIntent(VolumeInfo vol) { @@ -650,7 +651,8 @@ public class StorageNotification extends SystemUI { final int requestKey = vol.getId().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) { @@ -662,7 +664,8 @@ public class StorageNotification extends SystemUI { final int requestKey = vol.getId().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } else if (isAutomotive()) { intent.setClassName("com.android.car.settings", "com.android.car.settings.storage.StorageUnmountReceiver"); @@ -670,7 +673,8 @@ public class StorageNotification extends SystemUI { final int requestKey = vol.getId().hashCode(); return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + UserHandle.CURRENT); } else { intent.setClassName("com.android.settings", "com.android.settings.deviceinfo.StorageUnmountReceiver"); @@ -678,7 +682,8 @@ public class StorageNotification extends SystemUI { final int requestKey = vol.getId().hashCode(); return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + UserHandle.CURRENT); } } @@ -689,7 +694,8 @@ public class StorageNotification extends SystemUI { final int requestKey = vol.getId().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } finally { StrictMode.setVmPolicy(oldPolicy); } @@ -721,7 +727,8 @@ public class StorageNotification extends SystemUI { final int requestKey = vol.getId().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private PendingIntent buildSnoozeIntent(String fsUuid) { @@ -730,7 +737,8 @@ public class StorageNotification extends SystemUI { final int requestKey = fsUuid.hashCode(); return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + UserHandle.CURRENT); } private PendingIntent buildForgetPendingIntent(VolumeRecord rec) { @@ -742,7 +750,8 @@ public class StorageNotification extends SystemUI { final int requestKey = rec.getFsUuid().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private PendingIntent buildWizardMigratePendingIntent(MoveInfo move) { @@ -764,7 +773,8 @@ public class StorageNotification extends SystemUI { intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId()); } return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private PendingIntent buildWizardMovePendingIntent(MoveInfo move) { @@ -782,7 +792,8 @@ public class StorageNotification extends SystemUI { intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId); return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private PendingIntent buildWizardReadyPendingIntent(DiskInfo disk) { @@ -801,7 +812,8 @@ public class StorageNotification extends SystemUI { final int requestKey = disk.getId().hashCode(); return PendingIntent.getActivityAsUser(mContext, requestKey, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, + null, UserHandle.CURRENT); } private boolean isAutomotive() {