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

Commit 5ddd5b56 authored by Joe Antonetti's avatar Joe Antonetti Committed by Android (Google) Code Review
Browse files

Merge "[Handoff][2/N] Add IsHandoffEnabled to RemoteTaskInfo" into main

parents 327a520a d9ab496c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ message RemoteTaskInfo {
    string label = 2;
    int64 lastUsedTimeMillis = 3;
    bytes taskIcon = 4;
    bool isHandoffEnabled = 5;
}

message RemoteTaskRemovedMessage {
+22 −3
Original line number Diff line number Diff line
@@ -25,7 +25,12 @@ import java.util.Arrays;
import java.util.Objects;
import java.io.IOException;

public record RemoteTaskInfo(int id, String label, long lastUsedTimeMillis, byte[] taskIcon) {
public record RemoteTaskInfo(
    int id,
    String label,
    long lastUsedTimeMillis,
    byte[] taskIcon,
    boolean isHandoffEnabled) {

    public static RemoteTaskInfo fromProto(ProtoInputStream protoInputStream)
        throws IOException {
@@ -34,6 +39,7 @@ public record RemoteTaskInfo(int id, String label, long lastUsedTimeMillis, byte
        String label = "";
        long lastUsedTimeMillis = 0;
        byte[] taskIcon = new byte[0];
        boolean isHandoffEnabled = false;
        while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
            switch (protoInputStream.getFieldNumber()) {
              case (int) android.companion.RemoteTaskInfo.ID:
@@ -54,10 +60,14 @@ public record RemoteTaskInfo(int id, String label, long lastUsedTimeMillis, byte
                    taskIcon = protoInputStream
                        .readBytes(android.companion.RemoteTaskInfo.TASK_ICON);
                    break;
                case (int) android.companion.RemoteTaskInfo.IS_HANDOFF_ENABLED:
                    isHandoffEnabled = protoInputStream.readBoolean(
                        android.companion.RemoteTaskInfo.IS_HANDOFF_ENABLED);
                    break;
            }
       }

        return new RemoteTaskInfo(id, label, lastUsedTimeMillis, taskIcon);
        return new RemoteTaskInfo(id, label, lastUsedTimeMillis, taskIcon, isHandoffEnabled);
   }

    public void writeToProto(ProtoOutputStream protoOutputStream) {
@@ -71,6 +81,9 @@ public record RemoteTaskInfo(int id, String label, long lastUsedTimeMillis, byte
                lastUsedTimeMillis());
        protoOutputStream
            .writeBytes(android.companion.RemoteTaskInfo.TASK_ICON, taskIcon());
        protoOutputStream
            .writeBool(
                android.companion.RemoteTaskInfo.IS_HANDOFF_ENABLED, isHandoffEnabled());
    }

    @Override
@@ -87,7 +100,12 @@ public record RemoteTaskInfo(int id, String label, long lastUsedTimeMillis, byte

    @Override
    public int hashCode() {
        return Objects.hash(id(), label(), lastUsedTimeMillis(), Arrays.hashCode(taskIcon()));
        return Objects.hash(
            id(),
            label(),
            lastUsedTimeMillis(),
            Arrays.hashCode(taskIcon()),
            isHandoffEnabled());
    }

    public RemoteTask toRemoteTask(int deviceId, String deviceName) {
@@ -102,6 +120,7 @@ public record RemoteTaskInfo(int id, String label, long lastUsedTimeMillis, byte
                .setLastUsedTimestampMillis(lastUsedTimeMillis())
                .setSourceDeviceName(deviceName)
                .setIcon(taskIcon)
                .setHandoffEnabled(isHandoffEnabled())
                .build();
    }
}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -111,7 +111,8 @@ public class RunningTaskFetcher {
            taskInfo.taskId,
            packageMetadata.label(),
            taskInfo.lastActiveTime,
            packageMetadata.icon());
            packageMetadata.icon(),
            false);
    }

    @NonNull
+6 −3
Original line number Diff line number Diff line
@@ -91,7 +91,8 @@ public class TaskBroadcasterTest {
            100 /* taskId */,
            "test" /* label */,
            100 /* lastActiveTime */,
            new byte[0] /* icon */);
            new byte[0] /* icon */,
            true /* isHandoffEnabled */);
        when(mMockRunningTaskFetcher.getRunningTasks())
            .thenReturn(List.of(expectedRemoteTaskInfo));

@@ -115,7 +116,8 @@ public class TaskBroadcasterTest {
            123 /* taskId */,
            "newTask" /* label */,
            0 /* lastActiveTime */,
            new byte[0] /* icon */);
            new byte[0] /* icon */,
            true /* isHandoffEnabled */);
        when(mMockRunningTaskFetcher.getRunningTaskById(expectedRemoteTaskInfo.id()))
            .thenReturn(expectedRemoteTaskInfo);

@@ -155,7 +157,8 @@ public class TaskBroadcasterTest {
            1 /* taskId */,
            "task" /* label */,
            100 /* lastActiveTime */,
            new byte[0] /* icon */);
            new byte[0] /* icon */,
            true /* isHandoffEnabled */);
        when(mMockRunningTaskFetcher.getRunningTaskById(expectedRemoteTaskInfo.id()))
            .thenReturn(expectedRemoteTaskInfo);
        RunningTaskInfo taskInfo = new RunningTaskInfo();
+3 −3
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ public class TaskContinuityMessengerTest {
        int expectedAssociationId = 1;
        connectAssociations(List.of(expectedAssociationId));
        ContinuityDeviceConnected expectedMessage = new ContinuityDeviceConnected(
                    List.of(new RemoteTaskInfo(1, "label", 1000, new byte[0])));
                    List.of(new RemoteTaskInfo(1, "label", 1000, new byte[0], true)));

        listener.onMessageReceived(
            expectedAssociationId,
@@ -133,7 +133,7 @@ public class TaskContinuityMessengerTest {
        mTaskContinuityMessenger.enable();
        connectAssociations(List.of(associationId));
        ContinuityDeviceConnected expectedMessage = new ContinuityDeviceConnected(
            List.of(new RemoteTaskInfo(1, "label", 1000, new byte[0])));
            List.of(new RemoteTaskInfo(1, "label", 1000, new byte[0], true)));
        TaskContinuityMessenger.SendMessageResult result
            = mTaskContinuityMessenger.sendMessage(associationId, expectedMessage);
        verify(mMockCompanionDeviceManagerService, times(1))
@@ -150,7 +150,7 @@ public class TaskContinuityMessengerTest {

        int associationId = 1;
        ContinuityDeviceConnected expectedMessage = new ContinuityDeviceConnected(
            List.of(new RemoteTaskInfo(1, "label", 1000, new byte[0])));
            List.of(new RemoteTaskInfo(1, "label", 1000, new byte[0], true)));
        TaskContinuityMessenger.SendMessageResult result
            = mTaskContinuityMessenger.sendMessage(associationId, expectedMessage);
        verify(mMockCompanionDeviceManagerService, never())
Loading