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

Commit c6151f23 authored by Adam Cohen's avatar Adam Cohen
Browse files

Handle null PendingIntents, Bitmaps, Uris and Intents in RemoteViews (issue 5223291)

Change-Id: If8895b774dee6ba4138751a0c2f68c70402b3fa5
parent 12df3cf1
Loading
Loading
Loading
Loading
+65 −31
Original line number Diff line number Diff line
@@ -427,14 +427,23 @@ public class RemoteViews implements Parcelable, Filter {

        public SetOnClickPendingIntent(Parcel parcel) {
            viewId = parcel.readInt();

            // We check a flag to determine if the parcel contains a PendingIntent.
            if (parcel.readInt() != 0) {
                pendingIntent = PendingIntent.readPendingIntentOrNullFromParcel(parcel);
            }
        }

        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(TAG);
            dest.writeInt(viewId);

            // We use a flag to indicate whether the parcel contains a valid object.
            dest.writeInt(pendingIntent != null ? 1 : 0);
            if (pendingIntent != null) {
                pendingIntent.writeToParcel(dest, 0 /* no flags */);
            }
        }

        @Override
        public void apply(View root, ViewGroup rootParent) {
@@ -449,8 +458,11 @@ public class RemoteViews implements Parcelable, Filter {
                // TODO: return; We'll let this slide until apps are up to date.
            }

            if (target != null && pendingIntent != null) {
                OnClickListener listener = new OnClickListener() {
            if (target != null) {
                // If the pendingIntent is null, we clear the onClickListener
                OnClickListener listener = null;
                if (pendingIntent != null) {
                    listener = new OnClickListener() {
                        public void onClick(View v) {
                            // Find target view location in screen coordinates and
                            // fill into PendingIntent before sending.
@@ -470,6 +482,7 @@ public class RemoteViews implements Parcelable, Filter {
                            startIntentSafely(v.getContext(), pendingIntent, intent);
                        }
                    };
                }
                target.setOnClickListener(listener);
            }
        }
@@ -667,6 +680,9 @@ public class RemoteViews implements Parcelable, Filter {
                Log.d("RemoteViews", "read viewId=0x" + Integer.toHexString(this.viewId)
                        + " methodName=" + this.methodName + " type=" + this.type);
            }

            // For some values that may have been null, we first check a flag to see if they were
            // written to the parcel.
            switch (this.type) {
                case BOOLEAN:
                    this.value = in.readInt() != 0;
@@ -699,16 +715,22 @@ public class RemoteViews implements Parcelable, Filter {
                    this.value = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
                    break;
                case URI:
                    if (in.readInt() != 0) {
                        this.value = Uri.CREATOR.createFromParcel(in);
                    }
                    break;
                case BITMAP:
                    if (in.readInt() != 0) {
                        this.value = Bitmap.CREATOR.createFromParcel(in);
                    }
                    break;
                case BUNDLE:
                    this.value = in.readBundle();
                    break;
                case INTENT:
                    if (in.readInt() != 0) {
                        this.value = Intent.CREATOR.createFromParcel(in);
                    }
                    break;
                default:
                    break;
@@ -725,6 +747,9 @@ public class RemoteViews implements Parcelable, Filter {
                Log.d("RemoteViews", "write viewId=0x" + Integer.toHexString(this.viewId)
                        + " methodName=" + this.methodName + " type=" + this.type);
            }

            // For some values which are null, we record an integer flag to indicate whether
            // we have written a valid value to the parcel.
            switch (this.type) {
                case BOOLEAN:
                    out.writeInt((Boolean) this.value ? 1 : 0);
@@ -757,16 +782,25 @@ public class RemoteViews implements Parcelable, Filter {
                    TextUtils.writeToParcel((CharSequence)this.value, out, flags);   
                    break;
                case URI:
                    out.writeInt(this.value != null ? 1 : 0);
                    if (this.value != null) {
                        ((Uri)this.value).writeToParcel(out, flags);
                    }
                    break;
                case BITMAP:
                    out.writeInt(this.value != null ? 1 : 0);
                    if (this.value != null) {
                        ((Bitmap)this.value).writeToParcel(out, flags);
                    }
                    break;
                case BUNDLE:
                    out.writeBundle((Bundle) this.value);
                    break;
                case INTENT:
                    out.writeInt(this.value != null ? 1 : 0);
                    if (this.value != null) {
                        ((Intent)this.value).writeToParcel(out, flags);
                    }
                    break;
                default:
                    break;