Search in sources :

Example 11 with BadParcelableException

use of android.os.BadParcelableException in project android_frameworks_base by ResurrectionRemix.

the class Notification method cloneInto.

/**
     * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members
     * of this into that.
     * @hide
     */
public void cloneInto(Notification that, boolean heavy) {
    that.when = this.when;
    that.creationTime = this.creationTime;
    that.mSmallIcon = this.mSmallIcon;
    that.number = this.number;
    // PendingIntents are global, so there's no reason (or way) to clone them.
    that.contentIntent = this.contentIntent;
    that.deleteIntent = this.deleteIntent;
    that.fullScreenIntent = this.fullScreenIntent;
    if (this.tickerText != null) {
        that.tickerText = this.tickerText.toString();
    }
    if (heavy && this.tickerView != null) {
        that.tickerView = this.tickerView.clone();
    }
    if (heavy && this.contentView != null) {
        that.contentView = this.contentView.clone();
    }
    if (heavy && this.mLargeIcon != null) {
        that.mLargeIcon = this.mLargeIcon;
    }
    that.iconLevel = this.iconLevel;
    // android.net.Uri is immutable
    that.sound = this.sound;
    that.audioStreamType = this.audioStreamType;
    if (this.audioAttributes != null) {
        that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build();
    }
    final long[] vibrate = this.vibrate;
    if (vibrate != null) {
        final int N = vibrate.length;
        final long[] vib = that.vibrate = new long[N];
        System.arraycopy(vibrate, 0, vib, 0, N);
    }
    that.ledARGB = this.ledARGB;
    that.ledOnMS = this.ledOnMS;
    that.ledOffMS = this.ledOffMS;
    that.defaults = this.defaults;
    that.flags = this.flags;
    that.priority = this.priority;
    that.category = this.category;
    that.mGroupKey = this.mGroupKey;
    that.mSortKey = this.mSortKey;
    if (this.extras != null) {
        try {
            that.extras = new Bundle(this.extras);
            // will unparcel
            that.extras.size();
        } catch (BadParcelableException e) {
            Log.e(TAG, "could not unparcel extras from notification: " + this, e);
            that.extras = null;
        }
    }
    if (!ArrayUtils.isEmpty(allPendingIntents)) {
        that.allPendingIntents = new ArraySet<>(allPendingIntents);
    }
    if (this.actions != null) {
        that.actions = new Action[this.actions.length];
        for (int i = 0; i < this.actions.length; i++) {
            if (this.actions[i] != null) {
                that.actions[i] = this.actions[i].clone();
            }
        }
    }
    if (heavy && this.bigContentView != null) {
        that.bigContentView = this.bigContentView.clone();
    }
    if (heavy && this.headsUpContentView != null) {
        that.headsUpContentView = this.headsUpContentView.clone();
    }
    that.visibility = this.visibility;
    if (this.publicVersion != null) {
        that.publicVersion = new Notification();
        this.publicVersion.cloneInto(that.publicVersion, heavy);
    }
    that.color = this.color;
    if (!heavy) {
        // will clean out extras
        that.lightenPayload();
    }
}
Also used : Bundle(android.os.Bundle) SpannableStringBuilder(android.text.SpannableStringBuilder) BadParcelableException(android.os.BadParcelableException)

Example 12 with BadParcelableException

use of android.os.BadParcelableException in project android_frameworks_base by ResurrectionRemix.

the class Activity method getReferrer.

/**
     * Return information about who launched this activity.  If the launching Intent
     * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER},
     * that will be returned as-is; otherwise, if known, an
     * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the
     * package name that started the Intent will be returned.  This may return null if no
     * referrer can be identified -- it is neither explicitly specified, nor is it known which
     * application package was involved.
     *
     * <p>If called while inside the handling of {@link #onNewIntent}, this function will
     * return the referrer that submitted that new intent to the activity.  Otherwise, it
     * always returns the referrer of the original Intent.</p>
     *
     * <p>Note that this is <em>not</em> a security feature -- you can not trust the
     * referrer information, applications can spoof it.</p>
     */
@Nullable
public Uri getReferrer() {
    Intent intent = getIntent();
    try {
        Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
        if (referrer != null) {
            return referrer;
        }
        String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME);
        if (referrerName != null) {
            return Uri.parse(referrerName);
        }
    } catch (BadParcelableException e) {
        Log.w(TAG, "Cannot read referrer from intent;" + " intent extras contain unknown custom Parcelable objects");
    }
    if (mReferrer != null) {
        return new Uri.Builder().scheme("android-app").authority(mReferrer).build();
    }
    return null;
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) BadParcelableException(android.os.BadParcelableException) Nullable(android.annotation.Nullable)

Example 13 with BadParcelableException

use of android.os.BadParcelableException in project robolectric by robolectric.

the class ShadowParcel method readParcelableCreator.

@HiddenApi
@Implementation(minSdk = JELLY_BEAN_MR2)
public Parcelable.Creator<?> readParcelableCreator(ClassLoader loader) {
    // note: calling `readString` will also consume the string, and increment the data-pointer.
    // which is exactly what we need, since we do not call the real `readParcelableCreator`.
    final String name = realObject.readString();
    if (name == null) {
        return null;
    }
    Parcelable.Creator<?> creator;
    try {
        // If loader == null, explicitly emulate Class.forName(String) "caller
        // classloader" behavior.
        ClassLoader parcelableClassLoader = (loader == null ? getClass().getClassLoader() : loader);
        // Avoid initializing the Parcelable class until we know it implements
        // Parcelable and has the necessary CREATOR field.
        Class<?> parcelableClass = Class.forName(name, false, /* initialize */
        parcelableClassLoader);
        if (!Parcelable.class.isAssignableFrom(parcelableClass)) {
            throw new BadParcelableException("Parcelable protocol requires that the " + "class implements Parcelable");
        }
        Field f = parcelableClass.getField("CREATOR");
        // this is a fix for JDK8<->Android VM incompatibility:
        // Apparently, JDK will not allow access to a public field if its
        // class is not visible (private or package-private) from the call-site.
        f.setAccessible(true);
        if ((f.getModifiers() & Modifier.STATIC) == 0) {
            throw new BadParcelableException("Parcelable protocol requires " + "the CREATOR object to be static on class " + name);
        }
        Class<?> creatorType = f.getType();
        if (!Parcelable.Creator.class.isAssignableFrom(creatorType)) {
            // parcelableClass unnecessarily.
            throw new BadParcelableException("Parcelable protocol requires a " + "Parcelable.Creator object called " + "CREATOR on class " + name);
        }
        creator = (Parcelable.Creator<?>) f.get(null);
    } catch (IllegalAccessException e) {
        Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
        throw new BadParcelableException("IllegalAccessException when unmarshalling: " + name);
    } catch (ClassNotFoundException e) {
        Log.e(TAG, "Class not found when unmarshalling: " + name, e);
        throw new BadParcelableException("ClassNotFoundException when unmarshalling: " + name);
    } catch (NoSuchFieldException e) {
        throw new BadParcelableException("Parcelable protocol requires a " + "Parcelable.Creator object called " + "CREATOR on class " + name);
    }
    if (creator == null) {
        throw new BadParcelableException("Parcelable protocol requires a " + "non-null Parcelable.Creator object called " + "CREATOR on class " + name);
    }
    return creator;
}
Also used : Field(java.lang.reflect.Field) Parcelable(android.os.Parcelable) BadParcelableException(android.os.BadParcelableException) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

BadParcelableException (android.os.BadParcelableException)13 Bundle (android.os.Bundle)6 Nullable (android.annotation.Nullable)5 Intent (android.content.Intent)5 Uri (android.net.Uri)5 SpannableStringBuilder (android.text.SpannableStringBuilder)5 Parcelable (android.os.Parcelable)1 Field (java.lang.reflect.Field)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 HiddenApi (org.robolectric.annotation.HiddenApi)1 Implementation (org.robolectric.annotation.Implementation)1