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

Commit 0e757d0c authored by Yisroel Forta's avatar Yisroel Forta
Browse files

AppStartInfo intent serialization

Modify serialization, strip extras from intent, and update javadoc.

Test: make, flash, atest ApplicationStartInfoTest
Bug: 247814855
Change-Id: Ibbac9b50501d0ea17ff6c1bf2eefddafb8492bd0
parent 5eba0763
Loading
Loading
Loading
Loading
+27 −13
Original line number Original line Diff line number Diff line
@@ -413,7 +413,9 @@ public final class ApplicationStartInfo implements Parcelable {
     * @hide
     * @hide
     */
     */
    public void setIntent(Intent startIntent) {
    public void setIntent(Intent startIntent) {
        mStartIntent = startIntent;
        if (startIntent != null) {
            mStartIntent = startIntent.maybeStripForHistory();
        }
    }
    }


    /**
    /**
@@ -548,6 +550,8 @@ public final class ApplicationStartInfo implements Parcelable {
    /**
    /**
     * The intent used to launch the application.
     * The intent used to launch the application.
     *
     *
     * <p class="note"> Note: Intent is stripped and does not include extras.</p>
     *
     * <p class="note"> Note: field will be set for any {@link #getStartupState} value.</p>
     * <p class="note"> Note: field will be set for any {@link #getStartupState} value.</p>
     */
     */
    @SuppressLint("IntentBuilderName")
    @SuppressLint("IntentBuilderName")
@@ -662,6 +666,7 @@ public final class ApplicationStartInfo implements Parcelable {
    private static final String PROTO_SERIALIZER_ATTRIBUTE_TIMESTAMP = "timestamp";
    private static final String PROTO_SERIALIZER_ATTRIBUTE_TIMESTAMP = "timestamp";
    private static final String PROTO_SERIALIZER_ATTRIBUTE_KEY = "key";
    private static final String PROTO_SERIALIZER_ATTRIBUTE_KEY = "key";
    private static final String PROTO_SERIALIZER_ATTRIBUTE_TS = "ts";
    private static final String PROTO_SERIALIZER_ATTRIBUTE_TS = "ts";
    private static final String PROTO_SERIALIZER_ATTRIBUTE_INTENT = "intent";


    /**
    /**
     * Write to a protocol buffer output stream. Protocol buffer message definition at {@link
     * Write to a protocol buffer output stream. Protocol buffer message definition at {@link
@@ -702,10 +707,17 @@ public final class ApplicationStartInfo implements Parcelable {
        }
        }
        proto.write(ApplicationStartInfoProto.START_TYPE, mStartType);
        proto.write(ApplicationStartInfoProto.START_TYPE, mStartType);
        if (mStartIntent != null) {
        if (mStartIntent != null) {
            Parcel parcel = Parcel.obtain();
            ByteArrayOutputStream intentBytes = new ByteArrayOutputStream();
            mStartIntent.writeToParcel(parcel, 0);
            ObjectOutputStream intentOut = new ObjectOutputStream(intentBytes);
            proto.write(ApplicationStartInfoProto.START_INTENT, parcel.marshall());
            TypedXmlSerializer serializer = Xml.resolveSerializer(intentOut);
            parcel.recycle();
            serializer.startDocument(null, true);
            serializer.startTag(null, PROTO_SERIALIZER_ATTRIBUTE_INTENT);
            mStartIntent.saveToXml(serializer);
            serializer.endTag(null, PROTO_SERIALIZER_ATTRIBUTE_INTENT);
            serializer.endDocument();
            proto.write(ApplicationStartInfoProto.START_INTENT,
                    intentBytes.toByteArray());
            intentOut.close();
        }
        }
        proto.write(ApplicationStartInfoProto.LAUNCH_MODE, mLaunchMode);
        proto.write(ApplicationStartInfoProto.LAUNCH_MODE, mLaunchMode);
        proto.end(token);
        proto.end(token);
@@ -772,15 +784,17 @@ public final class ApplicationStartInfo implements Parcelable {
                    mStartType = proto.readInt(ApplicationStartInfoProto.START_TYPE);
                    mStartType = proto.readInt(ApplicationStartInfoProto.START_TYPE);
                    break;
                    break;
                case (int) ApplicationStartInfoProto.START_INTENT:
                case (int) ApplicationStartInfoProto.START_INTENT:
                    byte[] startIntentBytes = proto.readBytes(
                    ByteArrayInputStream intentBytes = new ByteArrayInputStream(proto.readBytes(
                        ApplicationStartInfoProto.START_INTENT);
                            ApplicationStartInfoProto.START_INTENT));
                    if (startIntentBytes.length > 0) {
                    ObjectInputStream intentIn = new ObjectInputStream(intentBytes);
                        Parcel parcel = Parcel.obtain();
                    try {
                        parcel.unmarshall(startIntentBytes, 0, startIntentBytes.length);
                        TypedXmlPullParser parser = Xml.resolvePullParser(intentIn);
                        parcel.setDataPosition(0);
                        XmlUtils.beginDocument(parser, PROTO_SERIALIZER_ATTRIBUTE_INTENT);
                        mStartIntent = Intent.CREATOR.createFromParcel(parcel);
                        mStartIntent = Intent.restoreFromXml(parser);
                        parcel.recycle();
                    } catch (XmlPullParserException e) {
                        // Intent lost
                    }
                    }
                    intentIn.close();
                    break;
                    break;
                case (int) ApplicationStartInfoProto.LAUNCH_MODE:
                case (int) ApplicationStartInfoProto.LAUNCH_MODE:
                    mLaunchMode = proto.readInt(ApplicationStartInfoProto.LAUNCH_MODE);
                    mLaunchMode = proto.readInt(ApplicationStartInfoProto.LAUNCH_MODE);