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

Commit e9e439a4 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

iorap: Update AppLaunchEvent binder calls to use protobuf

* Also makes a minor change to android.os.Intent to allow writing it
into a protobuf without needing an outer field ID. This makes it
directly unserializable into a C++ code-generated protobuf as a root
proto.

Bug: 72170747
Change-Id: I19e91f0f9c5e5a37810a430e9c483e7752af54d7
Test: atest system/iorap
parent ccee30ed
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -9852,10 +9852,22 @@ public class Intent implements Parcelable, Cloneable {
        writeToProto(proto, fieldId, true, true, true, false);
    }

    /** @hide */
    public void writeToProto(ProtoOutputStream proto) {
        // Same input parameters that toString() gives to toShortString().
        writeToProtoWithoutFieldId(proto, true, true, true, false);
    }

    /** @hide */
    public void writeToProto(ProtoOutputStream proto, long fieldId, boolean secure, boolean comp,
            boolean extras, boolean clip) {
        long token = proto.start(fieldId);
        writeToProtoWithoutFieldId(proto, secure, comp, extras, clip);
        proto.end(token);
    }

    private void writeToProtoWithoutFieldId(ProtoOutputStream proto, boolean secure, boolean comp,
            boolean extras, boolean clip) {
        if (mAction != null) {
            proto.write(IntentProto.ACTION, mAction);
        }
@@ -9900,7 +9912,6 @@ public class Intent implements Parcelable, Cloneable {
        if (mSelector != null) {
            proto.write(IntentProto.SELECTOR, mSelector.toShortString(secure, comp, extras, clip));
        }
        proto.end(token);
    }

    /**
+31 −7
Original line number Diff line number Diff line
@@ -24,9 +24,8 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.proto.ProtoOutputStream;

// TODO: fix this. either move this class into system server or add a dependency on
// these wm classes to libiorap-java and libiorap-java-tests (somehow).
import com.android.server.wm.ActivityMetricsLaunchObserver;
import com.android.server.wm.ActivityMetricsLaunchObserver.ActivityRecordProto;
import com.android.server.wm.ActivityMetricsLaunchObserver.Temperature;
@@ -113,12 +112,12 @@ public abstract class AppLaunchEvent implements Parcelable {
        @Override
        protected void writeToParcelImpl(Parcel p, int flags) {
            super.writeToParcelImpl(p, flags);
            intent.writeToParcel(p, flags);
            IntentProtoParcelable.write(p, intent, flags);
        }

        IntentStarted(Parcel p) {
            super(p);
            intent = Intent.CREATOR.createFromParcel(p);
            intent = IntentProtoParcelable.create(p);
        }
    }

@@ -232,8 +231,7 @@ public abstract class AppLaunchEvent implements Parcelable {
    }

     public static class ActivityLaunchCancelled extends AppLaunchEvent {
        public final @Nullable
        @ActivityRecordProto byte[] activityRecordSnapshot;
        public final @Nullable @ActivityRecordProto byte[] activityRecordSnapshot;

        public ActivityLaunchCancelled(@SequenceId long sequenceId,
                @Nullable @ActivityRecordProto byte[] snapshot) {
@@ -352,7 +350,6 @@ public abstract class AppLaunchEvent implements Parcelable {
            ActivityLaunchCancelled.class,
    };

    // TODO: move to @ActivityRecordProto byte[] once we have unit tests.
    public static class ActivityRecordProtoParcelable {
        public static void write(Parcel p, @ActivityRecordProto byte[] activityRecordSnapshot,
                int flags) {
@@ -365,4 +362,31 @@ public abstract class AppLaunchEvent implements Parcelable {
            return data;
        }
    }

    public static class IntentProtoParcelable {
        private static final int INTENT_PROTO_CHUNK_SIZE = 1024;

        public static void write(Parcel p, @NonNull Intent intent, int flags) {
            // There does not appear to be a way to 'reset' a ProtoOutputBuffer stream,
            // so create a new one every time.
            final ProtoOutputStream protoOutputStream =
                    new ProtoOutputStream(INTENT_PROTO_CHUNK_SIZE);
            // Write this data out as the top-most IntentProto (i.e. it is not a sub-object).
            intent.writeToProto(protoOutputStream);
            final byte[] bytes = protoOutputStream.getBytes();

            p.writeByteArray(bytes);
        }

        // TODO: Should be mockable for testing?
        // We cannot deserialize in the platform because we don't have a 'readFromProto'
        // code.
        public static @NonNull Intent create(Parcel p) {
            // This will "read" the correct amount of data, but then we discard it.
            byte[] data = p.createByteArray();

            // Never called by real code in a platform, this binder API is implemented only in C++.
            return new Intent("<cannot deserialize IntentProto>");
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public class IorapForwardingService extends SystemService {

            invokeRemote(() ->
                mIorapRemote.onAppLaunchEvent(RequestId.nextValueForSequence(),
                        new AppLaunchEvent.ActivityLaunchCancelled(mSequenceId, activity))
                        new AppLaunchEvent.ActivityLaunchFinished(mSequenceId, activity))
            );
        }
    }
+9 −0
Original line number Diff line number Diff line
@@ -33,6 +33,15 @@
    <target_preparer class="com.android.tradefed.targetprep.DisableSELinuxTargetPreparer">
    </target_preparer>

    <target_preparer
        class="com.android.tradefed.targetprep.DeviceSetup">
        <!-- Crash instead of using Log.wtf within the system_server iorap code. -->
        <option name="set-property" key="iorapd.forwarding_service.wtf_crash" value="true" />
        <!-- IIorapd has fake behavior: it doesn't do anything but reply with 'DONE' status -->
        <option name="set-property" key="iorapd.binder.fake" value="true" />
        <option name="restore-properties" value="true" />
    </target_preparer>

    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.google.android.startop.iorap.tests" />
        <option name="runner" value="android.support.test.runner.AndroidJUnitRunner" />