Register VmsPublisherService with VmsClientManager on construction time.
It is not necessary to defer to init() time, and this ensures the
publisher service is ready when the HAL client initializes.
Bug: 134708512
Test: atest AndroidCarApiTest CarServiceTest CarServiceUnitTest
Change-Id: I204844a0dbfe9bca560b4fcf0afcca46289301c6
diff --git a/service/src/com/android/car/VmsPublisherService.java b/service/src/com/android/car/VmsPublisherService.java
index 3384e3a..647b102 100644
--- a/service/src/com/android/car/VmsPublisherService.java
+++ b/service/src/com/android/car/VmsPublisherService.java
@@ -119,16 +119,14 @@
mContext = context;
mClientManager = clientManager;
mBrokerService = brokerService;
- }
-
- @Override
- public void init() {
mClientManager.registerConnectionListener(this);
}
@Override
+ public void init() {}
+
+ @Override
public void release() {
- mClientManager.unregisterConnectionListener(this);
mPublisherProxies.values().forEach(PublisherProxy::unregister);
mPublisherProxies.clear();
}
diff --git a/tests/carservice_unit_test/src/com/android/car/VmsPublisherServiceTest.java b/tests/carservice_unit_test/src/com/android/car/VmsPublisherServiceTest.java
index 2c63ef5..d65bc12 100644
--- a/tests/carservice_unit_test/src/com/android/car/VmsPublisherServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/VmsPublisherServiceTest.java
@@ -108,6 +108,8 @@
@Before
public void setUp() {
mPublisherService = new VmsPublisherService(mContext, mBrokerService, mClientManager);
+ verify(mClientManager).registerConnectionListener(mPublisherService);
+
mPublisherClient = new MockPublisherClient();
mPublisherClient2 = new MockPublisherClient();
when(mBrokerService.getSubscribersForLayerFromPublisher(LAYER, PUBLISHER_ID))
@@ -118,7 +120,6 @@
@Test
public void testInit() {
mPublisherService.init();
- verify(mClientManager).registerConnectionListener(mPublisherService);
}
@Test
@@ -637,7 +638,6 @@
@Test
public void testRelease() {
mPublisherService.release();
- verify(mClientManager).unregisterConnectionListener(mPublisherService);
}
private class MockPublisherClient extends IVmsPublisherClient.Stub {