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

Commit 3e75d248 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Do not unparcel bundle from application in LaunchActivityItem" into...

Merge "Do not unparcel bundle from application in LaunchActivityItem" into rvc-dev am: aec74e1a am: d74d22f5

Change-Id: Ia642babe3ea3e50f5d389be994ff50e63cbeeac1
parents 680244fc d74d22f5
Loading
Loading
Loading
Loading
+16 −22
Original line number Original line Diff line number Diff line
@@ -186,8 +186,8 @@ public class LaunchActivityItem extends ClientTransactionItem {
                && Objects.equals(mOverrideConfig, other.mOverrideConfig)
                && Objects.equals(mOverrideConfig, other.mOverrideConfig)
                && Objects.equals(mCompatInfo, other.mCompatInfo)
                && Objects.equals(mCompatInfo, other.mCompatInfo)
                && Objects.equals(mReferrer, other.mReferrer)
                && Objects.equals(mReferrer, other.mReferrer)
                && mProcState == other.mProcState && areBundlesEqual(mState, other.mState)
                && mProcState == other.mProcState && areBundlesEqualRoughly(mState, other.mState)
                && areBundlesEqual(mPersistentState, other.mPersistentState)
                && areBundlesEqualRoughly(mPersistentState, other.mPersistentState)
                && Objects.equals(mPendingResults, other.mPendingResults)
                && Objects.equals(mPendingResults, other.mPendingResults)
                && Objects.equals(mPendingNewIntents, other.mPendingNewIntents)
                && Objects.equals(mPendingNewIntents, other.mPendingNewIntents)
                && mIsForward == other.mIsForward
                && mIsForward == other.mIsForward
@@ -205,8 +205,8 @@ public class LaunchActivityItem extends ClientTransactionItem {
        result = 31 * result + Objects.hashCode(mCompatInfo);
        result = 31 * result + Objects.hashCode(mCompatInfo);
        result = 31 * result + Objects.hashCode(mReferrer);
        result = 31 * result + Objects.hashCode(mReferrer);
        result = 31 * result + Objects.hashCode(mProcState);
        result = 31 * result + Objects.hashCode(mProcState);
        result = 31 * result + (mState != null ? mState.size() : 0);
        result = 31 * result + getRoughBundleHashCode(mState);
        result = 31 * result + (mPersistentState != null ? mPersistentState.size() : 0);
        result = 31 * result + getRoughBundleHashCode(mPersistentState);
        result = 31 * result + Objects.hashCode(mPendingResults);
        result = 31 * result + Objects.hashCode(mPendingResults);
        result = 31 * result + Objects.hashCode(mPendingNewIntents);
        result = 31 * result + Objects.hashCode(mPendingNewIntents);
        result = 31 * result + (mIsForward ? 1 : 0);
        result = 31 * result + (mIsForward ? 1 : 0);
@@ -225,25 +225,19 @@ public class LaunchActivityItem extends ClientTransactionItem {
                && Objects.equals(mInfo.getComponentName(), other.getComponentName());
                && Objects.equals(mInfo.getComponentName(), other.getComponentName());
    }
    }


    private static boolean areBundlesEqual(BaseBundle extras, BaseBundle newExtras) {
    /**
        if (extras == null || newExtras == null) {
     * This method may be used to compare a parceled item with another unparceled item, and the
            return extras == newExtras;
     * parceled bundle may contain customized class that will raise BadParcelableException when
        }
     * unparceling if a customized class loader is not set to the bundle. So the hash code is

     * simply determined by the bundle is empty or not.
        if (extras.size() != newExtras.size()) {
     */
            return false;
    private static int getRoughBundleHashCode(BaseBundle bundle) {
        return (bundle == null || bundle.isDefinitelyEmpty()) ? 0 : 1;
    }
    }


        for (String key : extras.keySet()) {
    /** Compares the bundles without unparceling them (avoid BadParcelableException). */
            if (key != null) {
    private static boolean areBundlesEqualRoughly(BaseBundle a, BaseBundle b) {
                final Object value = extras.get(key);
        return getRoughBundleHashCode(a) == getRoughBundleHashCode(b);
                final Object newValue = newExtras.get(key);
                if (!Objects.equals(value, newValue)) {
                    return false;
                }
            }
        }
        return true;
    }
    }


    @Override
    @Override
+42 −1
Original line number Original line Diff line number Diff line
@@ -63,7 +63,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map;


/**
/**
@@ -213,6 +212,7 @@ public class TransactionParcelTests {
        int procState = 4;
        int procState = 4;
        Bundle bundle = new Bundle();
        Bundle bundle = new Bundle();
        bundle.putString("key", "value");
        bundle.putString("key", "value");
        bundle.putParcelable("data", new ParcelableData(1));
        PersistableBundle persistableBundle = new PersistableBundle();
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putInt("k", 4);
        persistableBundle.putInt("k", 4);


@@ -374,6 +374,47 @@ public class TransactionParcelTests {
        mParcel.setDataPosition(0);
        mParcel.setDataPosition(0);
    }
    }


    /**
     * The parcelable class to make sure that when comparing the {@link LaunchActivityItem} or
     * getting its hash code, the bundle is not unparceled. System shouldn't touch the data from
     * application, otherwise it will cause exception as:
     *   android.os.BadParcelableException: ClassNotFoundException when unmarshalling:
     *   android.app.servertransaction.TransactionParcelTests$ParcelableData".
     */
    public static class ParcelableData implements Parcelable {
        int mValue;

        ParcelableData() {}

        ParcelableData(int value) {
            mValue = value;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mValue);
        }

        public static final Creator<ParcelableData> CREATOR = new Creator<ParcelableData>() {
            @Override
            public ParcelableData createFromParcel(Parcel source) {
                final ParcelableData data = new ParcelableData();
                data.mValue = source.readInt();
                return data;
            }

            @Override
            public ParcelableData[] newArray(int size) {
                return new ParcelableData[size];
            }
        };
    }

    /** Stub implementation of IApplicationThread that can be presented as {@link Binder}. */
    /** Stub implementation of IApplicationThread that can be presented as {@link Binder}. */
    class StubAppThread extends android.app.IApplicationThread.Stub  {
    class StubAppThread extends android.app.IApplicationThread.Stub  {