From 3fd1264acbb93c83cb34175d5cdb32be68d3ca83 Mon Sep 17 00:00:00 2001 From: Jordan Liu Date: Mon, 9 Dec 2019 13:45:07 -0800 Subject: [PATCH] Do not modify passed in intent If the caller wanted to use that intent object after passing it to this method, it would be mutated in an unexpected way. Instead we create a copy of the intent and broadcast that. Bug: 144108192 Test: atest com.android.internal.telephony.CellBroadcastIntentsTest Change-Id: I89e08b4a50beeb49410521baa9d449b2dc28ecd3 Merged-In: I89e08b4a50beeb49410521baa9d449b2dc28ecd3 --- .../android/telephony/CellBroadcastIntents.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/java/android/telephony/CellBroadcastIntents.java b/core/java/android/telephony/CellBroadcastIntents.java index 4474f3ecc620a..8446253c63026 100644 --- a/core/java/android/telephony/CellBroadcastIntents.java +++ b/core/java/android/telephony/CellBroadcastIntents.java @@ -26,7 +26,6 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Handler; import android.os.UserHandle; -import android.util.Log; /** * A static helper class used to send Intents with prepopulated flags. @@ -75,20 +74,20 @@ public class CellBroadcastIntents { @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) { - Log.d(LOG_TAG, "sendOrderedBroadcastForBackgroundReceivers intent=" + intent.getAction()); int status = context.checkCallingOrSelfPermission( "android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS"); if (status == PackageManager.PERMISSION_DENIED) { throw new SecurityException( "Caller does not have permission to send broadcast for background receivers"); } - intent.setFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); + Intent backgroundIntent = new Intent(intent); + backgroundIntent.setFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); if (user != null) { - context.createContextAsUser(user, 0).sendOrderedBroadcast(intent, receiverPermission, - receiverAppOp, resultReceiver, scheduler, initialCode, initialData, - initialExtras); + context.createContextAsUser(user, 0).sendOrderedBroadcast(backgroundIntent, + receiverPermission, receiverAppOp, resultReceiver, scheduler, initialCode, + initialData, initialExtras); } else { - context.sendOrderedBroadcast(intent, receiverPermission, + context.sendOrderedBroadcast(backgroundIntent, receiverPermission, receiverAppOp, resultReceiver, scheduler, initialCode, initialData, initialExtras); }