Block creation of mutable implicit PendingIntent

After auditing and migrating all usages within the platform
(go/mutable-pis), convert Slog.wtfStack() to IllegalArgumentException().

ag/20580416 is the initial CL that introduced this feature.

Bug: 236704164
Bug: 229362273
Bug: 262253127
Test: atest PendingIntentTest
Change-Id: Ie33d850548520c9d887a562ab8f46b5793c65033
This commit is contained in:
Azhara Assanova
2023-01-18 12:30:11 +00:00
parent fb92f4386a
commit ad9eb760c8

View File

@@ -57,7 +57,6 @@ import android.util.AndroidException;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.GuardedBy;
@@ -430,10 +429,9 @@ public final class PendingIntent implements Parcelable {
}
// Whenever creation or retrieval of a mutable implicit PendingIntent occurs:
// - For apps with target SDK >= U, Log.wtfStack() that it is blocked for security reasons.
// This will be changed to a throw of an exception on the server side once we finish
// migrating to safer PendingIntents b/262253127.
// - Otherwise, warn that it will be blocked from target SDK U.
// - For apps with target SDK >= U, throw an IllegalArgumentException for
// security reasons.
// - Otherwise, warn that it will be blocked from target SDK U onwards.
if (isNewMutableDisallowedImplicitPendingIntent(flags, intent)) {
if (Compatibility.isChangeEnabled(BLOCK_MUTABLE_IMPLICIT_PENDING_INTENT)) {
String msg = packageName + ": Targeting U+ (version "
@@ -445,7 +443,7 @@ public final class PendingIntent implements Parcelable {
+ " PendingIntent, use FLAG_NO_CREATE, however, to create a"
+ " new PendingIntent with an implicit Intent use"
+ " FLAG_IMMUTABLE.";
Slog.wtfStack(TAG, msg);
throw new IllegalArgumentException(msg);
} else {
String msg = "New mutable implicit PendingIntent: pkg=" + packageName
+ ", action=" + intent.getAction()