blob: b6ae91ae22c7e99d07777b61f246c7755e42c54a [file] [log] [blame]
keunyounge18e25d2015-08-28 15:57:19 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.car.vehiclenetwork;
17
18import android.annotation.Nullable;
19import android.os.Handler;
20import android.os.Looper;
21import android.os.Message;
22import android.os.RemoteException;
23import android.os.ServiceManager;
24import android.util.Log;
25
keunyoungd32f4e62015-09-21 11:33:06 -070026import com.android.car.vehiclenetwork.VehicleNetworkConsts.VehicleValueType;
keunyounge18e25d2015-08-28 15:57:19 -070027import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropConfigs;
28import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValue;
29import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValues;
keunyoung1ab8e182015-09-24 09:25:22 -070030import com.android.internal.annotations.GuardedBy;
keunyounge18e25d2015-08-28 15:57:19 -070031
32import java.lang.ref.WeakReference;
33
34/**
35 * System API to access Vehicle network. This is only for system services and applications should
keunyoung15882e52015-09-16 16:57:58 -070036 * not use this. All APIs will fail with security error if normal app tries this.
keunyounge18e25d2015-08-28 15:57:19 -070037 */
38public class VehicleNetwork {
keunyoung1ab8e182015-09-24 09:25:22 -070039 /**
40 * Listener for VNS events.
41 */
keunyounge18e25d2015-08-28 15:57:19 -070042 public interface VehicleNetworkListener {
keunyoung1ab8e182015-09-24 09:25:22 -070043 /**
44 * Notify HAL events. This requires subscribing the property
45 */
keunyounge18e25d2015-08-28 15:57:19 -070046 void onVehicleNetworkEvents(VehiclePropValues values);
47 }
48
keunyoung1ab8e182015-09-24 09:25:22 -070049 public interface VehicleNetworkHalMock {
50 VehiclePropConfigs onListProperties();
51 void onPropertySet(VehiclePropValue value);
keunyoung7d74e6d2015-10-14 15:43:10 -070052 VehiclePropValue onPropertyGet(VehiclePropValue property);
keunyoung1ab8e182015-09-24 09:25:22 -070053 void onPropertySubscribe(int property, int sampleRate);
54 void onPropertyUnsubscribe(int property);
55 }
56
keunyounge18e25d2015-08-28 15:57:19 -070057 private static final String TAG = VehicleNetwork.class.getSimpleName();
58
59 private final IVehicleNetwork mService;
60 private final VehicleNetworkListener mListener;
61 private final IVehicleNetworkListenerImpl mVehicleNetworkListener;
62 private final EventHandler mEventHandler;
63
keunyoung1ab8e182015-09-24 09:25:22 -070064 @GuardedBy("this")
65 private VehicleNetworkHalMock mHalMock;
66 private IVehicleNetworkHalMock mHalMockImpl;
67
keunyoung217ca352015-11-17 14:45:38 -080068 private static final int VNS_CONNECT_MAX_RETRY = 10;
69 private static final long VNS_RETRY_WAIT_TIME_MS = 1000;
70
keunyoung5c7cb262015-10-19 10:47:45 -070071 /**
72 * Factory method to create VehicleNetwork
73 * @param listener listener for listening events
74 * @param looper Looper to dispatch listener events
75 * @return
76 */
keunyoung15882e52015-09-16 16:57:58 -070077 public static VehicleNetwork createVehicleNetwork(VehicleNetworkListener listener,
78 Looper looper) {
keunyoung217ca352015-11-17 14:45:38 -080079 int retryCount = 0;
80 IVehicleNetwork service = null;
81 while (service == null) {
82 service = IVehicleNetwork.Stub.asInterface(ServiceManager.getService(
83 IVehicleNetwork.class.getCanonicalName()));
84 retryCount++;
85 if (retryCount > VNS_CONNECT_MAX_RETRY) {
86 break;
87 }
88 try {
89 Thread.sleep(VNS_RETRY_WAIT_TIME_MS);
90 } catch (InterruptedException e) {
91 //ignore
92 }
93 }
keunyounge18e25d2015-08-28 15:57:19 -070094 if (service == null) {
keunyoung15882e52015-09-16 16:57:58 -070095 throw new RuntimeException("Vehicle network service not available:" +
96 IVehicleNetwork.class.getCanonicalName());
keunyounge18e25d2015-08-28 15:57:19 -070097 }
98 return new VehicleNetwork(service, listener, looper);
99 }
100
101 private VehicleNetwork(IVehicleNetwork service, VehicleNetworkListener listener,
102 Looper looper) {
103 mService = service;
104 mListener = listener;
105 mEventHandler = new EventHandler(looper);
106 mVehicleNetworkListener = new IVehicleNetworkListenerImpl(this);
107 }
108
keunyoung5c7cb262015-10-19 10:47:45 -0700109 /**
110 * List all properties from vehicle HAL
111 * @return all properties
112 */
keunyoung15882e52015-09-16 16:57:58 -0700113 public VehiclePropConfigs listProperties() {
114 return listProperties(0 /* all */);
115 }
116
keunyoung5c7cb262015-10-19 10:47:45 -0700117 /**
118 * Return configuration information of single property
119 * @param property vehicle property number defined in {@link VehicleNetworkConsts}. 0 has
120 * has special meaning of list all properties.
121 * @return null if given property does not exist.
122 */
keunyounge18e25d2015-08-28 15:57:19 -0700123 public VehiclePropConfigs listProperties(int property) {
124 try {
125 VehiclePropConfigsParcelable parcelable = mService.listProperties(property);
126 if (parcelable != null) {
127 return parcelable.configs;
128 }
129 } catch (RemoteException e) {
130 handleRemoteException(e);
131 }
132 return null;
133 }
134
keunyoung5c7cb262015-10-19 10:47:45 -0700135 /**
136 * Set property which will lead into writing the value to vehicle HAL.
137 * @param value
138 * @throws IllegalArgumentException If value set has wrong value like wrong valueType,
139 * wrong data, and etc.
140 */
141 public void setProperty(VehiclePropValue value) throws IllegalArgumentException {
keunyounge18e25d2015-08-28 15:57:19 -0700142 VehiclePropValueParcelable parcelable = new VehiclePropValueParcelable(value);
143 try {
keunyoung15882e52015-09-16 16:57:58 -0700144 mService.setProperty(parcelable);
keunyounge18e25d2015-08-28 15:57:19 -0700145 } catch (RemoteException e) {
146 handleRemoteException(e);
147 }
keunyounge18e25d2015-08-28 15:57:19 -0700148 }
149
keunyoung5c7cb262015-10-19 10:47:45 -0700150 /**
151 * Set integer type property
152 * @param property
153 * @param value
154 * @throws IllegalArgumentException For type mismatch (=the property is not int type)
155 */
156 public void setIntProperty(int property, int value) throws IllegalArgumentException {
keunyoung1ab8e182015-09-24 09:25:22 -0700157 VehiclePropValue v = VehiclePropValueUtil.createIntValue(property, value, 0);
keunyoungfe30ba02015-09-17 17:56:35 -0700158 setProperty(v);
159 }
160
keunyoung5c7cb262015-10-19 10:47:45 -0700161 /**
162 * Set int vector type property. Length of passed values should match with vector length.
163 * @param property
164 * @param values
165 * @throws IllegalArgumentException
166 */
167 public void setIntVectorProperty(int property, int[] values) throws IllegalArgumentException {
keunyoung1ab8e182015-09-24 09:25:22 -0700168 VehiclePropValue v = VehiclePropValueUtil.createIntVectorValue(property, values, 0);
169 setProperty(v);
keunyoungd32f4e62015-09-21 11:33:06 -0700170 }
171
keunyoung5c7cb262015-10-19 10:47:45 -0700172 /**
173 * Set long type property.
174 * @param property
175 * @param value
176 * @throws IllegalArgumentException
177 */
178 public void setLongProperty(int property, long value) throws IllegalArgumentException {
keunyoung1ab8e182015-09-24 09:25:22 -0700179 VehiclePropValue v = VehiclePropValueUtil.createLongValue(property, value, 0);
keunyoungfe30ba02015-09-17 17:56:35 -0700180 setProperty(v);
181 }
182
keunyoung5c7cb262015-10-19 10:47:45 -0700183 /**
184 * Set float type property.
185 * @param property
186 * @param value
187 * @throws IllegalArgumentException
188 */
189 public void setFloatProperty(int property, float value) throws IllegalArgumentException {
keunyoung1ab8e182015-09-24 09:25:22 -0700190 VehiclePropValue v = VehiclePropValueUtil.createFloatValue(property, value, 0);
keunyoungfe30ba02015-09-17 17:56:35 -0700191 setProperty(v);
192 }
193
keunyoung5c7cb262015-10-19 10:47:45 -0700194 /**
195 * Set float vector type property. Length of values should match with vector length.
196 * @param property
197 * @param values
198 * @throws IllegalArgumentException
199 */
200 public void setFloatVectorProperty(int property, float[] values)
201 throws IllegalArgumentException {
keunyoung1ab8e182015-09-24 09:25:22 -0700202 VehiclePropValue v = VehiclePropValueUtil.createFloatVectorValue(property, values, 0);
203 setProperty(v);
keunyoungd32f4e62015-09-21 11:33:06 -0700204 }
205
keunyoung5c7cb262015-10-19 10:47:45 -0700206 /**
207 * Get property. This can be used for a property which does not require any other data.
208 * @param property
209 * @return
210 * @throws IllegalArgumentException
211 */
212 public VehiclePropValue getProperty(int property) throws IllegalArgumentException {
keunyoung7d74e6d2015-10-14 15:43:10 -0700213 int valueType = VehicleNetworkConsts.getVehicleValueType(property);
214 VehiclePropValue value = VehiclePropValueUtil.createBuilder(property, valueType, 0).build();
215 return getProperty(value);
216 }
217
keunyoung5c7cb262015-10-19 10:47:45 -0700218 /**
219 * Generic get method for any type of property. Some property may require setting data portion
220 * as get may return different result depending on the data set.
221 * @param value
222 * @return
223 * @throws IllegalArgumentException
224 */
225 public VehiclePropValue getProperty(VehiclePropValue value) throws IllegalArgumentException {
keunyoung7d74e6d2015-10-14 15:43:10 -0700226 VehiclePropValueParcelable parcelable = new VehiclePropValueParcelable(value);
keunyounge18e25d2015-08-28 15:57:19 -0700227 try {
keunyoung7d74e6d2015-10-14 15:43:10 -0700228 VehiclePropValueParcelable resParcelable = mService.getProperty(parcelable);
229 if (resParcelable != null) {
230 return resParcelable.value;
keunyounge18e25d2015-08-28 15:57:19 -0700231 }
232 } catch (RemoteException e) {
233 handleRemoteException(e);
234 }
235 return null;
236 }
237
keunyoung5c7cb262015-10-19 10:47:45 -0700238 /**
239 * get int type property
240 * @param property
241 * @return
242 * @throws IllegalArgumentException
243 */
244 public int getIntProperty(int property) throws IllegalArgumentException {
keunyoungfe30ba02015-09-17 17:56:35 -0700245 VehiclePropValue v = getProperty(property);
246 if (v == null) {
keunyoungd32f4e62015-09-21 11:33:06 -0700247 // if property is invalid, IllegalArgumentException should have been thrown
248 // from getProperty.
keunyoungfe30ba02015-09-17 17:56:35 -0700249 throw new IllegalStateException();
250 }
keunyoungd32f4e62015-09-21 11:33:06 -0700251 if (v.getValueType() != VehicleValueType.VEHICLE_VALUE_TYPE_INT32) {
keunyoungfe30ba02015-09-17 17:56:35 -0700252 throw new IllegalArgumentException();
253 }
keunyoungd32f4e62015-09-21 11:33:06 -0700254 if (v.getInt32ValuesCount() != 1) {
255 throw new IllegalStateException();
256 }
257 return v.getInt32Values(0);
258 }
259
keunyoung5c7cb262015-10-19 10:47:45 -0700260 /**
261 * get int vector type property. Length of values should match vector length.
262 * @param property
keunyoung5c7cb262015-10-19 10:47:45 -0700263 * @throws IllegalArgumentException
264 */
keunyoung4b0212c2015-10-29 17:11:57 -0700265 public int[] getIntVectorProperty(int property) throws IllegalArgumentException {
keunyoungd32f4e62015-09-21 11:33:06 -0700266 VehiclePropValue v = getProperty(property);
267 if (v == null) {
268 // if property is invalid, IllegalArgumentException should have been thrown
269 // from getProperty.
270 throw new IllegalStateException();
271 }
272 switch (v.getValueType()) {
273 case VehicleValueType.VEHICLE_VALUE_TYPE_INT32_VEC2:
274 case VehicleValueType.VEHICLE_VALUE_TYPE_INT32_VEC3:
275 case VehicleValueType.VEHICLE_VALUE_TYPE_INT32_VEC4:
keunyoungd32f4e62015-09-21 11:33:06 -0700276 break;
277 default:
278 throw new IllegalArgumentException();
279 }
keunyoung4b0212c2015-10-29 17:11:57 -0700280 int[] values = new int[v.getValueType() - VehicleValueType.VEHICLE_VALUE_TYPE_INT32_VEC2 +
281 2];
keunyoungd32f4e62015-09-21 11:33:06 -0700282 if (v.getInt32ValuesCount() != values.length) {
283 throw new IllegalStateException();
284 }
285 for (int i = 0; i < values.length; i++) {
286 values[i] = v.getInt32Values(i);
287 }
keunyoung4b0212c2015-10-29 17:11:57 -0700288 return values;
keunyoungfe30ba02015-09-17 17:56:35 -0700289 }
290
keunyoung5c7cb262015-10-19 10:47:45 -0700291 /**
292 * Get float type property.
293 * @param property
294 * @return
295 * @throws IllegalArgumentException
296 */
297 public float getFloatProperty(int property) throws IllegalArgumentException {
keunyoungfe30ba02015-09-17 17:56:35 -0700298 VehiclePropValue v = getProperty(property);
299 if (v == null) {
300 throw new IllegalStateException();
301 }
keunyoungd32f4e62015-09-21 11:33:06 -0700302 if (v.getValueType() != VehicleValueType.VEHICLE_VALUE_TYPE_FLOAT) {
keunyoungfe30ba02015-09-17 17:56:35 -0700303 throw new IllegalArgumentException();
304 }
keunyoungd32f4e62015-09-21 11:33:06 -0700305 if (v.getFloatValuesCount() != 1) {
306 throw new IllegalStateException();
307 }
308 return v.getFloatValues(0);
309 }
310
keunyoung5c7cb262015-10-19 10:47:45 -0700311 /**
312 * Get float vector type property. Length of values should match vector's length.
313 * @param property
keunyoung5c7cb262015-10-19 10:47:45 -0700314 * @throws IllegalArgumentException
315 */
keunyoung4b0212c2015-10-29 17:11:57 -0700316 public float[] getFloatVectorProperty(int property)
keunyoung5c7cb262015-10-19 10:47:45 -0700317 throws IllegalArgumentException {
keunyoungd32f4e62015-09-21 11:33:06 -0700318 VehiclePropValue v = getProperty(property);
319 if (v == null) {
320 // if property is invalid, IllegalArgumentException should have been thrown
321 // from getProperty.
322 throw new IllegalStateException();
323 }
324 switch (v.getValueType()) {
325 case VehicleValueType.VEHICLE_VALUE_TYPE_FLOAT_VEC2:
326 case VehicleValueType.VEHICLE_VALUE_TYPE_FLOAT_VEC3:
327 case VehicleValueType.VEHICLE_VALUE_TYPE_FLOAT_VEC4:
keunyoungd32f4e62015-09-21 11:33:06 -0700328 break;
329 default:
330 throw new IllegalArgumentException();
331 }
keunyoung4b0212c2015-10-29 17:11:57 -0700332 float[] values = new float[v.getValueType() -
333 VehicleValueType.VEHICLE_VALUE_TYPE_FLOAT_VEC2 + 2];
keunyoungd32f4e62015-09-21 11:33:06 -0700334 if (v.getFloatValuesCount() != values.length) {
335 throw new IllegalStateException();
336 }
337 for (int i = 0; i < values.length; i++) {
338 values[i] = v.getFloatValues(i);
339 }
keunyoung4b0212c2015-10-29 17:11:57 -0700340 return values;
keunyoungfe30ba02015-09-17 17:56:35 -0700341 }
342
keunyoung5c7cb262015-10-19 10:47:45 -0700343 /**
344 * Get long type property.
345 * @param property
346 * @return
347 * @throws IllegalArgumentException
348 */
349 public long getLongProperty(int property) throws IllegalArgumentException {
keunyoungfe30ba02015-09-17 17:56:35 -0700350 VehiclePropValue v = getProperty(property);
351 if (v == null) {
352 throw new IllegalStateException();
353 }
keunyoungd32f4e62015-09-21 11:33:06 -0700354 if (v.getValueType() != VehicleValueType.VEHICLE_VALUE_TYPE_INT64) {
keunyoungfe30ba02015-09-17 17:56:35 -0700355 throw new IllegalArgumentException();
356 }
357 return v.getInt64Value();
358 }
359
keunyoung5c7cb262015-10-19 10:47:45 -0700360 /**
361 * Get string type property.
362 * @param property
363 * @return
364 * @throws IllegalArgumentException
365 */
keunyoungfe30ba02015-09-17 17:56:35 -0700366 //TODO check UTF8 to java string conversion
keunyoung5c7cb262015-10-19 10:47:45 -0700367 public String getStringProperty(int property) throws IllegalArgumentException {
keunyoungfe30ba02015-09-17 17:56:35 -0700368 VehiclePropValue v = getProperty(property);
369 if (v == null) {
370 throw new IllegalStateException();
371 }
keunyoungd32f4e62015-09-21 11:33:06 -0700372 if (v.getValueType() != VehicleValueType.VEHICLE_VALUE_TYPE_STRING) {
keunyoungfe30ba02015-09-17 17:56:35 -0700373 throw new IllegalArgumentException();
374 }
375 return v.getStringValue();
376 }
377
keunyoung5c7cb262015-10-19 10:47:45 -0700378 /**
379 * Subscribe given property with given sample rate.
380 * @param property
381 * @param sampleRate
382 * @throws IllegalArgumentException
383 */
384 public void subscribe(int property, float sampleRate) throws IllegalArgumentException {
keunyounge18e25d2015-08-28 15:57:19 -0700385 try {
keunyoung15882e52015-09-16 16:57:58 -0700386 mService.subscribe(mVehicleNetworkListener, property, sampleRate);
keunyounge18e25d2015-08-28 15:57:19 -0700387 } catch (RemoteException e) {
388 handleRemoteException(e);
389 }
keunyounge18e25d2015-08-28 15:57:19 -0700390 }
391
keunyoung5c7cb262015-10-19 10:47:45 -0700392 /**
393 * Stop subscribing the property.
394 * @param property
395 */
keunyounge18e25d2015-08-28 15:57:19 -0700396 public void unsubscribe(int property) {
397 try {
398 mService.unsubscribe(mVehicleNetworkListener, property);
399 } catch (RemoteException e) {
400 handleRemoteException(e);
401 }
402 }
403
keunyoung5c7cb262015-10-19 10:47:45 -0700404 /**
405 * Inject given value to all clients subscribing the property. This is for testing.
406 * @param value
407 */
keunyoung1ab8e182015-09-24 09:25:22 -0700408 public synchronized void injectEvent(VehiclePropValue value) {
409 try {
410 mService.injectEvent(new VehiclePropValueParcelable(value));
411 } catch (RemoteException e) {
412 handleRemoteException(e);
413 }
414 }
415
keunyoung5c7cb262015-10-19 10:47:45 -0700416 /**
417 * Start mocking of vehicle HAL. For testing only.
418 * @param mock
419 */
keunyoung1ab8e182015-09-24 09:25:22 -0700420 public synchronized void startMocking(VehicleNetworkHalMock mock) {
421 mHalMock = mock;
422 mHalMockImpl = new IVehicleNetworkHalMockImpl(this);
423 try {
424 mService.startMocking(mHalMockImpl);
425 } catch (RemoteException e) {
426 handleRemoteException(e);
427 }
428 }
429
keunyoung5c7cb262015-10-19 10:47:45 -0700430 /**
431 * Stop mocking of vehicle HAL. For testing only.
432 */
keunyoung1ab8e182015-09-24 09:25:22 -0700433 public synchronized void stopMocking() {
434 try {
435 mService.stopMocking(mHalMockImpl);
436 } catch (RemoteException e) {
437 handleRemoteException(e);
438 } finally {
439 mHalMock = null;
440 mHalMockImpl = null;
441 }
442 }
443
keunyoung5c7cb262015-10-19 10:47:45 -0700444 /**
445 * Start mocking of vehicle HAL. For testing only.
446 * @param mock
447 */
keunyoung1ab8e182015-09-24 09:25:22 -0700448 public synchronized void startMocking(IVehicleNetworkHalMock mock) {
449 mHalMock = null;
450 mHalMockImpl = mock;
451 try {
452 mService.startMocking(mHalMockImpl);
453 } catch (RemoteException e) {
454 handleRemoteException(e);
455 }
456 }
457
keunyoung5c7cb262015-10-19 10:47:45 -0700458 /**
459 * Stop mocking of vehicle HAL. For testing only.
460 */
keunyoung1ab8e182015-09-24 09:25:22 -0700461 public synchronized void stopMocking(IVehicleNetworkHalMock mock) {
462 if (mock.asBinder() != mHalMockImpl.asBinder()) {
463 return;
464 }
465 try {
466 mService.stopMocking(mHalMockImpl);
467 } catch (RemoteException e) {
468 handleRemoteException(e);
469 } finally {
470 mHalMock = null;
471 mHalMockImpl = null;
472 }
473 }
474
475 private synchronized VehicleNetworkHalMock getHalMock() {
476 return mHalMock;
477 }
478
keunyounge18e25d2015-08-28 15:57:19 -0700479 private void handleRemoteException(RemoteException e) {
480 throw new RuntimeException("Vehicle network service not working ", e);
481 }
482
483 private void handleVehicleNetworkEvents(VehiclePropValues values) {
484 mEventHandler.notifyEvents(values);
485 }
486
487 private void doHandleVehicleNetworkEvents(VehiclePropValues values) {
488 mListener.onVehicleNetworkEvents(values);
489 }
490
491 private class EventHandler extends Handler {
492 private static final int MSG_EVENTS = 0;
493
494 private EventHandler(Looper looper) {
495 super(looper);
496 }
497
498 private void notifyEvents(VehiclePropValues values) {
499 Message msg = obtainMessage(MSG_EVENTS, values);
500 sendMessage(msg);
501 }
502
503 @Override
504 public void handleMessage(Message msg) {
505 switch (msg.what) {
506 case MSG_EVENTS:
507 doHandleVehicleNetworkEvents((VehiclePropValues)msg.obj);
508 break;
509 default:
510 Log.w(TAG, "unown message:" + msg.what, new RuntimeException());
511 break;
512 }
513 }
514 }
515
516 private static class IVehicleNetworkListenerImpl extends IVehicleNetworkListener.Stub {
517 private final WeakReference<VehicleNetwork> mVehicleNetwork;
518
519 private IVehicleNetworkListenerImpl(VehicleNetwork vehicleNewotk) {
520 mVehicleNetwork = new WeakReference<VehicleNetwork>(vehicleNewotk);
521 }
522
523 @Override
524 public void onVehicleNetworkEvents(VehiclePropValuesParcelable values) {
525 VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
526 if (vehicleNetwork != null) {
527 vehicleNetwork.handleVehicleNetworkEvents(values.values);
528 }
529 }
530 }
keunyoung1ab8e182015-09-24 09:25:22 -0700531
532 private static class IVehicleNetworkHalMockImpl extends IVehicleNetworkHalMock.Stub {
533 private final WeakReference<VehicleNetwork> mVehicleNetwork;
534
535 private IVehicleNetworkHalMockImpl(VehicleNetwork vehicleNewotk) {
536 mVehicleNetwork = new WeakReference<VehicleNetwork>(vehicleNewotk);
537 }
538
539 @Override
540 public VehiclePropConfigsParcelable onListProperties() {
541 VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
542 if (vehicleNetwork == null) {
543 return null;
544 }
545 VehiclePropConfigs configs = vehicleNetwork.getHalMock().onListProperties();
546 return new VehiclePropConfigsParcelable(configs);
547 }
548
549 @Override
550 public void onPropertySet(VehiclePropValueParcelable value) {
551 VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
552 if (vehicleNetwork == null) {
553 return;
554 }
555 vehicleNetwork.getHalMock().onPropertySet(value.value);
556 }
557
558 @Override
keunyoung7d74e6d2015-10-14 15:43:10 -0700559 public VehiclePropValueParcelable onPropertyGet(VehiclePropValueParcelable value) {
keunyoung1ab8e182015-09-24 09:25:22 -0700560 VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
561 if (vehicleNetwork == null) {
562 return null;
563 }
keunyoung7d74e6d2015-10-14 15:43:10 -0700564 VehiclePropValue resValue = vehicleNetwork.getHalMock().onPropertyGet(value.value);
565 return new VehiclePropValueParcelable(resValue);
keunyoung1ab8e182015-09-24 09:25:22 -0700566 }
567
568 @Override
569 public void onPropertySubscribe(int property, int sampleRate) {
570 VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
571 if (vehicleNetwork == null) {
572 return;
573 }
574 vehicleNetwork.getHalMock().onPropertySubscribe(property, sampleRate);
575 }
576
577 @Override
578 public void onPropertyUnsubscribe(int property) {
579 VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
580 if (vehicleNetwork == null) {
581 return;
582 }
583 vehicleNetwork.getHalMock().onPropertyUnsubscribe(property);
584 }
585 }
keunyounge18e25d2015-08-28 15:57:19 -0700586}