Relax the PI mutability flag requirement for apps under instrumentation
This gives us some buffer time to help transition all the test apps. See go/immutable-pendingintents for more context. Bug: 160794467 Test: TH Change-Id: I2265dc8a5e86ac76e615e659169f8891e8a7ed75
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
throw new IllegalArgumentException(msg);
|
||||
if (!mInstrumentation.isInstrumenting()) {
|
||||
throw new IllegalArgumentException(msg);
|
||||
} else {
|
||||
Log.e(TAG, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user