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

Commit b0a78390 authored by Svetoslav's avatar Svetoslav
Browse files

Add a mechanism to make pending intents immutable.

bug:19618745

Change-Id: Ice742e0162cb9b7c0afbc32e0eea03d501666e2b
parent 682a433d
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -5101,6 +5101,7 @@ package android.app {
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.PendingIntent> CREATOR;
    field public static final android.os.Parcelable.Creator<android.app.PendingIntent> CREATOR;
    field public static final int FLAG_CANCEL_CURRENT = 268435456; // 0x10000000
    field public static final int FLAG_CANCEL_CURRENT = 268435456; // 0x10000000
    field public static final int FLAG_IMMUTABLE = 67108864; // 0x4000000
    field public static final int FLAG_NO_CREATE = 536870912; // 0x20000000
    field public static final int FLAG_NO_CREATE = 536870912; // 0x20000000
    field public static final int FLAG_ONE_SHOT = 1073741824; // 0x40000000
    field public static final int FLAG_ONE_SHOT = 1073741824; // 0x40000000
    field public static final int FLAG_UPDATE_CURRENT = 134217728; // 0x8000000
    field public static final int FLAG_UPDATE_CURRENT = 134217728; // 0x8000000
+1 −0
Original line number Original line Diff line number Diff line
@@ -5192,6 +5192,7 @@ package android.app {
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.PendingIntent> CREATOR;
    field public static final android.os.Parcelable.Creator<android.app.PendingIntent> CREATOR;
    field public static final int FLAG_CANCEL_CURRENT = 268435456; // 0x10000000
    field public static final int FLAG_CANCEL_CURRENT = 268435456; // 0x10000000
    field public static final int FLAG_IMMUTABLE = 67108864; // 0x4000000
    field public static final int FLAG_NO_CREATE = 536870912; // 0x20000000
    field public static final int FLAG_NO_CREATE = 536870912; // 0x20000000
    field public static final int FLAG_ONE_SHOT = 1073741824; // 0x40000000
    field public static final int FLAG_ONE_SHOT = 1073741824; // 0x40000000
    field public static final int FLAG_UPDATE_CURRENT = 134217728; // 0x8000000
    field public static final int FLAG_UPDATE_CURRENT = 134217728; // 0x8000000
+14 −1
Original line number Original line Diff line number Diff line
@@ -150,6 +150,14 @@ public final class PendingIntent implements Parcelable {
     */
     */
    public static final int FLAG_UPDATE_CURRENT = 1<<27;
    public static final int FLAG_UPDATE_CURRENT = 1<<27;


    /**
     * Flag indicating that the created PendingIntent should be immutable.
     * This means that the additional intent argument passed to the send
     * methods to fill in unpopulated properties of this intent will be
     * ignored.
     */
    public static final int FLAG_IMMUTABLE = 1<<26;

    /**
    /**
     * Exception thrown when trying to send through a PendingIntent that
     * Exception thrown when trying to send through a PendingIntent that
     * has been canceled or is otherwise no longer able to execute the request.
     * has been canceled or is otherwise no longer able to execute the request.
@@ -618,7 +626,8 @@ public final class PendingIntent implements Parcelable {
     * @param code Result code to supply back to the PendingIntent's target.
     * @param code Result code to supply back to the PendingIntent's target.
     * @param intent Additional Intent data.  See {@link Intent#fillIn
     * @param intent Additional Intent data.  See {@link Intent#fillIn
     * Intent.fillIn()} for information on how this is applied to the
     * Intent.fillIn()} for information on how this is applied to the
     * original Intent.
     * original Intent. If flag {@link #FLAG_IMMUTABLE} was set when this
     * pending intent was created, this argument will be ignored.
     *
     *
     * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
     * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
     *
     *
@@ -667,6 +676,8 @@ public final class PendingIntent implements Parcelable {
     * @param intent Additional Intent data.  See {@link Intent#fillIn
     * @param intent Additional Intent data.  See {@link Intent#fillIn
     * Intent.fillIn()} for information on how this is applied to the
     * Intent.fillIn()} for information on how this is applied to the
     * original Intent.  Use null to not modify the original Intent.
     * original Intent.  Use null to not modify the original Intent.
     * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
     * created, this argument will be ignored.
     * @param onFinished The object to call back on when the send has
     * @param onFinished The object to call back on when the send has
     * completed, or null for no callback.
     * completed, or null for no callback.
     * @param handler Handler identifying the thread on which the callback
     * @param handler Handler identifying the thread on which the callback
@@ -703,6 +714,8 @@ public final class PendingIntent implements Parcelable {
     * @param intent Additional Intent data.  See {@link Intent#fillIn
     * @param intent Additional Intent data.  See {@link Intent#fillIn
     * Intent.fillIn()} for information on how this is applied to the
     * Intent.fillIn()} for information on how this is applied to the
     * original Intent.  Use null to not modify the original Intent.
     * original Intent.  Use null to not modify the original Intent.
     * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
     * created, this argument will be ignored.
     * @param onFinished The object to call back on when the send has
     * @param onFinished The object to call back on when the send has
     * completed, or null for no callback.
     * completed, or null for no callback.
     * @param handler Handler identifying the thread on which the callback
     * @param handler Handler identifying the thread on which the callback
+7 −4
Original line number Original line Diff line number Diff line
@@ -674,7 +674,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku


    @Override
    @Override
    public IntentSender createAppWidgetConfigIntentSender(String callingPackage, int appWidgetId,
    public IntentSender createAppWidgetConfigIntentSender(String callingPackage, int appWidgetId,
            int intentFlags) {
            final int intentFlags) {
        final int userId = UserHandle.getCallingUserId();
        final int userId = UserHandle.getCallingUserId();


        if (DEBUG) {
        if (DEBUG) {
@@ -701,18 +701,21 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                throw new IllegalArgumentException("Widget not bound " + appWidgetId);
                throw new IllegalArgumentException("Widget not bound " + appWidgetId);
            }
            }


            // Make sure only safe flags can be passed it.
            final int secureFlags = intentFlags & ~Intent.IMMUTABLE_FLAGS;

            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.setComponent(provider.info.configure);
            intent.setComponent(provider.info.configure);
            intent.setFlags(intentFlags);
            intent.setFlags(secureFlags);


            // All right, create the sender.
            // All right, create the sender.
            final long identity = Binder.clearCallingIdentity();
            final long identity = Binder.clearCallingIdentity();
            try {
            try {
                return PendingIntent.getActivityAsUser(
                return PendingIntent.getActivityAsUser(
                        mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
                        mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
                                | PendingIntent.FLAG_CANCEL_CURRENT, null,
                                | PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT,
                                new UserHandle(provider.getUserId()))
                                null, new UserHandle(provider.getUserId()))
                        .getIntentSender();
                        .getIntentSender();
            } finally {
            } finally {
                Binder.restoreCallingIdentity(identity);
                Binder.restoreCallingIdentity(identity);
+13 −6
Original line number Original line Diff line number Diff line
@@ -222,8 +222,12 @@ final class PendingIntentRecord extends IIntentSender.Stub {
                    owner.cancelIntentSenderLocked(this, true);
                    owner.cancelIntentSenderLocked(this, true);
                    canceled = true;
                    canceled = true;
                }
                }

                Intent finalIntent = key.requestIntent != null
                Intent finalIntent = key.requestIntent != null
                        ? new Intent(key.requestIntent) : new Intent();
                        ? new Intent(key.requestIntent) : new Intent();

                final boolean immutable = (key.flags & PendingIntent.FLAG_IMMUTABLE) != 0;
                if (!immutable) {
                    if (intent != null) {
                    if (intent != null) {
                        int changes = finalIntent.fillIn(intent, key.flags);
                        int changes = finalIntent.fillIn(intent, key.flags);
                        if ((changes & Intent.FILL_IN_DATA) == 0) {
                        if ((changes & Intent.FILL_IN_DATA) == 0) {
@@ -235,6 +239,9 @@ final class PendingIntentRecord extends IIntentSender.Stub {
                    flagsMask &= ~Intent.IMMUTABLE_FLAGS;
                    flagsMask &= ~Intent.IMMUTABLE_FLAGS;
                    flagsValues &= flagsMask;
                    flagsValues &= flagsMask;
                    finalIntent.setFlags((finalIntent.getFlags() & ~flagsMask) | flagsValues);
                    finalIntent.setFlags((finalIntent.getFlags() & ~flagsMask) | flagsValues);
                } else {
                    resolvedType = key.requestResolvedType;
                }


                final long origId = Binder.clearCallingIdentity();
                final long origId = Binder.clearCallingIdentity();


Loading