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

Commit 957b6180 authored by cketti's avatar cketti
Browse files

Don't use Parcelable in Intents that can be launched from notifications

parent 9b7ed6e9
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.fsck.k9.activity.setup.FolderSettings;
import com.fsck.k9.activity.setup.Prefs;
import com.fsck.k9.fragment.MessageListFragment;
import com.fsck.k9.fragment.MessageListFragment.MessageListFragmentListener;
import com.fsck.k9.helper.ParcelableUtil;
import com.fsck.k9.mailstore.StorageManager;
import com.fsck.k9.preferences.StorageEditor;
import com.fsck.k9.search.LocalSearch;
@@ -108,7 +109,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
    public static Intent intentDisplaySearch(Context context, SearchSpecification search,
            boolean noThreading, boolean newTask, boolean clearTop) {
        Intent intent = new Intent(context, MessageList.class);
        intent.putExtra(EXTRA_SEARCH, search);
        intent.putExtra(EXTRA_SEARCH, ParcelableUtil.marshall(search));
        intent.putExtra(EXTRA_NO_THREADING, noThreading);

        if (clearTop) {
@@ -432,7 +433,8 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
            }
        } else {
            // regular LocalSearch object was passed
            mSearch = intent.getParcelableExtra(EXTRA_SEARCH);
            mSearch = intent.hasExtra(EXTRA_SEARCH) ?
                    ParcelableUtil.unmarshall(intent.getByteArrayExtra(EXTRA_SEARCH), LocalSearch.CREATOR) : null;
            mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false);
        }

+31 −0
Original line number Diff line number Diff line
package com.fsck.k9.helper;


import android.os.Parcel;
import android.os.Parcelable;


// Source: http://stackoverflow.com/a/18000094
public class ParcelableUtil {
    public static byte[] marshall(Parcelable parceable) {
        Parcel parcel = Parcel.obtain();
        parceable.writeToParcel(parcel, 0);
        byte[] bytes = parcel.marshall();
        parcel.recycle();
        return bytes;
    }

    public static <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) {
        Parcel parcel = unmarshall(bytes);
        T result = creator.createFromParcel(parcel);
        parcel.recycle();
        return result;
    }

    private static Parcel unmarshall(byte[] bytes) {
        Parcel parcel = Parcel.obtain();
        parcel.unmarshall(bytes, 0, bytes.length);
        parcel.setDataPosition(0);
        return parcel;
    }
}