Loading core/proto/android/companion/task_continuity_message.proto +5 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ message TaskContinuityMessage { ContinuityDeviceConnected device_connected = 1; ContinuityDeviceConnected device_connected = 1; RemoteTaskAddedMessage remote_task_added_message = 2; RemoteTaskAddedMessage remote_task_added_message = 2; RemoteTaskRemovedMessage remote_task_removed = 3; RemoteTaskRemovedMessage remote_task_removed = 3; HandoffRequestMessage handoff_request = 4; } } } } Loading @@ -38,6 +39,10 @@ message RemoteTaskAddedMessage { RemoteTaskInfo task = 1; RemoteTaskInfo task = 1; } } message HandoffRequestMessage { int32 task_id = 1; } message RemoteTaskInfo { message RemoteTaskInfo { int32 id = 1; int32 id = 1; string label = 2; string label = 2; Loading services/companion/java/com/android/server/companion/datatransfer/continuity/messages/HandoffRequestMessage.java 0 → 100644 +46 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.companion.datatransfer.continuity.messages; import android.util.proto.ProtoInputStream; import android.util.proto.ProtoOutputStream; import java.io.IOException; /** * Deserialized version of the HandoffRequestMessage proto. */ public record HandoffRequestMessage(int taskId) implements TaskContinuityMessageData { public static HandoffRequestMessage readFromProto(ProtoInputStream pis) throws IOException { int taskId = 0; while (pis.nextField() != ProtoInputStream.NO_MORE_FIELDS) { switch (pis.getFieldNumber()) { case (int) android.companion.HandoffRequestMessage.TASK_ID: taskId = pis.readInt(android.companion.HandoffRequestMessage.TASK_ID); break; } } return new HandoffRequestMessage(taskId); } @Override public void writeToProto(ProtoOutputStream pos) { pos.write(android.companion.HandoffRequestMessage.TASK_ID, taskId()); } } No newline at end of file services/tests/servicestests/src/com/android/server/companion/datatransfer/continuity/messages/HandoffRequestMessageTest.java 0 → 100644 +77 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.companion.datatransfer.continuity.messages; import static com.google.common.truth.Truth.assertThat; import android.platform.test.annotations.Presubmit; import android.testing.AndroidTestingRunner; import android.util.proto.ProtoInputStream; import android.util.proto.ProtoOutputStream; import org.junit.Test; import org.junit.runner.RunWith; import java.io.IOException; @Presubmit @RunWith(AndroidTestingRunner.class) public class HandoffRequestMessageTest { @Test public void testConstructor_fromTaskId() { int taskId = 1; HandoffRequestMessage handoffRequestMessage = new HandoffRequestMessage(taskId); assertThat(handoffRequestMessage.taskId()).isEqualTo(taskId); } @Test public void testConstructor_fromProto() throws IOException { int taskId = 1; final ProtoOutputStream pos = new ProtoOutputStream(); pos.write(android.companion.HandoffRequestMessage.TASK_ID, taskId); pos.flush(); ProtoInputStream pis = new ProtoInputStream(pos.getBytes()); HandoffRequestMessage handoffRequestMessage = HandoffRequestMessage.readFromProto(pis); assertThat(handoffRequestMessage.taskId()).isEqualTo(taskId); } @Test public void testConstructor_fromProto_noTaskId_returnsZero() throws IOException { final ProtoOutputStream pos = new ProtoOutputStream(); pos.flush(); ProtoInputStream pis = new ProtoInputStream(pos.getBytes()); HandoffRequestMessage handoffRequestMessage = HandoffRequestMessage.readFromProto(pis); assertThat(handoffRequestMessage.taskId()).isEqualTo(0); } @Test public void testWriteAndRead_roundTrip_works() throws IOException { HandoffRequestMessage expectedMessage = new HandoffRequestMessage(1); final ProtoOutputStream pos = new ProtoOutputStream(); expectedMessage.writeToProto(pos); pos.flush(); final ProtoInputStream pis = new ProtoInputStream(pos.getBytes()); final HandoffRequestMessage actualMessage = HandoffRequestMessage.readFromProto(pis); assertThat(actualMessage).isEqualTo(expectedMessage); } } No newline at end of file Loading
core/proto/android/companion/task_continuity_message.proto +5 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ message TaskContinuityMessage { ContinuityDeviceConnected device_connected = 1; ContinuityDeviceConnected device_connected = 1; RemoteTaskAddedMessage remote_task_added_message = 2; RemoteTaskAddedMessage remote_task_added_message = 2; RemoteTaskRemovedMessage remote_task_removed = 3; RemoteTaskRemovedMessage remote_task_removed = 3; HandoffRequestMessage handoff_request = 4; } } } } Loading @@ -38,6 +39,10 @@ message RemoteTaskAddedMessage { RemoteTaskInfo task = 1; RemoteTaskInfo task = 1; } } message HandoffRequestMessage { int32 task_id = 1; } message RemoteTaskInfo { message RemoteTaskInfo { int32 id = 1; int32 id = 1; string label = 2; string label = 2; Loading
services/companion/java/com/android/server/companion/datatransfer/continuity/messages/HandoffRequestMessage.java 0 → 100644 +46 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.companion.datatransfer.continuity.messages; import android.util.proto.ProtoInputStream; import android.util.proto.ProtoOutputStream; import java.io.IOException; /** * Deserialized version of the HandoffRequestMessage proto. */ public record HandoffRequestMessage(int taskId) implements TaskContinuityMessageData { public static HandoffRequestMessage readFromProto(ProtoInputStream pis) throws IOException { int taskId = 0; while (pis.nextField() != ProtoInputStream.NO_MORE_FIELDS) { switch (pis.getFieldNumber()) { case (int) android.companion.HandoffRequestMessage.TASK_ID: taskId = pis.readInt(android.companion.HandoffRequestMessage.TASK_ID); break; } } return new HandoffRequestMessage(taskId); } @Override public void writeToProto(ProtoOutputStream pos) { pos.write(android.companion.HandoffRequestMessage.TASK_ID, taskId()); } } No newline at end of file
services/tests/servicestests/src/com/android/server/companion/datatransfer/continuity/messages/HandoffRequestMessageTest.java 0 → 100644 +77 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.companion.datatransfer.continuity.messages; import static com.google.common.truth.Truth.assertThat; import android.platform.test.annotations.Presubmit; import android.testing.AndroidTestingRunner; import android.util.proto.ProtoInputStream; import android.util.proto.ProtoOutputStream; import org.junit.Test; import org.junit.runner.RunWith; import java.io.IOException; @Presubmit @RunWith(AndroidTestingRunner.class) public class HandoffRequestMessageTest { @Test public void testConstructor_fromTaskId() { int taskId = 1; HandoffRequestMessage handoffRequestMessage = new HandoffRequestMessage(taskId); assertThat(handoffRequestMessage.taskId()).isEqualTo(taskId); } @Test public void testConstructor_fromProto() throws IOException { int taskId = 1; final ProtoOutputStream pos = new ProtoOutputStream(); pos.write(android.companion.HandoffRequestMessage.TASK_ID, taskId); pos.flush(); ProtoInputStream pis = new ProtoInputStream(pos.getBytes()); HandoffRequestMessage handoffRequestMessage = HandoffRequestMessage.readFromProto(pis); assertThat(handoffRequestMessage.taskId()).isEqualTo(taskId); } @Test public void testConstructor_fromProto_noTaskId_returnsZero() throws IOException { final ProtoOutputStream pos = new ProtoOutputStream(); pos.flush(); ProtoInputStream pis = new ProtoInputStream(pos.getBytes()); HandoffRequestMessage handoffRequestMessage = HandoffRequestMessage.readFromProto(pis); assertThat(handoffRequestMessage.taskId()).isEqualTo(0); } @Test public void testWriteAndRead_roundTrip_works() throws IOException { HandoffRequestMessage expectedMessage = new HandoffRequestMessage(1); final ProtoOutputStream pos = new ProtoOutputStream(); expectedMessage.writeToProto(pos); pos.flush(); final ProtoInputStream pis = new ProtoInputStream(pos.getBytes()); final HandoffRequestMessage actualMessage = HandoffRequestMessage.readFromProto(pis); assertThat(actualMessage).isEqualTo(expectedMessage); } } No newline at end of file