startop: Add reportFullyDrawn event support in Iorap.

Bug: 137684347
Test: make
Test: run on a crosshatch device and check the reportFullyDrawn event in
the logcat.

Change-Id: Ib8373ecfa1d3579c937242d30cea1ce1396ba632
This commit is contained in:
Yan Wang
2019-09-30 15:43:50 -07:00
parent d47f90bc46
commit 722d6be12f
2 changed files with 97 additions and 13 deletions

View File

@@ -86,10 +86,14 @@ public abstract class AppLaunchEvent implements Parcelable {
public static final class IntentStarted extends AppLaunchEvent {
@NonNull
public final Intent intent;
public final long timestampNs;
public IntentStarted(@SequenceId long sequenceId, Intent intent) {
public IntentStarted(@SequenceId long sequenceId,
Intent intent,
long timestampNs) {
super(sequenceId);
this.intent = intent;
this.timestampNs = timestampNs;
Objects.requireNonNull(intent, "intent");
}
@@ -98,14 +102,16 @@ public abstract class AppLaunchEvent implements Parcelable {
public boolean equals(Object other) {
if (other instanceof IntentStarted) {
return intent.equals(((IntentStarted)other).intent) &&
super.equals(other);
timestampNs == ((IntentStarted)other).timestampNs &&
super.equals(other);
}
return false;
}
@Override
protected String toStringBody() {
return ", intent=" + intent.toString();
return ", intent=" + intent.toString() +
" , timestampNs=" + Long.toString(timestampNs);
}
@@ -113,11 +119,13 @@ public abstract class AppLaunchEvent implements Parcelable {
protected void writeToParcelImpl(Parcel p, int flags) {
super.writeToParcelImpl(p, flags);
IntentProtoParcelable.write(p, intent, flags);
p.writeLong(timestampNs);
}
IntentStarted(Parcel p) {
super(p);
intent = IntentProtoParcelable.create(p);
timestampNs = p.readLong();
}
}
@@ -216,18 +224,39 @@ public abstract class AppLaunchEvent implements Parcelable {
}
public static final class ActivityLaunchFinished extends BaseWithActivityRecordData {
public final long timestampNs;
public ActivityLaunchFinished(@SequenceId long sequenceId,
@NonNull @ActivityRecordProto byte[] snapshot) {
@NonNull @ActivityRecordProto byte[] snapshot,
long timestampNs) {
super(sequenceId, snapshot);
this.timestampNs = timestampNs;
}
@Override
public boolean equals(Object other) {
if (other instanceof ActivityLaunched) {
return super.equals(other);
return timestampNs == ((ActivityLaunchFinished)other).timestampNs &&
super.equals(other);
}
return false;
}
@Override
protected String toStringBody() {
return ", timestampNs=" + Long.toString(timestampNs);
}
@Override
protected void writeToParcelImpl(Parcel p, int flags) {
super.writeToParcelImpl(p, flags);
p.writeLong(timestampNs);
}
ActivityLaunchFinished(Parcel p) {
super(p);
timestampNs = p.readLong();
}
}
public static class ActivityLaunchCancelled extends AppLaunchEvent {
@@ -275,6 +304,42 @@ public abstract class AppLaunchEvent implements Parcelable {
}
}
public static final class ReportFullyDrawn extends BaseWithActivityRecordData {
public final long timestampNs;
public ReportFullyDrawn(@SequenceId long sequenceId,
@NonNull @ActivityRecordProto byte[] snapshot,
long timestampNs) {
super(sequenceId, snapshot);
this.timestampNs = timestampNs;
}
@Override
public boolean equals(Object other) {
if (other instanceof ReportFullyDrawn) {
return timestampNs == ((ReportFullyDrawn)other).timestampNs &&
super.equals(other);
}
return false;
}
@Override
protected String toStringBody() {
return ", timestampNs=" + Long.toString(timestampNs);
}
@Override
protected void writeToParcelImpl(Parcel p, int flags) {
super.writeToParcelImpl(p, flags);
p.writeLong(timestampNs);
}
ReportFullyDrawn(Parcel p) {
super(p);
timestampNs = p.readLong();
}
}
@Override
public @ContentsFlags int describeContents() { return 0; }
@@ -348,6 +413,7 @@ public abstract class AppLaunchEvent implements Parcelable {
ActivityLaunched.class,
ActivityLaunchFinished.class,
ActivityLaunchCancelled.class,
ReportFullyDrawn.class,
};
public static class ActivityRecordProtoParcelable {

View File

@@ -315,19 +315,19 @@ public class IorapForwardingService extends SystemService {
// All callbacks occur on the same background thread. Don't synchronize explicitly.
@Override
public void onIntentStarted(@NonNull Intent intent) {
public void onIntentStarted(@NonNull Intent intent, long timestampNs) {
// #onIntentStarted [is the only transition that] initiates a new launch sequence.
++mSequenceId;
if (DEBUG) {
Log.v(TAG, String.format("AppLaunchObserver#onIntentStarted(%d, %s)",
mSequenceId, intent));
Log.v(TAG, String.format("AppLaunchObserver#onIntentStarted(%d, %s, %d)",
mSequenceId, intent, timestampNs));
}
invokeRemote(mIorapRemote,
(IIorap remote) ->
remote.onAppLaunchEvent(RequestId.nextValueForSequence(),
new AppLaunchEvent.IntentStarted(mSequenceId, intent))
new AppLaunchEvent.IntentStarted(mSequenceId, intent, timestampNs))
);
}
@@ -374,16 +374,34 @@ public class IorapForwardingService extends SystemService {
}
@Override
public void onActivityLaunchFinished(@NonNull @ActivityRecordProto byte[] activity) {
public void onActivityLaunchFinished(@NonNull @ActivityRecordProto byte[] activity,
long timestampNs) {
if (DEBUG) {
Log.v(TAG, String.format("AppLaunchObserver#onActivityLaunchFinished(%d, %s)",
mSequenceId, activity));
Log.v(TAG, String.format("AppLaunchObserver#onActivityLaunchFinished(%d, %s, %d)",
mSequenceId, activity, timestampNs));
}
invokeRemote(mIorapRemote,
(IIorap remote) ->
remote.onAppLaunchEvent(RequestId.nextValueForSequence(),
new AppLaunchEvent.ActivityLaunchFinished(mSequenceId, activity))
new AppLaunchEvent.ActivityLaunchFinished(mSequenceId,
activity,
timestampNs))
);
}
@Override
public void onReportFullyDrawn(@NonNull @ActivityRecordProto byte[] activity,
long timestampNs) {
if (DEBUG) {
Log.v(TAG, String.format("AppLaunchObserver#onReportFullyDrawn(%d, %s, %d)",
mSequenceId, activity, timestampNs));
}
invokeRemote(mIorapRemote,
(IIorap remote) ->
remote.onAppLaunchEvent(RequestId.nextValueForSequence(),
new AppLaunchEvent.ReportFullyDrawn(mSequenceId, activity, timestampNs))
);
}
}