From d2c9c89e8cba79026645b77844a21862d637d8ff Mon Sep 17 00:00:00 2001 From: Hugh Chen Date: Mon, 9 Nov 2020 17:20:07 +0800 Subject: [PATCH] Add the explicitly mutable flag for creating a PendingIntent - Android S+ to specify explicitly either FLAG_MUTABLE or FLAG_IMMUTABLE when creating a PendingIntent. - Suggest to use the FLAG_IMMUTABLE as default. Change it to FLAG_MUTABLE while errors occur. Bug: 172415655 Test: build pass, manual test to start/remove discoverable timeout Change-Id: I94e26c44eb8aebb8d9a67b9d29e6bbac768a40e7 --- .../bluetooth/BluetoothDiscoverableTimeoutReceiver.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDiscoverableTimeoutReceiver.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDiscoverableTimeoutReceiver.java index 9ea7a4af8d128..6ce72bbc6909d 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDiscoverableTimeoutReceiver.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDiscoverableTimeoutReceiver.java @@ -38,7 +38,7 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver { Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT); intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class); PendingIntent pending = PendingIntent.getBroadcast( - context, 0, intent, 0); + context, 0, intent, PendingIntent.FLAG_IMMUTABLE); AlarmManager alarmManager = (AlarmManager) context.getSystemService (Context.ALARM_SERVICE); @@ -47,8 +47,7 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver { alarmManager.cancel(pending); Log.d(TAG, "setDiscoverableAlarm(): cancel prev alarm"); } - pending = PendingIntent.getBroadcast( - context, 0, intent, 0); + pending = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pending); } @@ -59,7 +58,7 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver { Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT); intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class); PendingIntent pending = PendingIntent.getBroadcast( - context, 0, intent, PendingIntent.FLAG_NO_CREATE); + context, 0, intent, PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE); if (pending != null) { // Cancel any previous alarms that do the same thing. AlarmManager alarmManager =