Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2c9c89e authored by Hugh Chen's avatar Hugh Chen
Browse files

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
parent 9873b970
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -38,7 +38,7 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver {
        Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
        Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
        intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
        intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
        PendingIntent pending = PendingIntent.getBroadcast(
        PendingIntent pending = PendingIntent.getBroadcast(
            context, 0, intent, 0);
                context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
        AlarmManager alarmManager =
        AlarmManager alarmManager =
              (AlarmManager) context.getSystemService (Context.ALARM_SERVICE);
              (AlarmManager) context.getSystemService (Context.ALARM_SERVICE);


@@ -47,8 +47,7 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver {
            alarmManager.cancel(pending);
            alarmManager.cancel(pending);
            Log.d(TAG, "setDiscoverableAlarm(): cancel prev alarm");
            Log.d(TAG, "setDiscoverableAlarm(): cancel prev alarm");
        }
        }
        pending = PendingIntent.getBroadcast(
        pending = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
            context, 0, intent, 0);


        alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pending);
        alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pending);
    }
    }
@@ -59,7 +58,7 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver {
        Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
        Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
        intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
        intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
        PendingIntent pending = PendingIntent.getBroadcast(
        PendingIntent pending = PendingIntent.getBroadcast(
            context, 0, intent, PendingIntent.FLAG_NO_CREATE);
                context, 0, intent, PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE);
        if (pending != null) {
        if (pending != null) {
            // Cancel any previous alarms that do the same thing.
            // Cancel any previous alarms that do the same thing.
            AlarmManager alarmManager =
            AlarmManager alarmManager =