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

Commit 4469d60c authored by Ashwini Oruganti's avatar Ashwini Oruganti Committed by Android (Google) Code Review
Browse files

Merge "Relax the PI mutability flag requirement for apps under instrumentation"

parents aca88329 6fa883e1
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -138,6 +138,20 @@ public class Instrumentation {
        }
    }

    /**
     * Returns if it is being called in an instrumentation environment.
     *
     * @hide
     */
    public boolean isInstrumenting() {
        // Check if we have an instrumentation context, as init should only get called by
        // the system in startup processes that are being instrumented.
        if (mInstrContext == null) {
            return false;
        }
        return true;
    }

    /**
     * Called when the instrumentation is starting, before any application code
     * has been loaded.  Usually this will be implemented to simply call
+12 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.util.AndroidException;
import android.util.ArraySet;
import android.util.Log;
import android.util.proto.ProtoOutputStream;

import com.android.internal.os.IResultReceiver;
@@ -107,6 +108,7 @@ import java.lang.annotation.RetentionPolicy;
 * FLAG_ONE_SHOT, <b>both</b> FLAG_ONE_SHOT and FLAG_NO_CREATE need to be supplied.
 */
public final class PendingIntent implements Parcelable {
    private static final String TAG = "PendingIntent";
    private final IIntentSender mTarget;
    private IResultReceiver mCancelReceiver;
    private IBinder mWhitelistToken;
@@ -350,9 +352,18 @@ public final class PendingIntent implements Parcelable {
                "Cannot set both FLAG_IMMUTABLE and FLAG_MUTABLE for PendingIntent");
        }

        // TODO(b/178092897) Remove the below instrumentation check and enforce
        // the explicit mutability requirement for apps under instrumentation.
        ActivityThread thread = ActivityThread.currentActivityThread();
        Instrumentation mInstrumentation = thread.getInstrumentation();

        if (Compatibility.isChangeEnabled(PENDING_INTENT_EXPLICIT_MUTABILITY_REQUIRED)
                && !flagImmutableSet && !flagMutableSet) {
            if (!mInstrumentation.isInstrumenting()) {
                throw new IllegalArgumentException(msg);
            } else {
                Log.e(TAG, msg);
            }
        }
    }