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
This commit is contained in:
Jordan Liu
2019-12-09 13:45:07 -08:00
parent d0f439c43b
commit 3fd1264acb

View File

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