blob: 6ec50fed596271c3630e810752a59fbfc54fbc89 [file] [log] [blame]
keunyoungcc449f72015-08-12 10:46:27 -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 */
16
17package com.android.car.hal;
18
keunyoungcc449f72015-08-12 10:46:27 -070019import android.os.HandlerThread;
Keun-young Park97e46eb2016-04-09 15:02:38 -070020import android.os.SystemClock;
keunyoungfe30ba02015-09-17 17:56:35 -070021import android.util.ArraySet;
keunyoungcc449f72015-08-12 10:46:27 -070022import android.util.Log;
23import android.util.SparseArray;
24
25import com.android.car.CarLog;
keunyoungfe30ba02015-09-17 17:56:35 -070026import com.android.car.vehiclenetwork.VehicleNetwork;
27import com.android.car.vehiclenetwork.VehicleNetwork.VehicleNetworkListener;
keunyounga74b9ca2015-10-21 13:33:58 -070028import com.android.car.vehiclenetwork.VehicleNetworkConsts;
29import com.android.car.vehiclenetwork.VehicleNetworkConsts.VehiclePropAccess;
30import com.android.car.vehiclenetwork.VehicleNetworkConsts.VehiclePropChangeMode;
keunyoungfe30ba02015-09-17 17:56:35 -070031import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropConfig;
32import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropConfigs;
33import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValue;
34import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValues;
Keun-young Parkfd3fbf72016-01-22 17:00:17 -080035import com.android.internal.annotations.VisibleForTesting;
keunyoungcc449f72015-08-12 10:46:27 -070036
37import java.io.PrintWriter;
Steve Paik4d6088c2016-07-20 20:27:55 -070038import java.util.ArrayList;
keunyounga74b9ca2015-10-21 13:33:58 -070039import java.util.Collection;
keunyounge4c90c42015-11-16 18:42:52 -080040import java.util.HashMap;
keunyoungcc449f72015-08-12 10:46:27 -070041import java.util.LinkedList;
42import java.util.List;
43
44/**
45 * Abstraction for vehicle HAL. This class handles interface with native HAL and do basic parsing
46 * of received data (type check). Then each event is sent to corresponding {@link HalServiceBase}
47 * implementation. It is responsibility of {@link HalServiceBase} to convert data to corresponding
48 * Car*Service for Car*Manager API.
49 */
keunyoungfe30ba02015-09-17 17:56:35 -070050public class VehicleHal implements VehicleNetworkListener {
keunyoungcc449f72015-08-12 10:46:27 -070051
Vitalii Tomkiv1b1247b2016-09-30 11:27:19 -070052 private static final boolean DBG = false;
keunyoungcc449f72015-08-12 10:46:27 -070053
keunyoungcc449f72015-08-12 10:46:27 -070054 static {
keunyoungfe30ba02015-09-17 17:56:35 -070055 createInstance();
keunyoungcc449f72015-08-12 10:46:27 -070056 }
57
58 private static VehicleHal sInstance;
59
keunyoungfe30ba02015-09-17 17:56:35 -070060 public static synchronized VehicleHal getInstance() {
keunyoungcc449f72015-08-12 10:46:27 -070061 if (sInstance == null) {
keunyoungfe30ba02015-09-17 17:56:35 -070062 createInstance();
keunyoungcc449f72015-08-12 10:46:27 -070063 }
64 return sInstance;
65 }
66
keunyoungfe30ba02015-09-17 17:56:35 -070067 private static synchronized void createInstance() {
68 sInstance = new VehicleHal();
69 // init is handled in a separate thread to prevent blocking the calling thread for too
70 // long.
keunyounge4c90c42015-11-16 18:42:52 -080071 sInstance.init();
keunyoungfe30ba02015-09-17 17:56:35 -070072 }
73
keunyoungcc449f72015-08-12 10:46:27 -070074 public static synchronized void releaseInstance() {
75 if (sInstance != null) {
76 sInstance.release();
77 sInstance = null;
78 }
79 }
80
keunyounge4c90c42015-11-16 18:42:52 -080081 private final HandlerThread mHandlerThread;
keunyoungfe30ba02015-09-17 17:56:35 -070082 private final VehicleNetwork mVehicleNetwork;
keunyoungcc449f72015-08-12 10:46:27 -070083 private final SensorHalService mSensorHal;
keunyounga3b28d82015-08-25 13:05:15 -070084 private final InfoHalService mInfoHal;
keunyoungd32f4e62015-09-21 11:33:06 -070085 private final AudioHalService mAudioHal;
Steve Paik43c04a72016-07-08 19:12:09 -070086 private final CabinHalService mCabinHal;
Sanket Agarwal3cf096a2015-10-13 14:46:31 -070087 private final RadioHalService mRadioHal;
keunyoung4b0212c2015-10-29 17:11:57 -070088 private final PowerHalService mPowerHal;
Steve Paik66481982015-10-27 15:22:38 -070089 private final HvacHalService mHvacHal;
Keun-young Parka28d7b22016-02-29 16:54:29 -080090 private final InputHalService mInputHal;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -070091 private final VendorExtensionHalService mVendorExtensionHal;
keunyoungcc449f72015-08-12 10:46:27 -070092
93 /** stores handler for each HAL property. Property events are sent to handler. */
94 private final SparseArray<HalServiceBase> mPropertyHandlers = new SparseArray<HalServiceBase>();
95 /** This is for iterating all HalServices with fixed order. */
96 private final HalServiceBase[] mAllServices;
keunyoungfe30ba02015-09-17 17:56:35 -070097 private final ArraySet<Integer> mSubscribedProperties = new ArraySet<Integer>();
Steve Paik4d6088c2016-07-20 20:27:55 -070098 private final HashMap<Integer, VehiclePropConfig> mAllProperties = new HashMap<>();
Keun-young Park97e46eb2016-04-09 15:02:38 -070099 private final HashMap<Integer, VehiclePropertyEventInfo> mEventLog = new HashMap<>();
100
keunyoungfe30ba02015-09-17 17:56:35 -0700101 private VehicleHal() {
keunyounge4c90c42015-11-16 18:42:52 -0800102 mHandlerThread = new HandlerThread("VEHICLE-HAL");
keunyoungcc449f72015-08-12 10:46:27 -0700103 mHandlerThread.start();
keunyoungcc449f72015-08-12 10:46:27 -0700104 // passing this should be safe as long as it is just kept and not used in constructor
keunyoung4b0212c2015-10-29 17:11:57 -0700105 mPowerHal = new PowerHalService(this);
keunyoungcc449f72015-08-12 10:46:27 -0700106 mSensorHal = new SensorHalService(this);
keunyounga3b28d82015-08-25 13:05:15 -0700107 mInfoHal = new InfoHalService(this);
keunyoungd32f4e62015-09-21 11:33:06 -0700108 mAudioHal = new AudioHalService(this);
Steve Paik43c04a72016-07-08 19:12:09 -0700109 mCabinHal = new CabinHalService(this);
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700110 mRadioHal = new RadioHalService(this);
Steve Paik66481982015-10-27 15:22:38 -0700111 mHvacHal = new HvacHalService(this);
Keun-young Parka28d7b22016-02-29 16:54:29 -0800112 mInputHal = new InputHalService();
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700113 mVendorExtensionHal = new VendorExtensionHalService(this);
keunyounga3b28d82015-08-25 13:05:15 -0700114 mAllServices = new HalServiceBase[] {
keunyoung4b0212c2015-10-29 17:11:57 -0700115 mPowerHal,
keunyoungd32f4e62015-09-21 11:33:06 -0700116 mAudioHal,
Steve Paik43c04a72016-07-08 19:12:09 -0700117 mCabinHal,
Steve Paik66481982015-10-27 15:22:38 -0700118 mHvacHal,
keunyounga3b28d82015-08-25 13:05:15 -0700119 mInfoHal,
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700120 mSensorHal,
Keun-young Parka28d7b22016-02-29 16:54:29 -0800121 mRadioHal,
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700122 mInputHal,
123 mVendorExtensionHal
Keun-young Parka28d7b22016-02-29 16:54:29 -0800124 };
keunyoungfe30ba02015-09-17 17:56:35 -0700125 mVehicleNetwork = VehicleNetwork.createVehicleNetwork(this, mHandlerThread.getLooper());
keunyoungcc449f72015-08-12 10:46:27 -0700126 }
127
Keun-young Parkfd3fbf72016-01-22 17:00:17 -0800128 /** Dummy version only for testing */
129 @VisibleForTesting
130 public VehicleHal(PowerHalService powerHal, SensorHalService sensorHal, InfoHalService infoHal,
Steve Paik43c04a72016-07-08 19:12:09 -0700131 AudioHalService audioHal, CabinHalService cabinHal, RadioHalService radioHal,
132 HvacHalService hvacHal, VehicleNetwork vehicleNetwork) {
Keun-young Parkfd3fbf72016-01-22 17:00:17 -0800133 mHandlerThread = null;
134 mPowerHal = powerHal;
135 mSensorHal = sensorHal;
136 mInfoHal = infoHal;
137 mAudioHal = audioHal;
Steve Paik43c04a72016-07-08 19:12:09 -0700138 mCabinHal = cabinHal;
Keun-young Parkfd3fbf72016-01-22 17:00:17 -0800139 mRadioHal = radioHal;
140 mHvacHal = hvacHal;
Keun-young Parka28d7b22016-02-29 16:54:29 -0800141 mInputHal = null;
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700142 mVendorExtensionHal = null;
Keun-young Parkfd3fbf72016-01-22 17:00:17 -0800143 mAllServices = null;
144 mVehicleNetwork = vehicleNetwork;
145 }
146
Keun-young Park021310d2016-04-25 21:09:39 -0700147 public void init() {
keunyoungfe30ba02015-09-17 17:56:35 -0700148 VehiclePropConfigs properties = mVehicleNetwork.listProperties();
149 // needs copy as getConfigsList gives unmodifiable one.
150 List<VehiclePropConfig> propertiesList =
151 new LinkedList<VehiclePropConfig>(properties.getConfigsList());
Steve Paik4d6088c2016-07-20 20:27:55 -0700152
153 synchronized (this) {
154 // Create map of all properties
155 for (VehiclePropConfig p : propertiesList) {
156 mAllProperties.put(p.getProp(), p);
157 }
158 }
159
keunyoungcc449f72015-08-12 10:46:27 -0700160 for (HalServiceBase service: mAllServices) {
keunyoungfe30ba02015-09-17 17:56:35 -0700161 List<VehiclePropConfig> taken = service.takeSupportedProperties(propertiesList);
keunyounga3b28d82015-08-25 13:05:15 -0700162 if (taken == null) {
163 continue;
164 }
keunyoungcc449f72015-08-12 10:46:27 -0700165 if (DBG) {
166 Log.i(CarLog.TAG_HAL, "HalService " + service + " take properties " + taken.size());
167 }
keunyounge4c90c42015-11-16 18:42:52 -0800168 synchronized (this) {
169 for (VehiclePropConfig p: taken) {
170 mPropertyHandlers.append(p.getProp(), service);
171 }
keunyoungcc449f72015-08-12 10:46:27 -0700172 }
keunyoungfe30ba02015-09-17 17:56:35 -0700173 propertiesList.removeAll(taken);
keunyoungcc449f72015-08-12 10:46:27 -0700174 service.init();
175 }
176 }
177
Keun-young Park021310d2016-04-25 21:09:39 -0700178 public void release() {
keunyoungcc449f72015-08-12 10:46:27 -0700179 // release in reverse order from init
180 for (int i = mAllServices.length - 1; i >= 0; i--) {
181 mAllServices[i].release();
182 }
keunyounge4c90c42015-11-16 18:42:52 -0800183 synchronized (this) {
184 for (int p : mSubscribedProperties) {
185 mVehicleNetwork.unsubscribe(p);
186 }
187 mSubscribedProperties.clear();
Keun-young Park450faba2016-02-10 18:15:12 -0800188 mAllProperties.clear();
keunyoungfe30ba02015-09-17 17:56:35 -0700189 }
keunyoungfe30ba02015-09-17 17:56:35 -0700190 // keep the looper thread as should be kept for the whole life cycle.
keunyoungcc449f72015-08-12 10:46:27 -0700191 }
192
193 public SensorHalService getSensorHal() {
194 return mSensorHal;
195 }
196
keunyounga3b28d82015-08-25 13:05:15 -0700197 public InfoHalService getInfoHal() {
198 return mInfoHal;
199 }
200
keunyoungd32f4e62015-09-21 11:33:06 -0700201 public AudioHalService getAudioHal() {
202 return mAudioHal;
203 }
204
Steve Paik43c04a72016-07-08 19:12:09 -0700205 public CabinHalService getCabinHal() {
206 return mCabinHal;
207 }
208
Sanket Agarwal3cf096a2015-10-13 14:46:31 -0700209 public RadioHalService getRadioHal() {
210 return mRadioHal;
211 }
212
keunyoung4b0212c2015-10-29 17:11:57 -0700213 public PowerHalService getPowerHal() {
214 return mPowerHal;
215 }
216
Steve Paik66481982015-10-27 15:22:38 -0700217 public HvacHalService getHvacHal() {
218 return mHvacHal;
219 }
220
Keun-young Parka28d7b22016-02-29 16:54:29 -0800221 public InputHalService getInputHal() {
222 return mInputHal;
223 }
224
Pavel Maltsev634e1ff2016-07-14 15:41:26 -0700225 public VendorExtensionHalService getVendorExtensionHal() {
226 return mVendorExtensionHal;
227 }
228
keunyounge4c90c42015-11-16 18:42:52 -0800229 private void assertServiceOwnerLocked(HalServiceBase service, int property) {
keunyoungd32f4e62015-09-21 11:33:06 -0700230 if (service != mPropertyHandlers.get(property)) {
Pavel Maltsev1bfbaef2016-07-25 14:23:51 -0700231 throw new IllegalArgumentException("Property 0x" + Integer.toHexString(property)
232 + " is not owned by service: " + service);
keunyoungfe30ba02015-09-17 17:56:35 -0700233 }
keunyoungcc449f72015-08-12 10:46:27 -0700234 }
235
keunyoungfe30ba02015-09-17 17:56:35 -0700236 /**
237 * Subscribe given property. Only Hal service owning the property can subscribe it.
238 * @param service
239 * @param property
240 * @param samplingRateHz
241 */
keunyoungd32f4e62015-09-21 11:33:06 -0700242 public void subscribeProperty(HalServiceBase service, int property,
keunyoungfe30ba02015-09-17 17:56:35 -0700243 float samplingRateHz) throws IllegalArgumentException {
Steve Paik4d6088c2016-07-20 20:27:55 -0700244 VehiclePropConfig config;
keunyounge4c90c42015-11-16 18:42:52 -0800245 synchronized (this) {
Steve Paik4d6088c2016-07-20 20:27:55 -0700246 config = mAllProperties.get(property);
keunyounge4c90c42015-11-16 18:42:52 -0800247 }
Steve Paik4d6088c2016-07-20 20:27:55 -0700248
249 if (config == null) {
250 throw new IllegalArgumentException("subscribe error: config is null for property " +
251 property);
252 } else if (isPropertySubscribable(config)) {
253 synchronized (this) {
254 assertServiceOwnerLocked(service, property);
255 mSubscribedProperties.add(property);
256 }
257 mVehicleNetwork.subscribe(property, samplingRateHz);
258 } else {
259 Log.e(CarLog.TAG_HAL, "Cannot subscribe to property: " + property);
260 }
keunyounga3b28d82015-08-25 13:05:15 -0700261 }
262
keunyoungd32f4e62015-09-21 11:33:06 -0700263 public void unsubscribeProperty(HalServiceBase service, int property) {
Steve Paik4d6088c2016-07-20 20:27:55 -0700264 VehiclePropConfig config;
keunyounge4c90c42015-11-16 18:42:52 -0800265 synchronized (this) {
Steve Paik4d6088c2016-07-20 20:27:55 -0700266 config = mAllProperties.get(property);
keunyounge4c90c42015-11-16 18:42:52 -0800267 }
Steve Paik4d6088c2016-07-20 20:27:55 -0700268
269 if (config == null) {
270 Log.e(CarLog.TAG_HAL, "unsubscribeProperty: property " + property + " does not exist");
271 } else if (isPropertySubscribable(config)) {
272 synchronized (this) {
273 assertServiceOwnerLocked(service, property);
274 mSubscribedProperties.remove(property);
275 }
276 mVehicleNetwork.unsubscribe(property);
277 } else {
278 Log.e(CarLog.TAG_HAL, "Cannot unsubscribe property: " + property);
279 }
keunyounga3b28d82015-08-25 13:05:15 -0700280 }
281
keunyoungd32f4e62015-09-21 11:33:06 -0700282 public VehicleNetwork getVehicleNetwork() {
283 return mVehicleNetwork;
keunyoungcc449f72015-08-12 10:46:27 -0700284 }
285
keunyounga74b9ca2015-10-21 13:33:58 -0700286 public static boolean isPropertySubscribable(VehiclePropConfig config) {
Keun-young Park4c6834a2016-06-28 12:58:23 -0700287 if ((config.getAccess() & VehiclePropAccess.VEHICLE_PROP_ACCESS_READ) == 0 ||
288 (config.getChangeMode() ==
289 VehiclePropChangeMode.VEHICLE_PROP_CHANGE_MODE_STATIC)) {
keunyounga74b9ca2015-10-21 13:33:58 -0700290 return false;
291 }
292 return true;
293 }
294
295 public static void dumpProperties(PrintWriter writer, Collection<VehiclePropConfig> configs) {
296 for (VehiclePropConfig config : configs) {
297 writer.println("property " +
298 VehicleNetworkConsts.getVehiclePropertyName(config.getProp()));
299 }
300 }
301
keunyoungfe30ba02015-09-17 17:56:35 -0700302 private final ArraySet<HalServiceBase> mServicesToDispatch = new ArraySet<HalServiceBase>();
keunyounge4c90c42015-11-16 18:42:52 -0800303
keunyoungfe30ba02015-09-17 17:56:35 -0700304 @Override
305 public void onVehicleNetworkEvents(VehiclePropValues values) {
keunyounge4c90c42015-11-16 18:42:52 -0800306 synchronized (this) {
307 for (VehiclePropValue v : values.getValuesList()) {
308 HalServiceBase service = mPropertyHandlers.get(v.getProp());
309 service.getDispatchList().add(v);
310 mServicesToDispatch.add(service);
Keun-young Park97e46eb2016-04-09 15:02:38 -0700311 VehiclePropertyEventInfo info = mEventLog.get(v.getProp());
312 if (info == null) {
313 info = new VehiclePropertyEventInfo(v);
314 mEventLog.put(v.getProp(), info);
315 } else {
316 info.addNewEvent(v);
317 }
keunyounge4c90c42015-11-16 18:42:52 -0800318 }
keunyoungcc449f72015-08-12 10:46:27 -0700319 }
keunyoungfe30ba02015-09-17 17:56:35 -0700320 for (HalServiceBase s : mServicesToDispatch) {
321 s.handleHalEvents(s.getDispatchList());
322 s.getDispatchList().clear();
323 }
324 mServicesToDispatch.clear();
keunyoungcc449f72015-08-12 10:46:27 -0700325 }
326
Keun-young Park28dd4702015-11-19 18:06:04 -0800327 @Override
Pavel Maltsevb0324b42016-09-27 21:00:41 -0700328 public void onPropertySet(VehiclePropValue value) {
329 // No need to handle on-property-set events in HAL service yet.
330 }
331
332 @Override
Keun-young Park28dd4702015-11-19 18:06:04 -0800333 public void onHalError(int errorCode, int property, int operation) {
334 Log.e(CarLog.TAG_HAL, "onHalError, errorCode:" + errorCode +
335 " property:0x" + Integer.toHexString(property) +
336 " operation:" + operation);
337 // TODO propagate per property error to HAL services and handle global error
338 }
339
340 @Override
341 public void onHalRestart(boolean inMocking) {
342 Log.e(CarLog.TAG_HAL, "onHalRestart, inMocking:" + inMocking);
343 // TODO restart things as other components started mocking. For now, ignore.
344 }
345
keunyoungcc449f72015-08-12 10:46:27 -0700346 public void dump(PrintWriter writer) {
347 writer.println("**dump HAL services**");
348 for (HalServiceBase service: mAllServices) {
349 service.dump(writer);
350 }
Steve Paik4d6088c2016-07-20 20:27:55 -0700351
352 List<VehiclePropConfig> configList;
353 synchronized (this) {
354 configList = new ArrayList<>(mAllProperties.values());
355 }
356
Keun-young Park450faba2016-02-10 18:15:12 -0800357 writer.println("**All properties**");
Steve Paik4d6088c2016-07-20 20:27:55 -0700358 for (VehiclePropConfig config : configList) {
Keun-young Park450faba2016-02-10 18:15:12 -0800359 StringBuilder builder = new StringBuilder();
Pavel Maltsev437ab412016-08-15 15:41:06 -0700360 builder.append("Property:0x").append(Integer.toHexString(config.getProp()));
Keun-young Park97e46eb2016-04-09 15:02:38 -0700361 builder.append(",access:0x" + Integer.toHexString(config.getAccess()));
362 builder.append(",changeMode:0x" + Integer.toHexString(config.getChangeMode()));
363 builder.append(",valueType:0x" + Integer.toHexString(config.getValueType()));
364 builder.append(",permission:0x" + Integer.toHexString(config.getPermissionModel()));
365 builder.append(",config:0x" + Integer.toHexString(config.getConfigArray(0)));
Keun-young Park450faba2016-02-10 18:15:12 -0800366 builder.append(",fs min:" + config.getSampleRateMin());
Pavel Maltsev437ab412016-08-15 15:41:06 -0700367 builder.append(",fs max:").append(config.getSampleRateMax());
Keun-young Park71b2f5c2016-03-10 18:44:40 -0800368 for (int i = 0; i < config.getFloatMaxsCount(); i++) {
369 builder.append(",v min:" + config.getFloatMins(i));
370 builder.append(",v max:" + config.getFloatMaxs(i));
Keun-young Park450faba2016-02-10 18:15:12 -0800371 }
Keun-young Park71b2f5c2016-03-10 18:44:40 -0800372 for (int i = 0; i < config.getInt32MaxsCount(); i++) {
373 builder.append(",v min:" + config.getInt32Mins(i));
374 builder.append(",v max:" + config.getInt32Maxs(i));
Keun-young Park450faba2016-02-10 18:15:12 -0800375 }
Keun-young Park71b2f5c2016-03-10 18:44:40 -0800376 for (int i = 0; i < config.getInt64MaxsCount(); i++) {
377 builder.append(",v min:" + config.getInt64Mins(i));
378 builder.append(",v max:" + config.getInt64Maxs(i));
Keun-young Park450faba2016-02-10 18:15:12 -0800379 }
380 writer.println(builder.toString());
381 }
Keun-young Park97e46eb2016-04-09 15:02:38 -0700382 writer.println(String.format("**All Events, now ns:%d**",
383 SystemClock.elapsedRealtimeNanos()));
384 for (VehiclePropertyEventInfo info : mEventLog.values()) {
385 writer.println(String.format("event count:%d, lastEvent:%s",
386 info.eventCount, dumpVehiclePropValue(info.lastEvent)));
387 }
Pavel Maltsev437ab412016-08-15 15:41:06 -0700388
389 writer.println("**Property handlers**");
390 for (int i = 0; i < mPropertyHandlers.size(); i++) {
391 int propId = mPropertyHandlers.keyAt(i);
392 HalServiceBase service = mPropertyHandlers.valueAt(i);
393 writer.println(String.format("Prop: 0x%08X, service: %s", propId, service));
394 }
Keun-young Park97e46eb2016-04-09 15:02:38 -0700395 }
396
397 public static String dumpVehiclePropValue(VehiclePropValue value) {
398 StringBuilder sb = new StringBuilder();
399 sb.append("Property:0x" + Integer.toHexString(value.getProp()));
400 sb.append(",timestamp:" + value.getTimestamp());
401 sb.append(",value type:0x" + Integer.toHexString(value.getValueType()));
402 sb.append(",zone:0x" + Integer.toHexString(value.getZone()));
403 if (value.getInt32ValuesCount() > 0) {
404 sb.append(",int32 values:");
405 for (int i = 0; i < value.getInt32ValuesCount(); i++) {
406 sb.append("," + value.getInt32Values(i));
407 }
408 }
409 if (value.hasInt64Value()) {
410 sb.append(",int64 value:" + value.getInt64Value());
411 }
412 if (value.getFloatValuesCount() > 0) {
413 sb.append(",float values:");
414 for (int i = 0; i < value.getFloatValuesCount(); i++) {
415 sb.append("," + value.getFloatValues(i));
416 }
417 }
418 if (value.hasStringValue()) {
419 sb.append(",string value:" + value.getStringValue());
420 }
421 if (value.hasBytesValue()) {
422 sb.append(",bytes value:" + value.getBytesValue());
423 }
424 return sb.toString();
425 }
426 private static class VehiclePropertyEventInfo {
427 private int eventCount;
428 private VehiclePropValue lastEvent;
429
430 private VehiclePropertyEventInfo(VehiclePropValue event) {
431 eventCount = 1;
432 lastEvent = event;
433 }
434
435 private void addNewEvent(VehiclePropValue event) {
436 eventCount++;
437 lastEvent = event;
438 }
keunyoungcc449f72015-08-12 10:46:27 -0700439 }
440}