Adding getPublisherId/getPublisherInfo support to HAL implementation.

Bug: 123767230
Test: Added tests for new messages to CarServiceUnitTest:VmsHalServiceTest
Test: atest AndroidCarApiTest AndroidSupportCarApiTest CarServiceTest CarServiceUnitTest
Change-Id: Id8ab144d1064ff764ebdec694748e6733dad173b
(cherry picked from commit 4e4d216643f316053f360983016a6ab8fd6eb9fc)
diff --git a/service/src/com/android/car/hal/VmsHalService.java b/service/src/com/android/car/hal/VmsHalService.java
index eaaecc2..1f6c2e2 100644
--- a/service/src/com/android/car/hal/VmsHalService.java
+++ b/service/src/com/android/car/hal/VmsHalService.java
@@ -39,6 +39,7 @@
 import android.hardware.automotive.vehicle.V2_0.VmsMessageWithLayerAndPublisherIdIntegerValuesIndex;
 import android.hardware.automotive.vehicle.V2_0.VmsMessageWithLayerIntegerValuesIndex;
 import android.hardware.automotive.vehicle.V2_0.VmsOfferingMessageIntegerValuesIndex;
+import android.hardware.automotive.vehicle.V2_0.VmsPublisherInformationIntegerValuesIndex;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
@@ -315,6 +316,11 @@
                     case VmsMessageType.UNSUBSCRIBE_TO_PUBLISHER:
                         handleUnsubscribeFromPublisherEvent(vec);
                         break;
+                    case VmsMessageType.PUBLISHER_ID_REQUEST:
+                        handlePublisherIdRequest(toByteArray(v.value.bytes));
+                        break;
+                    case VmsMessageType.PUBLISHER_INFORMATION_REQUEST:
+                        handlePublisherInfoRequest(vec);
                     case VmsMessageType.OFFERING:
                         handleOfferingEvent(vec);
                         break;
@@ -429,6 +435,57 @@
     }
 
     /**
+     * PUBLISHER_ID_REQUEST message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher info (bytes)
+     * </ul>
+     *
+     * PUBLISHER_ID_RESPONSE message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher ID
+     * </ul>
+     */
+    private void handlePublisherIdRequest(byte[] payload)
+            throws RemoteException {
+        if (DBG) Log.d(TAG, "Handling a publisher id request event");
+
+        VehiclePropValue vehicleProp = createVmsMessage(VmsMessageType.PUBLISHER_ID_RESPONSE);
+        // Publisher ID
+        vehicleProp.value.int32Values.add(mPublisherService.getPublisherId(payload));
+
+        setPropertyValue(vehicleProp);
+    }
+
+
+    /**
+     * PUBLISHER_INFORMATION_REQUEST message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher ID
+     * </ul>
+     *
+     * PUBLISHER_INFORMATION_RESPONSE message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher info (bytes)
+     * </ul>
+     */
+    private void handlePublisherInfoRequest(List<Integer> message)
+            throws RemoteException {
+        if (DBG) Log.d(TAG, "Handling a publisher info request event");
+        int publisherId = message.get(VmsPublisherInformationIntegerValuesIndex.PUBLISHER_ID);
+
+        VehiclePropValue vehicleProp =
+                createVmsMessage(VmsMessageType.PUBLISHER_INFORMATION_RESPONSE);
+        // Publisher Info
+        appendBytes(vehicleProp.value.bytes, mSubscriberService.getPublisherInfo(publisherId));
+
+        setPropertyValue(vehicleProp);
+    }
+
+    /**
      * OFFERING message format:
      * <ul>
      * <li>Message type
@@ -555,11 +612,7 @@
         message.add(publisherId);
 
         // Payload
-        ArrayList<Byte> messagePayload = vehicleProp.value.bytes;
-        messagePayload.ensureCapacity(payload.length);
-        for (byte b : payload) {
-            messagePayload.add(b);
-        }
+        appendBytes(vehicleProp.value.bytes, payload);
         return vehicleProp;
     }
 
@@ -713,6 +766,13 @@
         }
     }
 
+    private static void appendBytes(ArrayList<Byte> dst, byte[] src) {
+        dst.ensureCapacity(src.length);
+        for (byte b : src) {
+            dst.add(b);
+        }
+    }
+
     private static VmsLayer parseVmsLayerFromMessage(List<Integer> message) {
         return parseVmsLayerAtIndex(message,
                 VmsMessageWithLayerIntegerValuesIndex.LAYER_TYPE);
diff --git a/tests/carservice_unit_test/src/com/android/car/hal/VmsHalServiceTest.java b/tests/carservice_unit_test/src/com/android/car/hal/VmsHalServiceTest.java
index 603b329..baaab26 100644
--- a/tests/carservice_unit_test/src/com/android/car/hal/VmsHalServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/hal/VmsHalServiceTest.java
@@ -63,8 +63,7 @@
     private static final VmsLayer LAYER = new VmsLayer(LAYER_TYPE, LAYER_SUBTYPE, LAYER_VERSION);
     private static final int PUBLISHER_ID = 12345;
     private static final byte[] PAYLOAD = new byte[]{1, 2, 3, 4};
-    private static final List<Byte> PAYLOAD_AS_LIST = Arrays.asList(
-            new Byte[]{1, 2, 3, 4});
+    private static final List<Byte> PAYLOAD_AS_LIST = Arrays.asList(new Byte[]{1, 2, 3, 4});
 
     @Rule
     public MockitoRule mockito = MockitoJUnit.rule();
@@ -233,6 +232,68 @@
     }
 
     /**
+     * PUBLISHER_ID_REQUEST message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher info (bytes)
+     * </ul>
+     *
+     * PUBLISHER_ID_RESPONSE message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher ID
+     * </ul>
+     */
+    @Test
+    public void testHandlePublisherIdRequestEvent() throws Exception {
+        VehiclePropValue request = createHalMessage(
+                VmsMessageType.PUBLISHER_ID_REQUEST  // Message type
+        );
+        request.value.bytes.addAll(PAYLOAD_AS_LIST);
+
+        when(mPublisherService.getPublisherId(PAYLOAD)).thenReturn(PUBLISHER_ID);
+
+        VehiclePropValue response = createHalMessage(
+                VmsMessageType.PUBLISHER_ID_RESPONSE,  // Message type
+                PUBLISHER_ID                           // Publisher ID
+        );
+
+        sendHalMessage(request);
+        verify(mVehicleHal).set(response);
+    }
+
+    /**
+     * PUBLISHER_INFORMATION_REQUEST message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher ID
+     * </ul>
+     *
+     * PUBLISHER_INFORMATION_RESPONSE message format:
+     * <ul>
+     * <li>Message type
+     * <li>Publisher info (bytes)
+     * </ul>
+     */
+    @Test
+    public void testHandlePublisherInformationRequestEvent() throws Exception {
+        VehiclePropValue request = createHalMessage(
+                VmsMessageType.PUBLISHER_INFORMATION_REQUEST,  // Message type
+                PUBLISHER_ID                                   // Publisher ID
+        );
+
+        when(mSubscriberService.getPublisherInfo(PUBLISHER_ID)).thenReturn(PAYLOAD);
+
+        VehiclePropValue response = createHalMessage(
+                VmsMessageType.PUBLISHER_INFORMATION_RESPONSE  // Message type
+        );
+        response.value.bytes.addAll(PAYLOAD_AS_LIST);
+
+        sendHalMessage(request);
+        verify(mVehicleHal).set(response);
+    }
+
+    /**
      * OFFERING message format:
      * <ul>
      * <li>Message type