summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2018-05-31 02:22:15 -0500
committerandroid-build-team Robot2018-05-31 02:22:15 -0500
commitceff380a26066f3a785bee07653e224d46fd8278 (patch)
tree3645823a00c376dc01c9b3dc3e4680e31b1ee3e9
parent94ee7ca2db43087fcf7f5d329d2592e0ad44bc76 (diff)
parent748ffee591b39b00acdcdecb93a8daa2a455a6d5 (diff)
downloadplatform-packages-services-car-ceff380a26066f3a785bee07653e224d46fd8278.tar.gz
platform-packages-services-car-ceff380a26066f3a785bee07653e224d46fd8278.tar.xz
platform-packages-services-car-ceff380a26066f3a785bee07653e224d46fd8278.zip
Snap for 4813226 from 748ffee591b39b00acdcdecb93a8daa2a455a6d5 to pi-release
Change-Id: Ie1cfcf3bb016b6e58be8dcdc403727884c076f5f
-rw-r--r--service/src/com/android/car/CarAudioService.java3
-rw-r--r--service/src/com/android/car/VmsPublisherService.java408
-rw-r--r--service/src/com/android/car/VmsSubscriberService.java2
3 files changed, 207 insertions, 206 deletions
diff --git a/service/src/com/android/car/CarAudioService.java b/service/src/com/android/car/CarAudioService.java
index 372bbba1..77f0f096 100644
--- a/service/src/com/android/car/CarAudioService.java
+++ b/service/src/com/android/car/CarAudioService.java
@@ -241,7 +241,8 @@ public class CarAudioService extends ICarAudio.Stub implements CarServiceBase {
241 @Override 241 @Override
242 public void dump(PrintWriter writer) { 242 public void dump(PrintWriter writer) {
243 writer.println("*CarAudioService*"); 243 writer.println("*CarAudioService*");
244 writer.println("Run in legacy mode? " + (!mUseDynamicRouting)); 244 writer.println("\tRun in legacy mode? " + (!mUseDynamicRouting));
245 writer.println("\tMaster mute? " + mAudioManager.isMasterMute());
245 // Empty line for comfortable reading 246 // Empty line for comfortable reading
246 writer.println(); 247 writer.println();
247 if (mUseDynamicRouting) { 248 if (mUseDynamicRouting) {
diff --git a/service/src/com/android/car/VmsPublisherService.java b/service/src/com/android/car/VmsPublisherService.java
index 299ca178..a240e171 100644
--- a/service/src/com/android/car/VmsPublisherService.java
+++ b/service/src/com/android/car/VmsPublisherService.java
@@ -16,37 +16,36 @@
16 16
17package com.android.car; 17package com.android.car;
18 18
19import android.annotation.SystemApi;
20import android.car.vms.IVmsPublisherClient; 19import android.car.vms.IVmsPublisherClient;
21import android.car.vms.IVmsPublisherService; 20import android.car.vms.IVmsPublisherService;
22import android.car.vms.IVmsSubscriberClient; 21import android.car.vms.IVmsSubscriberClient;
23import android.car.vms.VmsLayer; 22import android.car.vms.VmsLayer;
24import android.car.vms.VmsLayersOffering; 23import android.car.vms.VmsLayersOffering;
25import android.car.vms.VmsSubscriptionState; 24import android.car.vms.VmsSubscriptionState;
25import android.content.BroadcastReceiver;
26import android.content.ComponentName; 26import android.content.ComponentName;
27import android.content.Context; 27import android.content.Context;
28import android.content.Intent; 28import android.content.Intent;
29import android.content.IntentFilter;
29import android.content.ServiceConnection; 30import android.content.ServiceConnection;
30import android.content.pm.PackageInfo; 31import android.content.pm.PackageInfo;
31import android.content.pm.PackageManager; 32import android.content.pm.PackageManager;
32import android.os.Binder; 33import android.os.Binder;
33import android.os.Handler; 34import android.os.Handler;
34import android.os.IBinder; 35import android.os.IBinder;
36import android.os.Message;
35import android.os.RemoteException; 37import android.os.RemoteException;
36import android.os.UserHandle; 38import android.os.UserHandle;
37import android.text.TextUtils; 39import android.text.TextUtils;
40import android.util.ArrayMap;
41import android.util.ArraySet;
38import android.util.Log; 42import android.util.Log;
39 43
40import com.android.car.hal.VmsHalService; 44import com.android.car.hal.VmsHalService;
41import com.android.internal.annotations.GuardedBy; 45import com.android.car.hal.VmsHalService.VmsHalPublisherListener;
42 46
43import java.io.PrintWriter; 47import java.io.PrintWriter;
44import java.lang.ref.WeakReference;
45import java.util.ArrayList;
46import java.util.Arrays; 48import java.util.Arrays;
47import java.util.HashMap;
48import java.util.HashSet;
49import java.util.List;
50import java.util.Map; 49import java.util.Map;
51import java.util.Set; 50import java.util.Set;
52 51
@@ -54,36 +53,65 @@ import java.util.Set;
54 * Receives HAL updates by implementing VmsHalService.VmsHalListener. 53 * Receives HAL updates by implementing VmsHalService.VmsHalListener.
55 * Binds to publishers and configures them to use this service. 54 * Binds to publishers and configures them to use this service.
56 * Notifies publishers of subscription changes. 55 * Notifies publishers of subscription changes.
57 *
58 * @hide
59 */ 56 */
60@SystemApi 57public class VmsPublisherService extends IVmsPublisherService.Stub implements CarServiceBase {
61public class VmsPublisherService extends IVmsPublisherService.Stub
62 implements CarServiceBase, VmsHalService.VmsHalPublisherListener {
63 private static final boolean DBG = true; 58 private static final boolean DBG = true;
64 private static final String TAG = "VmsPublisherService"; 59 private static final String TAG = "VmsPublisherService";
65 60
61 private static final int MSG_HAL_SUBSCRIPTION_CHANGED = 1;
62
66 private final Context mContext; 63 private final Context mContext;
67 private final VmsHalService mHal; 64 private final VmsHalService mHal;
68 private final VmsPublisherManager mPublisherManager; 65 private final Map<String, PublisherConnection> mPublisherConnectionMap = new ArrayMap<>();
69 private Set<String> mSafePermissions; 66 private final Map<String, IVmsPublisherClient> mPublisherMap = new ArrayMap<>();
67 private final Set<String> mSafePermissions;
68 private final Handler mHandler = new EventHandler();
69 private final VmsHalPublisherListener mHalPublisherListener;
70
71 private BroadcastReceiver mBootCompleteReceiver;
70 72
71 public VmsPublisherService(Context context, VmsHalService hal) { 73 public VmsPublisherService(Context context, VmsHalService hal) {
72 mContext = context; 74 mContext = context;
73 mHal = hal; 75 mHal = hal;
74 mPublisherManager = new VmsPublisherManager(this, context, new Handler()); 76
77 mHalPublisherListener = subscriptionState -> mHandler.sendMessage(
78 mHandler.obtainMessage(MSG_HAL_SUBSCRIPTION_CHANGED, subscriptionState));
79
80 // Load permissions that can be granted to publishers.
81 mSafePermissions = new ArraySet<>(
82 Arrays.asList(mContext.getResources().getStringArray(R.array.vmsSafePermissions)));
75 } 83 }
76 84
77 // Implements CarServiceBase interface. 85 // Implements CarServiceBase interface.
78 @Override 86 @Override
79 public void init() { 87 public void init() {
80 mHal.addPublisherListener(this); 88 mHal.addPublisherListener(mHalPublisherListener);
81 // Load permissions that can be granted to publishers. 89
82 mSafePermissions = new HashSet<>( 90 if (isTestEnvironment()) {
83 Arrays.asList(mContext.getResources().getStringArray(R.array.vmsSafePermissions))); 91 Log.d(TAG, "Running under test environment");
84 // Launch publishers. 92 bindToAllPublishers();
93 } else {
94 mBootCompleteReceiver = new BroadcastReceiver() {
95 @Override
96 public void onReceive(Context context, Intent intent) {
97 if (Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())) {
98 onLockedBootCompleted();
99 } else {
100 Log.e(TAG, "Unexpected action received: " + intent);
101 }
102 }
103 };
104
105 mContext.registerReceiver(mBootCompleteReceiver,
106 new IntentFilter(Intent.ACTION_LOCKED_BOOT_COMPLETED));
107 }
108 }
109
110 private void bindToAllPublishers() {
85 String[] publisherNames = mContext.getResources().getStringArray( 111 String[] publisherNames = mContext.getResources().getStringArray(
86 R.array.vmsPublisherClients); 112 R.array.vmsPublisherClients);
113 if (DBG) Log.d(TAG, "Publishers found: " + publisherNames.length);
114
87 for (String publisherName : publisherNames) { 115 for (String publisherName : publisherNames) {
88 if (TextUtils.isEmpty(publisherName)) { 116 if (TextUtils.isEmpty(publisherName)) {
89 Log.e(TAG, "empty publisher name"); 117 Log.e(TAG, "empty publisher name");
@@ -92,32 +120,48 @@ public class VmsPublisherService extends IVmsPublisherService.Stub
92 ComponentName name = ComponentName.unflattenFromString(publisherName); 120 ComponentName name = ComponentName.unflattenFromString(publisherName);
93 if (name == null) { 121 if (name == null) {
94 Log.e(TAG, "invalid publisher name: " + publisherName); 122 Log.e(TAG, "invalid publisher name: " + publisherName);
123 continue;
95 } 124 }
96 125
97 if (mContext.getPackageManager().isPackageAvailable(name.getPackageName())) { 126 if (!mContext.getPackageManager().isPackageAvailable(name.getPackageName())) {
98 mPublisherManager.bind(name);
99 } else {
100 Log.w(TAG, "VMS publisher not installed: " + publisherName); 127 Log.w(TAG, "VMS publisher not installed: " + publisherName);
128 continue;
101 } 129 }
130
131 bind(name);
102 } 132 }
103 } 133 }
104 134
105 @Override 135 @Override
106 public void release() { 136 public void release() {
107 mPublisherManager.release(); 137 if (mBootCompleteReceiver != null) {
108 mHal.removePublisherListener(this); 138 mContext.unregisterReceiver(mBootCompleteReceiver);
139 mBootCompleteReceiver = null;
140 }
141 mHal.removePublisherListener(mHalPublisherListener);
142
143 for (PublisherConnection connection : mPublisherConnectionMap.values()) {
144 mContext.unbindService(connection);
145 }
146 mPublisherConnectionMap.clear();
147 mPublisherMap.clear();
109 } 148 }
110 149
111 @Override 150 @Override
112 public void dump(PrintWriter writer) { 151 public void dump(PrintWriter writer) {
152 writer.println("*" + getClass().getSimpleName() + "*");
153 writer.println("mSafePermissions: " + mSafePermissions);
154 writer.println("mPublisherMap:" + mPublisherMap);
155 writer.println("mPublisherConnectionMap:" + mPublisherConnectionMap);
113 } 156 }
114 157
158 /* Called in arbitrary binder thread */
115 @Override 159 @Override
116 public void setLayersOffering(IBinder token, VmsLayersOffering offering) { 160 public void setLayersOffering(IBinder token, VmsLayersOffering offering) {
117 mHal.setPublisherLayersOffering(token, offering); 161 mHal.setPublisherLayersOffering(token, offering);
118 } 162 }
119 163
120 // Implements IVmsPublisherService interface. 164 /* Called in arbitrary binder thread */
121 @Override 165 @Override
122 public void publish(IBinder token, VmsLayer layer, int publisherId, byte[] payload) { 166 public void publish(IBinder token, VmsLayer layer, int publisherId, byte[] payload) {
123 if (DBG) { 167 if (DBG) {
@@ -149,27 +193,33 @@ public class VmsPublisherService extends IVmsPublisherService.Stub
149 } 193 }
150 } 194 }
151 195
196 /* Called in arbitrary binder thread */
152 @Override 197 @Override
153 public VmsSubscriptionState getSubscriptions() { 198 public VmsSubscriptionState getSubscriptions() {
154 ICarImpl.assertVmsPublisherPermission(mContext); 199 ICarImpl.assertVmsPublisherPermission(mContext);
155 return mHal.getSubscriptionState(); 200 return mHal.getSubscriptionState();
156 } 201 }
157 202
203 /* Called in arbitrary binder thread */
158 @Override 204 @Override
159 public int getPublisherId(byte[] publisherInfo) { 205 public int getPublisherId(byte[] publisherInfo) {
160 ICarImpl.assertVmsPublisherPermission(mContext); 206 ICarImpl.assertVmsPublisherPermission(mContext);
161 return mHal.getPublisherId(publisherInfo); 207 return mHal.getPublisherId(publisherInfo);
162 } 208 }
163 209
164 // Implements VmsHalListener interface 210 private void onLockedBootCompleted() {
211 if (DBG) Log.i(TAG, "onLockedBootCompleted");
212
213 bindToAllPublishers();
214 }
215
165 /** 216 /**
166 * This method is only invoked by VmsHalService.notifyPublishers which is synchronized. 217 * This method is only invoked by VmsHalService.notifyPublishers which is synchronized.
167 * Therefore this method only sees a non-decreasing sequence. 218 * Therefore this method only sees a non-decreasing sequence.
168 */ 219 */
169 @Override 220 private void handleHalSubscriptionChanged(VmsSubscriptionState subscriptionState) {
170 public void onChange(VmsSubscriptionState subscriptionState) {
171 // Send the message to application listeners. 221 // Send the message to application listeners.
172 for (IVmsPublisherClient client : mPublisherManager.getClients()) { 222 for (IVmsPublisherClient client : mPublisherMap.values()) {
173 try { 223 try {
174 client.onVmsSubscriptionChange(subscriptionState); 224 client.onVmsSubscriptionChange(subscriptionState);
175 } catch (RemoteException ex) { 225 } catch (RemoteException ex) {
@@ -179,202 +229,154 @@ public class VmsPublisherService extends IVmsPublisherService.Stub
179 } 229 }
180 230
181 /** 231 /**
182 * Keeps track of publishers that are using this service. 232 * Tries to bind to a publisher.
233 *
234 * @param name publisher component name (e.g. android.car.vms.logger/.LoggingService).
183 */ 235 */
184 private static class VmsPublisherManager { 236 private void bind(ComponentName name) {
185 /** 237 String publisherName = name.flattenToString();
186 * Allows to modify mPublisherMap and mPublisherConnectionMap as a single unit. 238 if (DBG) {
187 */ 239 Log.d(TAG, "binding to: " + publisherName);
188 private final Object mLock = new Object();
189 @GuardedBy("mLock")
190 private final Map<String, PublisherConnection> mPublisherConnectionMap = new HashMap<>();
191 @GuardedBy("mLock")
192 private final Map<String, IVmsPublisherClient> mPublisherMap = new HashMap<>();
193 private final WeakReference<VmsPublisherService> mPublisherService;
194 private Context mContext;
195 private Handler mHandler;
196
197
198 VmsPublisherManager(
199 VmsPublisherService publisherService, Context context, Handler handler) {
200 if (context == null) {
201 throw new IllegalArgumentException("Context is null");
202 }
203 mPublisherService = new WeakReference<>(publisherService);
204 mContext = context;
205 mHandler = handler;
206 } 240 }
207 241
208 /** 242 if (mPublisherConnectionMap.containsKey(publisherName)) {
209 * Tries to bind to a publisher. 243 // Already registered, nothing to do.
210 * 244 return;
211 * @param name publisher component name (e.g. android.car.vms.logger/.LoggingService).
212 */
213 public void bind(ComponentName name) {
214 VmsPublisherService publisherService = mPublisherService.get();
215 if (publisherService == null) return;
216 String publisherName = name.flattenToString();
217 if (DBG) {
218 Log.d(TAG, "binding to: " + publisherName);
219 }
220 synchronized (mLock) {
221 if (mPublisherConnectionMap.containsKey(publisherName)) {
222 // Already registered, nothing to do.
223 return;
224 }
225 grantPermissions(name);
226 Intent intent = new Intent();
227 intent.setComponent(name);
228 PublisherConnection connection = new PublisherConnection(mContext, mHandler, name);
229 if (publisherService.mContext.bindServiceAsUser(intent, connection,
230 Context.BIND_AUTO_CREATE, UserHandle.SYSTEM)) {
231 mPublisherConnectionMap.put(publisherName, connection);
232 } else {
233 Log.e(TAG, "unable to bind to: " + publisherName);
234 }
235 }
236 } 245 }
237 246 grantPermissions(name);
238 /** 247 Intent intent = new Intent();
239 * Removes the publisher and associated connection. 248 intent.setComponent(name);
240 * 249 PublisherConnection connection = new PublisherConnection(name);
241 * @param name publisher component name (e.g. android.car.vms.Logger). 250 if (mContext.bindServiceAsUser(intent, connection,
242 */ 251 Context.BIND_AUTO_CREATE, UserHandle.SYSTEM)) {
243 public void unbind(ComponentName name) { 252 mPublisherConnectionMap.put(publisherName, connection);
244 VmsPublisherService publisherService = mPublisherService.get(); 253 } else {
245 if (publisherService == null) return; 254 Log.e(TAG, "unable to bind to: " + publisherName);
246 String publisherName = name.flattenToString();
247 if (DBG) {
248 Log.d(TAG, "unbinding from: " + publisherName);
249 }
250 synchronized (mLock) {
251 boolean found = mPublisherMap.remove(publisherName) != null;
252 if (found) {
253 PublisherConnection connection = mPublisherConnectionMap.get(publisherName);
254 publisherService.mContext.unbindService(connection);
255 mPublisherConnectionMap.remove(publisherName);
256 } else {
257 Log.e(TAG, "unbind: unknown publisher." + publisherName);
258 }
259 }
260 } 255 }
256 }
261 257
262 /** 258 /**
263 * Returns the list of publishers currently registered. 259 * Removes the publisher and associated connection.
264 * 260 *
265 * @return list of publishers. 261 * @param name publisher component name (e.g. android.car.vms.Logger).
266 */ 262 */
267 public List<IVmsPublisherClient> getClients() { 263 private void unbind(ComponentName name) {
268 synchronized (mLock) { 264 String publisherName = name.flattenToString();
269 return new ArrayList<>(mPublisherMap.values()); 265 if (DBG) {
270 } 266 Log.d(TAG, "unbinding from: " + publisherName);
271 } 267 }
272 268
273 public void release() { 269 boolean found = mPublisherMap.remove(publisherName) != null;
274 VmsPublisherService publisherService = mPublisherService.get(); 270 if (found) {
275 if (publisherService == null) return; 271 PublisherConnection connection = mPublisherConnectionMap.get(publisherName);
276 for (PublisherConnection connection : mPublisherConnectionMap.values()) { 272 mContext.unbindService(connection);
277 publisherService.mContext.unbindService(connection); 273 mPublisherConnectionMap.remove(publisherName);
278 } 274 } else {
279 mPublisherConnectionMap.clear(); 275 Log.e(TAG, "unbind: unknown publisher." + publisherName);
280 mPublisherMap.clear();
281 } 276 }
277 }
282 278
283 private void grantPermissions(ComponentName component) { 279 private void grantPermissions(ComponentName component) {
284 VmsPublisherService publisherService = mPublisherService.get(); 280 final PackageManager packageManager = mContext.getPackageManager();
285 if (publisherService == null) return; 281 final String packageName = component.getPackageName();
286 final PackageManager packageManager = publisherService.mContext.getPackageManager(); 282 PackageInfo packageInfo;
287 final String packageName = component.getPackageName(); 283 try {
288 PackageInfo packageInfo; 284 packageInfo = packageManager.getPackageInfo(packageName,
289 try { 285 PackageManager.GET_PERMISSIONS);
290 packageInfo = packageManager.getPackageInfo(packageName, 286 } catch (PackageManager.NameNotFoundException e) {
291 PackageManager.GET_PERMISSIONS); 287 Log.e(TAG, "Error getting package info for " + packageName, e);
292 } catch (PackageManager.NameNotFoundException e) { 288 return;
293 Log.e(TAG, "Error getting package info for " + packageName, e); 289 }
294 return; 290 if (packageInfo.requestedPermissions == null) return;
291 for (String permission : packageInfo.requestedPermissions) {
292 if (!mSafePermissions.contains(permission)) {
293 continue;
295 } 294 }
296 if (packageInfo.requestedPermissions == null) return; 295 if (packageManager.checkPermission(permission, packageName)
297 for (String permission : packageInfo.requestedPermissions) { 296 == PackageManager.PERMISSION_GRANTED) {
298 if (!publisherService.mSafePermissions.contains(permission)) { 297 continue;
299 continue; 298 }
300 } 299 try {
301 if (packageManager.checkPermission(permission, packageName) 300 packageManager.grantRuntimePermission(packageName, permission,
302 == PackageManager.PERMISSION_GRANTED) { 301 UserHandle.SYSTEM);
303 continue; 302 Log.d(TAG, "Permission " + permission + " granted to " + packageName);
304 } 303 } catch (SecurityException | IllegalArgumentException e) {
305 try { 304 Log.e(TAG, "Error while trying to grant " + permission + " to " + packageName,
306 packageManager.grantRuntimePermission(packageName, permission, 305 e);
307 UserHandle.SYSTEM);
308 Log.d(TAG, "Permission " + permission + " granted to " + packageName);
309 } catch (SecurityException | IllegalArgumentException e) {
310 Log.e(TAG, "Error while trying to grant " + permission + " to " + packageName,
311 e);
312 }
313 } 306 }
314 } 307 }
308 }
315 309
316 class PublisherConnection implements ServiceConnection { 310 private boolean isTestEnvironment() {
311 // If the context is derived from other package it means we're running under
312 // environment.
313 return !TextUtils.equals(mContext.getBasePackageName(), mContext.getPackageName());
314 }
315
316 class PublisherConnection implements ServiceConnection {
317 private final IBinder mToken = new Binder();
318 private final ComponentName mName;
317 319
318 private final Context mContext; 320 PublisherConnection(ComponentName name) {
319 private final IBinder mToken = new Binder(); 321 mName = name;
320 private final ComponentName mName; 322 }
321 private final Handler mHandler;
322 323
323 PublisherConnection(Context context, Handler handler, ComponentName name) { 324 private final Runnable mBindRunnable = new Runnable() {
324 mContext = context; 325 @Override
325 mHandler = handler; 326 public void run() {
326 mName = name; 327 Log.d(TAG, "delayed binding for: " + mName);
328 bind(mName);
327 } 329 }
330 };
328 331
329 private final Runnable mBindRunnable = new Runnable() { 332 /**
330 @Override 333 * Once the service binds to a publisher service, the publisher binder is added to
331 public void run() { 334 * mPublisherMap
332 Log.d(TAG, "delayed binding for: " + mName); 335 * and the publisher is configured to use this service.
333 VmsPublisherManager.this.bind(mName); 336 */
334 } 337 @Override
335 }; 338 public void onServiceConnected(ComponentName name, IBinder binder) {
339 if (DBG) {
340 Log.d(TAG, "onServiceConnected, name: " + name + ", binder: " + binder);
341 }
342 IVmsPublisherClient service = IVmsPublisherClient.Stub.asInterface(binder);
343 mPublisherMap.put(name.flattenToString(), service);
344 try {
345 service.setVmsPublisherService(mToken, VmsPublisherService.this);
346 } catch (RemoteException e) {
347 Log.e(TAG, "unable to configure publisher: " + name, e);
348 }
349 }
336 350
337 /** 351 /**
338 * Once the service binds to a publisher service, the publisher binder is added to 352 * Tries to rebind to the publisher service.
339 * mPublisherMap 353 */
340 * and the publisher is configured to use this service. 354 @Override
341 */ 355 public void onServiceDisconnected(ComponentName name) {
342 @Override 356 String publisherName = name.flattenToString();
343 public void onServiceConnected(ComponentName name, IBinder binder) { 357 Log.d(TAG, "onServiceDisconnected, name: " + publisherName);
344 VmsPublisherService publisherService = mPublisherService.get(); 358
345 if (publisherService == null) return; 359 int millisecondsToWait = mContext.getResources().getInteger(
346 if (DBG) { 360 com.android.car.R.integer.millisecondsBeforeRebindToVmsPublisher);
347 Log.d(TAG, "onServiceConnected, name: " + name + ", binder: " + binder); 361 if (!mName.flattenToString().equals(name.flattenToString())) {
348 } 362 throw new IllegalArgumentException(
349 IVmsPublisherClient service = IVmsPublisherClient.Stub.asInterface(binder); 363 "Mismatch on publisherConnection. Expected: " + mName + " Got: " + name);
350 synchronized (mLock) {
351 mPublisherMap.put(name.flattenToString(), service);
352 }
353 try {
354 service.setVmsPublisherService(mToken, publisherService);
355 } catch (RemoteException e) {
356 Log.e(TAG, "unable to configure publisher: " + name, e);
357 }
358 } 364 }
365 mHandler.postDelayed(mBindRunnable, millisecondsToWait);
359 366
360 /** 367 unbind(name);
361 * Tries to rebind to the publisher service. 368 }
362 */ 369 }
363 @Override
364 public void onServiceDisconnected(ComponentName name) {
365 String publisherName = name.flattenToString();
366 Log.d(TAG, "onServiceDisconnected, name: " + publisherName);
367
368 int millisecondsToWait = mContext.getResources().getInteger(
369 com.android.car.R.integer.millisecondsBeforeRebindToVmsPublisher);
370 if (!mName.flattenToString().equals(name.flattenToString())) {
371 throw new IllegalArgumentException(
372 "Mismatch on publisherConnection. Expected: " + mName + " Got: " + name);
373 }
374 mHandler.postDelayed(mBindRunnable, millisecondsToWait);
375 370
376 VmsPublisherManager.this.unbind(name); 371 private class EventHandler extends Handler {
372 @Override
373 public void handleMessage(Message msg) {
374 switch (msg.what) {
375 case MSG_HAL_SUBSCRIPTION_CHANGED:
376 handleHalSubscriptionChanged((VmsSubscriptionState) msg.obj);
377 return;
377 } 378 }
379 super.handleMessage(msg);
378 } 380 }
379 } 381 }
380} 382}
diff --git a/service/src/com/android/car/VmsSubscriberService.java b/service/src/com/android/car/VmsSubscriberService.java
index e86690df..c4c507ee 100644
--- a/service/src/com/android/car/VmsSubscriberService.java
+++ b/service/src/com/android/car/VmsSubscriberService.java
@@ -16,7 +16,6 @@
16 16
17package com.android.car; 17package com.android.car;
18 18
19import android.annotation.SystemApi;
20import android.car.Car; 19import android.car.Car;
21import android.car.vms.IVmsSubscriberClient; 20import android.car.vms.IVmsSubscriberClient;
22import android.car.vms.IVmsSubscriberService; 21import android.car.vms.IVmsSubscriberService;
@@ -42,7 +41,6 @@ import java.util.Set;
42 * + Receives HAL updates by implementing VmsHalService.VmsHalListener. 41 * + Receives HAL updates by implementing VmsHalService.VmsHalListener.
43 * + Offers subscriber/publisher services by implementing IVmsService.Stub. 42 * + Offers subscriber/publisher services by implementing IVmsService.Stub.
44 */ 43 */
45@SystemApi
46public class VmsSubscriberService extends IVmsSubscriberService.Stub 44public class VmsSubscriberService extends IVmsSubscriberService.Stub
47 implements CarServiceBase, VmsHalService.VmsHalSubscriberListener { 45 implements CarServiceBase, VmsHalService.VmsHalSubscriberListener {
48 private static final boolean DBG = true; 46 private static final boolean DBG = true;