1 /* 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 17 package android.car.hardware; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.car.annotation.AddedInOrBefore; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 26 27 /** 28 * A CarSensorEvent object corresponds to a single sensor event coming from the car. The sensor 29 * data is stored in a sensor-type specific format in the object's float and byte arrays. 30 * 31 * To aid unmarshalling the object's data arrays, this class provides static nested classes and 32 * conversion methods. The conversion methods each have an optional data parameter which, 33 * if not null, will be used and returned. This parameter should be used to avoid unnecessary 34 * object churn whenever possible. Additionally, calling a conversion method on a CarSensorEvent 35 * object with an inappropriate type will result in an {@code UnsupportedOperationException} 36 * being thrown. 37 * 38 * @deprecated consider using {@link CarPropertyValue} and 39 * {@link android.car.hardware.property.CarPropertyManager} instead. 40 */ 41 @Deprecated 42 public class CarSensorEvent implements Parcelable { 43 44 /** 45 * GEAR_* represents meaning of intValues[0] for {@link CarSensorManager#SENSOR_TYPE_GEAR} 46 * sensor type. 47 * GEAR_NEUTRAL means transmission gear is in neutral state, and the car may be moving. 48 */ 49 @AddedInOrBefore(majorVersion = 33) 50 public static final int GEAR_NEUTRAL = 0x0001; 51 /** 52 * intValues[0] from 1 to 99 represents transmission gear number for moving forward. 53 * GEAR_FIRST is for gear number 1. 54 */ 55 @AddedInOrBefore(majorVersion = 33) 56 public static final int GEAR_FIRST = 0x0010; 57 /** Gear number 2. */ 58 @AddedInOrBefore(majorVersion = 33) 59 public static final int GEAR_SECOND = 0x0020; 60 /** Gear number 3. */ 61 @AddedInOrBefore(majorVersion = 33) 62 public static final int GEAR_THIRD = 0x0040; 63 /** Gear number 4. */ 64 @AddedInOrBefore(majorVersion = 33) 65 public static final int GEAR_FOURTH = 0x0080; 66 /** Gear number 5. */ 67 @AddedInOrBefore(majorVersion = 33) 68 public static final int GEAR_FIFTH = 0x0100; 69 /** Gear number 6. */ 70 @AddedInOrBefore(majorVersion = 33) 71 public static final int GEAR_SIXTH = 0x0200; 72 /** Gear number 7. */ 73 @AddedInOrBefore(majorVersion = 33) 74 public static final int GEAR_SEVENTH = 0x0400; 75 /** Gear number 8. */ 76 @AddedInOrBefore(majorVersion = 33) 77 public static final int GEAR_EIGHTH = 0x0800; 78 /** Gear number 9. */ 79 @AddedInOrBefore(majorVersion = 33) 80 public static final int GEAR_NINTH = 0x1000; 81 /** Gear number 10. */ 82 @AddedInOrBefore(majorVersion = 33) 83 public static final int GEAR_TENTH = 0x2000; 84 /** 85 * This is for transmission without specific gear number for moving forward like CVT. It tells 86 * that car is in a transmission state to move it forward. 87 */ 88 @AddedInOrBefore(majorVersion = 33) 89 public static final int GEAR_DRIVE = 0x0008; 90 /** Gear in parking state */ 91 @AddedInOrBefore(majorVersion = 33) 92 public static final int GEAR_PARK = 0x0004; 93 /** Gear in reverse */ 94 @AddedInOrBefore(majorVersion = 33) 95 public static final int GEAR_REVERSE = 0x0002; 96 97 /** 98 * Ignition state is unknown. 99 * 100 * The constants that starts with IGNITION_STATE_ represent values for 101 * {@link CarSensorManager#SENSOR_TYPE_IGNITION_STATE} sensor. 102 * */ 103 @AddedInOrBefore(majorVersion = 33) 104 public static final int IGNITION_STATE_UNDEFINED = 0; 105 /** 106 * Steering wheel is locked. 107 */ 108 @AddedInOrBefore(majorVersion = 33) 109 public static final int IGNITION_STATE_LOCK = 1; 110 /** Typically engine is off, but steering wheel is unlocked. */ 111 @AddedInOrBefore(majorVersion = 33) 112 public static final int IGNITION_STATE_OFF = 2; 113 /** Accessory is turned off, but engine is not running yet (for EV car is not ready to move). */ 114 @AddedInOrBefore(majorVersion = 33) 115 public static final int IGNITION_STATE_ACC = 3; 116 /** In this state engine typically is running (for EV, car is ready to move). */ 117 @AddedInOrBefore(majorVersion = 33) 118 public static final int IGNITION_STATE_ON = 4; 119 /** In this state engine is typically starting (cranking). */ 120 @AddedInOrBefore(majorVersion = 33) 121 public static final int IGNITION_STATE_START = 5; 122 123 /** 124 * Index for {@link CarSensorManager#SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE} in floatValues. 125 * Temperature in Celsius degrees. 126 */ 127 @AddedInOrBefore(majorVersion = 33) 128 public static final int INDEX_ENVIRONMENT_TEMPERATURE = 0; 129 130 /** 131 * Index for {@link CarSensorManager#SENSOR_TYPE_WHEEL_TICK_DISTANCE} in longValues. RESET_COUNT 132 * is incremented whenever the HAL detects that a sensor reset has occurred. It represents to 133 * the upper layer that the WHEEL_DISTANCE values will not be contiguous with other values 134 * reported with a different RESET_COUNT. 135 */ 136 @AddedInOrBefore(majorVersion = 33) 137 public static final int INDEX_WHEEL_DISTANCE_RESET_COUNT = 0; 138 @AddedInOrBefore(majorVersion = 33) 139 public static final int INDEX_WHEEL_DISTANCE_FRONT_LEFT = 1; 140 @AddedInOrBefore(majorVersion = 33) 141 public static final int INDEX_WHEEL_DISTANCE_FRONT_RIGHT = 2; 142 @AddedInOrBefore(majorVersion = 33) 143 public static final int INDEX_WHEEL_DISTANCE_REAR_RIGHT = 3; 144 @AddedInOrBefore(majorVersion = 33) 145 public static final int INDEX_WHEEL_DISTANCE_REAR_LEFT = 4; 146 147 private static final long MILLI_IN_NANOS = 1000000L; 148 149 /** Sensor type for this event like {@link CarSensorManager#SENSOR_TYPE_CAR_SPEED}. */ 150 @AddedInOrBefore(majorVersion = 33) 151 public int sensorType; 152 153 /** 154 * When this data was received from car. It is elapsed real-time of data reception from car in 155 * nanoseconds since system boot. 156 */ 157 @AddedInOrBefore(majorVersion = 33) 158 public long timestamp; 159 /** 160 * array holding float type of sensor data. If the sensor has single value, only floatValues[0] 161 * should be used. */ 162 @AddedInOrBefore(majorVersion = 33) 163 public final float[] floatValues; 164 /** array holding int type of sensor data */ 165 @AddedInOrBefore(majorVersion = 33) 166 public final int[] intValues; 167 /** array holding long int type of sensor data */ 168 @AddedInOrBefore(majorVersion = 33) 169 public final long[] longValues; 170 171 /** @hide */ CarSensorEvent(Parcel in)172 public CarSensorEvent(Parcel in) { 173 sensorType = in.readInt(); 174 timestamp = in.readLong(); 175 floatValues = in.createFloatArray(); 176 intValues = in.createIntArray(); 177 // version 1 up to here 178 longValues = in.createLongArray(); 179 } 180 181 @Override 182 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 183 @AddedInOrBefore(majorVersion = 33) describeContents()184 public int describeContents() { 185 return 0; 186 } 187 188 @Override 189 @AddedInOrBefore(majorVersion = 33) writeToParcel(Parcel dest, int flags)190 public void writeToParcel(Parcel dest, int flags) { 191 dest.writeInt(sensorType); 192 dest.writeLong(timestamp); 193 dest.writeFloatArray(floatValues); 194 dest.writeIntArray(intValues); 195 dest.writeLongArray(longValues); 196 } 197 198 @AddedInOrBefore(majorVersion = 33) 199 public static final Parcelable.Creator<CarSensorEvent> CREATOR = 200 new Parcelable.Creator<CarSensorEvent>() { 201 public CarSensorEvent createFromParcel(Parcel in) { 202 return new CarSensorEvent(in); 203 } 204 205 public CarSensorEvent[] newArray(int size) { 206 return new CarSensorEvent[size]; 207 } 208 }; 209 210 /** @hide */ CarSensorEvent(int sensorType, long timestamp, int floatValueSize, int intValueSize, int longValueSize)211 public CarSensorEvent(int sensorType, long timestamp, int floatValueSize, int intValueSize, 212 int longValueSize) { 213 this.sensorType = sensorType; 214 this.timestamp = timestamp; 215 floatValues = new float[floatValueSize]; 216 intValues = new int[intValueSize]; 217 longValues = new long[longValueSize]; 218 } 219 220 /** @hide */ CarSensorEvent(int sensorType, long timestamp, float[] floatValues, int[] intValues, long[] longValues)221 CarSensorEvent(int sensorType, long timestamp, float[] floatValues, int[] intValues, 222 long[] longValues) { 223 this.sensorType = sensorType; 224 this.timestamp = timestamp; 225 this.floatValues = floatValues; 226 this.intValues = intValues; 227 this.longValues = longValues; 228 } 229 checkType(int type)230 private void checkType(int type) { 231 if (sensorType == type) { 232 return; 233 } 234 throw new UnsupportedOperationException(String.format( 235 "Invalid sensor type: expected %d, got %d", type, sensorType)); 236 } 237 238 /** 239 * Environment data with timestamp and temperature. 240 */ 241 public static class EnvironmentData { 242 @AddedInOrBefore(majorVersion = 33) 243 public long timestamp; 244 /** If unsupported by the car, this value is NaN. */ 245 @AddedInOrBefore(majorVersion = 33) 246 public float temperature; 247 248 /** @hide */ EnvironmentData()249 private EnvironmentData() {}; 250 } 251 252 /** 253 * Convenience method for obtaining an {@link EnvironmentData} object from a CarSensorEvent 254 * object with type {@link CarSensorManager#SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE}. 255 * 256 * @param outData an optional output parameter which, if non-null, will be used by this method 257 * instead of a newly created object. 258 * @return an EnvironmentData object corresponding to the data contained in the CarSensorEvent. 259 * @hide 260 */ 261 @AddedInOrBefore(majorVersion = 33) getEnvironmentData(EnvironmentData outData)262 public EnvironmentData getEnvironmentData(EnvironmentData outData) { 263 EnvironmentData data = outData; 264 checkType(CarSensorManager.SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE); 265 if (data == null) { 266 data = new EnvironmentData(); 267 } 268 data.timestamp = timestamp; 269 data.temperature = floatValues[INDEX_ENVIRONMENT_TEMPERATURE]; 270 return data; 271 } 272 273 /** @hide*/ 274 public static class IgnitionStateData { 275 @AddedInOrBefore(majorVersion = 33) 276 public long timestamp; 277 @AddedInOrBefore(majorVersion = 33) 278 public int ignitionState; 279 280 /** @hide */ IgnitionStateData()281 private IgnitionStateData() {}; 282 } 283 284 /** 285 * Convenience method for obtaining a {@link IgnitionStateData} object from a CarSensorEvent 286 * object with type {@link CarSensorManager#SENSOR_TYPE_IGNITION_STATE}. 287 * 288 * @param dataParam an optional output parameter which, if non-null, will be used by this method 289 * instead of a newly created object. 290 * @return a IgnitionStateData object corresponding to the data contained in the CarSensorEvent. 291 * @hide 292 */ 293 @AddedInOrBefore(majorVersion = 33) getIgnitionStateData(IgnitionStateData dataParam)294 public IgnitionStateData getIgnitionStateData(IgnitionStateData dataParam) { 295 IgnitionStateData data = dataParam; 296 checkType(CarSensorManager.SENSOR_TYPE_IGNITION_STATE); 297 if (data == null) { 298 data = new IgnitionStateData(); 299 } 300 data.timestamp = timestamp; 301 data.ignitionState = intValues[0]; 302 return data; 303 } 304 305 /** @hide */ 306 public static class NightData { 307 @AddedInOrBefore(majorVersion = 33) 308 public long timestamp; 309 @AddedInOrBefore(majorVersion = 33) 310 public boolean isNightMode; 311 312 /** @hide */ NightData()313 private NightData() {}; 314 } 315 316 /** 317 * Convenience method for obtaining a {@link NightData} object from a CarSensorEvent 318 * object with type {@link CarSensorManager#SENSOR_TYPE_NIGHT}. 319 * 320 * @param dataParam an optional output parameter which, if non-null, will be used by this method 321 * instead of a newly created object. 322 * @return a NightData object corresponding to the data contained in the CarSensorEvent. 323 * @hide 324 */ 325 @AddedInOrBefore(majorVersion = 33) getNightData(NightData dataParam)326 public NightData getNightData(NightData dataParam) { 327 NightData data = dataParam; 328 checkType(CarSensorManager.SENSOR_TYPE_NIGHT); 329 if (data == null) { 330 data = new NightData(); 331 } 332 data.timestamp = timestamp; 333 data.isNightMode = intValues[0] == 1; 334 return data; 335 } 336 337 /** @hide */ 338 public static class GearData { 339 @AddedInOrBefore(majorVersion = 33) 340 public long timestamp; 341 @AddedInOrBefore(majorVersion = 33) 342 public int gear; 343 344 /** @hide */ GearData()345 private GearData() {}; 346 } 347 348 /** 349 * Convenience method for obtaining a {@link GearData} object from a CarSensorEvent 350 * object with type {@link CarSensorManager#SENSOR_TYPE_GEAR}. 351 * 352 * @param dataParam an optional output parameter which, if non-null, will be used by this method 353 * instead of a newly created object. 354 * @return a GearData object corresponding to the data contained in the CarSensorEvent. 355 * @hide 356 */ 357 @AddedInOrBefore(majorVersion = 33) getGearData(GearData dataParam)358 public GearData getGearData(GearData dataParam) { 359 GearData data = dataParam; 360 checkType(CarSensorManager.SENSOR_TYPE_GEAR); 361 if (data == null) { 362 data = new GearData(); 363 } 364 data.timestamp = timestamp; 365 data.gear = intValues[0]; 366 return data; 367 } 368 369 /** @hide */ 370 public static class ParkingBrakeData { 371 @AddedInOrBefore(majorVersion = 33) 372 public long timestamp; 373 @AddedInOrBefore(majorVersion = 33) 374 public boolean isEngaged; 375 376 /** @hide */ ParkingBrakeData()377 private ParkingBrakeData() {} 378 } 379 380 /** 381 * Convenience method for obtaining a {@link ParkingBrakeData} object from a CarSensorEvent 382 * object with type {@link CarSensorManager#SENSOR_TYPE_PARKING_BRAKE}. 383 * 384 * @param dataParam an optional output parameter which, if non-null, will be used by this method 385 * instead of a newly created object. 386 * @return a ParkingBreakData object corresponding to the data contained in the CarSensorEvent. 387 * @hide 388 */ 389 @AddedInOrBefore(majorVersion = 33) getParkingBrakeData(ParkingBrakeData dataParam)390 public ParkingBrakeData getParkingBrakeData(ParkingBrakeData dataParam) { 391 ParkingBrakeData data = dataParam; 392 checkType(CarSensorManager.SENSOR_TYPE_PARKING_BRAKE); 393 if (data == null) { 394 data = new ParkingBrakeData(); 395 } 396 data.timestamp = timestamp; 397 data.isEngaged = intValues[0] == 1; 398 return data; 399 } 400 401 /** @hide */ 402 public static class FuelLevelData { 403 @AddedInOrBefore(majorVersion = 33) 404 public long timestamp; 405 /** Fuel level in milliliters. Negative values indicate this property is unsupported. */ 406 @AddedInOrBefore(majorVersion = 33) 407 public float level; 408 409 /** @hide */ FuelLevelData()410 private FuelLevelData() {}; 411 } 412 413 /** 414 * Convenience method for obtaining a {@link FuelLevelData} object from a CarSensorEvent 415 * object with type {@link CarSensorManager#SENSOR_TYPE_FUEL_LEVEL}. 416 * 417 * @param dataParam an optional output parameter which, if non-null, will be used by this method 418 * instead of a newly created object. 419 * @return a FuelLevel object corresponding to the data contained in the CarSensorEvent. 420 * @hide 421 */ 422 @AddedInOrBefore(majorVersion = 33) getFuelLevelData(FuelLevelData dataParam)423 public FuelLevelData getFuelLevelData(FuelLevelData dataParam) { 424 FuelLevelData data = dataParam; 425 checkType(CarSensorManager.SENSOR_TYPE_FUEL_LEVEL); 426 if (data == null) { 427 data = new FuelLevelData(); 428 } 429 data.timestamp = timestamp; 430 if (floatValues == null) { 431 data.level = -1.0f; 432 } else { 433 if (floatValues[0] < 0) { 434 data.level = -1.0f; 435 } else { 436 data.level = floatValues[0]; 437 } 438 } 439 return data; 440 } 441 442 /** @hide */ 443 public static class OdometerData { 444 @AddedInOrBefore(majorVersion = 33) 445 public long timestamp; 446 @AddedInOrBefore(majorVersion = 33) 447 public float kms; 448 449 /** @hide */ OdometerData()450 private OdometerData() {}; 451 } 452 453 /** 454 * Convenience method for obtaining an {@link OdometerData} object from a CarSensorEvent 455 * object with type {@link CarSensorManager#SENSOR_TYPE_ODOMETER}. 456 * 457 * @param dataParam an optional output parameter which, if non-null, will be used by this method 458 * instead of a newly created object. 459 * @return an OdometerData object corresponding to the data contained in the CarSensorEvent. 460 * @hide 461 */ 462 @AddedInOrBefore(majorVersion = 33) getOdometerData(OdometerData dataParam)463 public OdometerData getOdometerData(OdometerData dataParam) { 464 OdometerData data = dataParam; 465 checkType(CarSensorManager.SENSOR_TYPE_ODOMETER); 466 if (data == null) { 467 data = new OdometerData(); 468 } 469 data.timestamp = timestamp; 470 data.kms = floatValues[0]; 471 return data; 472 } 473 474 /** @hide */ 475 public static class RpmData { 476 @AddedInOrBefore(majorVersion = 33) 477 public long timestamp; 478 @AddedInOrBefore(majorVersion = 33) 479 public float rpm; 480 481 /** @hide */ RpmData()482 private RpmData() {}; 483 } 484 485 /** 486 * Convenience method for obtaining a {@link RpmData} object from a CarSensorEvent 487 * object with type {@link CarSensorManager#SENSOR_TYPE_RPM}. 488 * 489 * @param dataParam an optional output parameter which, if non-null, will be used by this method 490 * instead of a newly created object. 491 * @return a RpmData object corresponding to the data contained in the CarSensorEvent. 492 * @hide 493 */ 494 @AddedInOrBefore(majorVersion = 33) getRpmData(RpmData dataParam)495 public RpmData getRpmData(RpmData dataParam) { 496 RpmData data = dataParam; 497 checkType(CarSensorManager.SENSOR_TYPE_RPM); 498 if (data == null) { 499 data = new RpmData(); 500 } 501 data.timestamp = timestamp; 502 data.rpm = floatValues[0]; 503 return data; 504 } 505 506 /** @hide */ 507 public static class CarSpeedData { 508 @AddedInOrBefore(majorVersion = 33) 509 public long timestamp; 510 @AddedInOrBefore(majorVersion = 33) 511 public float carSpeed; 512 513 /** @hide */ CarSpeedData()514 private CarSpeedData() {}; 515 } 516 517 /** 518 * Convenience method for obtaining a {@link CarSpeedData} object from a CarSensorEvent 519 * object with type {@link CarSensorManager#SENSOR_TYPE_CAR_SPEED}. 520 * 521 * @param dataParam an optional output parameter which, if non-null, will be used by this method 522 * instead of a newly created object. 523 * @return a CarSpeedData object corresponding to the data contained in the CarSensorEvent. 524 * @hide 525 */ 526 @AddedInOrBefore(majorVersion = 33) getCarSpeedData(CarSpeedData dataParam)527 public CarSpeedData getCarSpeedData(CarSpeedData dataParam) { 528 CarSpeedData data = dataParam; 529 checkType(CarSensorManager.SENSOR_TYPE_CAR_SPEED); 530 if (data == null) { 531 data = new CarSpeedData(); 532 } 533 data.timestamp = timestamp; 534 data.carSpeed = floatValues[0]; 535 return data; 536 } 537 538 /** @hide */ 539 public static class CarWheelTickDistanceData { 540 @AddedInOrBefore(majorVersion = 33) 541 public long timestamp; 542 @AddedInOrBefore(majorVersion = 33) 543 public long sensorResetCount; 544 @AddedInOrBefore(majorVersion = 33) 545 public long frontLeftWheelDistanceMm; 546 @AddedInOrBefore(majorVersion = 33) 547 public long frontRightWheelDistanceMm; 548 @AddedInOrBefore(majorVersion = 33) 549 public long rearRightWheelDistanceMm; 550 @AddedInOrBefore(majorVersion = 33) 551 public long rearLeftWheelDistanceMm; 552 553 /** @hide */ CarWheelTickDistanceData()554 private CarWheelTickDistanceData() {}; 555 } 556 557 /** 558 * Convenience method for obtaining a {@link CarWheelTickDistanceData} object from a 559 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_WHEEL_TICK_DISTANCE}. 560 * 561 * @param dataParam an optional output parameter which, if non-null, will be used by this method 562 * instead of a newly created object. 563 * @return CarWheelTickDistanceData object corresponding to data contained in the CarSensorEvent 564 * @hide 565 */ 566 @AddedInOrBefore(majorVersion = 33) getCarWheelTickDistanceData( CarWheelTickDistanceData dataParam)567 public CarWheelTickDistanceData getCarWheelTickDistanceData( 568 CarWheelTickDistanceData dataParam) { 569 CarWheelTickDistanceData data = dataParam; 570 checkType(CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE); 571 if (data == null) { 572 data = new CarWheelTickDistanceData(); 573 } 574 data.timestamp = timestamp; 575 data.sensorResetCount = longValues[INDEX_WHEEL_DISTANCE_RESET_COUNT]; 576 data.frontLeftWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_FRONT_LEFT]; 577 data.frontRightWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_FRONT_RIGHT]; 578 data.rearRightWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_REAR_RIGHT]; 579 data.rearLeftWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_REAR_LEFT]; 580 return data; 581 } 582 583 /** @hide */ 584 public static class CarAbsActiveData { 585 @AddedInOrBefore(majorVersion = 33) 586 public long timestamp; 587 @AddedInOrBefore(majorVersion = 33) 588 public boolean absIsActive; 589 590 /** @hide */ CarAbsActiveData()591 private CarAbsActiveData() {}; 592 } 593 594 /** 595 * Convenience method for obtaining a {@link CarAbsActiveData} object from a CarSensorEvent 596 * object with type {@link CarSensorManager#SENSOR_TYPE_ABS_ACTIVE}. 597 * 598 * @param dataParam an optional output parameter which, if non-null, will be used by this method 599 * instead of a newly created object. 600 * @return a CarAbsActiveData object corresponding to data contained in the CarSensorEvent. 601 * @hide 602 */ 603 @AddedInOrBefore(majorVersion = 33) getCarAbsActiveData(CarAbsActiveData dataParam)604 public CarAbsActiveData getCarAbsActiveData(CarAbsActiveData dataParam) { 605 CarAbsActiveData data = dataParam; 606 checkType(CarSensorManager.SENSOR_TYPE_ABS_ACTIVE); 607 if (data == null) { 608 data = new CarAbsActiveData(); 609 } 610 data.timestamp = timestamp; 611 data.absIsActive = intValues[0] == 1; 612 return data; 613 } 614 615 /** @hide */ 616 public static class CarTractionControlActiveData { 617 @AddedInOrBefore(majorVersion = 33) 618 public long timestamp; 619 @AddedInOrBefore(majorVersion = 33) 620 public boolean tractionControlIsActive; 621 622 /** @hide */ CarTractionControlActiveData()623 private CarTractionControlActiveData() {}; 624 } 625 626 /** 627 * Convenience method for obtaining a {@link CarTractionControlActiveData} object from a 628 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_TRACTION_CONTROL_ACTIVE}. 629 * 630 * @param dataParam an optional output parameter which, if non-null, will be used by this method 631 * instead of a newly created object. 632 * @return a CarTractionControlActiveData object corresponding to data contained in the 633 * CarSensorEvent. 634 * @hide 635 */ 636 @AddedInOrBefore(majorVersion = 33) getCarTractionControlActiveData( CarTractionControlActiveData dataParam)637 public CarTractionControlActiveData getCarTractionControlActiveData( 638 CarTractionControlActiveData dataParam) { 639 CarTractionControlActiveData data = dataParam; 640 checkType(CarSensorManager.SENSOR_TYPE_TRACTION_CONTROL_ACTIVE); 641 if (data == null) { 642 data = new CarTractionControlActiveData(); 643 } 644 data.timestamp = timestamp; 645 data.tractionControlIsActive = intValues[0] == 1; 646 return data; 647 } 648 649 /** @hide */ 650 public static class CarFuelDoorOpenData { 651 @AddedInOrBefore(majorVersion = 33) 652 public long timestamp; 653 @AddedInOrBefore(majorVersion = 33) 654 public boolean fuelDoorIsOpen; 655 656 /** @hide */ CarFuelDoorOpenData()657 private CarFuelDoorOpenData() {}; 658 } 659 660 /** 661 * Convenience method for obtaining a {@link CarFuelDoorOpenData} object from a 662 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_FUEL_DOOR_OPEN}. 663 * 664 * @param dataParam an optional output parameter which, if non-null, will be used by this method 665 * instead of a newly created object. 666 * @return a CarFuelDoorOpenData object corresponding to data contained in the 667 * CarSensorEvent. 668 * @hide 669 */ 670 @AddedInOrBefore(majorVersion = 33) getCarFuelDoorOpenData(CarFuelDoorOpenData dataParam)671 public CarFuelDoorOpenData getCarFuelDoorOpenData(CarFuelDoorOpenData dataParam) { 672 CarFuelDoorOpenData data = dataParam; 673 checkType(CarSensorManager.SENSOR_TYPE_FUEL_DOOR_OPEN); 674 if (data == null) { 675 data = new CarFuelDoorOpenData(); 676 } 677 data.timestamp = timestamp; 678 data.fuelDoorIsOpen = intValues[0] == 1; 679 return data; 680 } 681 682 /** @hide */ 683 public static class CarEvBatteryLevelData { 684 @AddedInOrBefore(majorVersion = 33) 685 public long timestamp; 686 /** Battery Level in Watt-hours */ 687 @AddedInOrBefore(majorVersion = 33) 688 public float evBatteryLevel; 689 690 /** @hide */ CarEvBatteryLevelData()691 private CarEvBatteryLevelData() {}; 692 } 693 694 /** 695 * Convenience method for obtaining a {@link CarEvBatteryLevelData} object from a 696 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_BATTERY_LEVEL}. 697 * 698 * @param dataParam an optional output parameter which, if non-null, will be used by this method 699 * instead of a newly created object. 700 * @return a CarEvBatteryLevelData object corresponding to data contained in the 701 * CarSensorEvent. 702 * @hide 703 */ 704 @AddedInOrBefore(majorVersion = 33) getCarEvBatteryLevelData(CarEvBatteryLevelData dataParam)705 public CarEvBatteryLevelData getCarEvBatteryLevelData(CarEvBatteryLevelData dataParam) { 706 CarEvBatteryLevelData data = dataParam; 707 checkType(CarSensorManager.SENSOR_TYPE_EV_BATTERY_LEVEL); 708 if (data == null) { 709 data = new CarEvBatteryLevelData(); 710 } 711 data.timestamp = timestamp; 712 if (floatValues == null) { 713 data.evBatteryLevel = -1.0f; 714 } else { 715 if (floatValues[0] < 0) { 716 data.evBatteryLevel = -1.0f; 717 } else { 718 data.evBatteryLevel = floatValues[0]; 719 } 720 } 721 return data; 722 } 723 724 /** @hide */ 725 public static class CarEvChargePortOpenData { 726 @AddedInOrBefore(majorVersion = 33) 727 public long timestamp; 728 @AddedInOrBefore(majorVersion = 33) 729 public boolean evChargePortIsOpen; 730 731 /** @hide */ CarEvChargePortOpenData()732 private CarEvChargePortOpenData() {}; 733 } 734 735 /** 736 * Convenience method for obtaining a {@link CarEvChargePortOpenData} object from a 737 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_CHARGE_PORT_OPEN}. 738 * 739 * @param dataParam an optional output parameter which, if non-null, will be used by this method 740 * instead of a newly created object. 741 * @return a CarEvChargePortOpenData object corresponding to data contained in the 742 * CarSensorEvent. 743 * @hide 744 */ 745 @AddedInOrBefore(majorVersion = 33) getCarEvChargePortOpenData(CarEvChargePortOpenData dataParam)746 public CarEvChargePortOpenData getCarEvChargePortOpenData(CarEvChargePortOpenData dataParam) { 747 CarEvChargePortOpenData data = dataParam; 748 checkType(CarSensorManager.SENSOR_TYPE_EV_CHARGE_PORT_OPEN); 749 if (data == null) { 750 data = new CarEvChargePortOpenData(); 751 } 752 data.timestamp = timestamp; 753 data.evChargePortIsOpen = intValues[0] == 1; 754 return data; 755 } 756 757 /** @hide */ 758 public static class CarEvChargePortConnectedData { 759 @AddedInOrBefore(majorVersion = 33) 760 public long timestamp; 761 @AddedInOrBefore(majorVersion = 33) 762 public boolean evChargePortIsConnected; 763 764 /** @hide */ CarEvChargePortConnectedData()765 private CarEvChargePortConnectedData() {}; 766 } 767 768 /** 769 * Convenience method for obtaining a {@link CarEvChargePortConnectedData} object from a 770 * CarSensorEvent with type {@link CarSensorManager#SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED}. 771 * 772 * @param dataParam an optional output parameter which, if non-null, will be used by this method 773 * instead of a newly created object. 774 * @return a CarEvChargePortConnectedData object corresponding to data contained in the 775 * CarSensorEvent. 776 * @hide 777 */ 778 @AddedInOrBefore(majorVersion = 33) getCarEvChargePortConnectedData( CarEvChargePortConnectedData dataParam)779 public CarEvChargePortConnectedData getCarEvChargePortConnectedData( 780 CarEvChargePortConnectedData dataParam) { 781 CarEvChargePortConnectedData data = dataParam; 782 checkType(CarSensorManager.SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED); 783 if (data == null) { 784 data = new CarEvChargePortConnectedData(); 785 } 786 data.timestamp = timestamp; 787 data.evChargePortIsConnected = intValues[0] == 1; 788 return data; 789 } 790 791 /** @hide */ 792 public static class CarEvBatteryChargeRateData { 793 @AddedInOrBefore(majorVersion = 33) 794 public long timestamp; 795 /** EV battery charging rate in mW. 796 * Positive values indicates battery being charged. Negative values indicate discharge */ 797 @AddedInOrBefore(majorVersion = 33) 798 public float evChargeRate; 799 800 /** @hide */ CarEvBatteryChargeRateData()801 private CarEvBatteryChargeRateData() {}; 802 } 803 804 /** 805 * Convenience method for obtaining a {@link CarEvBatteryChargeRateData} object from a 806 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_BATTERY_CHARGE_RATE}. 807 * 808 * @param dataParam an optional output parameter which, if non-null, will be used by this method 809 * instead of a newly created object. 810 * @return a CarEvBatteryChargeRateData object corresponding to data contained in the 811 * CarSensorEvent. 812 * @hide 813 */ 814 @AddedInOrBefore(majorVersion = 33) getCarEvBatteryChargeRateData( CarEvBatteryChargeRateData dataParam)815 public CarEvBatteryChargeRateData getCarEvBatteryChargeRateData( 816 CarEvBatteryChargeRateData dataParam) { 817 CarEvBatteryChargeRateData data = dataParam; 818 checkType(CarSensorManager.SENSOR_TYPE_EV_BATTERY_CHARGE_RATE); 819 if (data == null) { 820 data = new CarEvBatteryChargeRateData(); 821 } 822 data.timestamp = timestamp; 823 data.evChargeRate = floatValues[0]; 824 return data; 825 } 826 827 /** @hide */ 828 public static class CarEngineOilLevelData { 829 @AddedInOrBefore(majorVersion = 33) 830 public long timestamp; 831 @AddedInOrBefore(majorVersion = 33) 832 public int engineOilLevel; 833 834 /** @hide */ CarEngineOilLevelData()835 private CarEngineOilLevelData() {}; 836 } 837 838 /** 839 * Convenience method for obtaining a {@link CarEngineOilLevelData} object from a 840 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_ENGINE_OIL_LEVEL}. 841 * 842 * @param dataParam an optional output parameter, which, if non-null, will be used by this 843 * method instead of a newly created object. 844 * @return a CarEngineOilLEvelData object corresponding to data contained in the CarSensorEvent. 845 * @hide 846 */ 847 @AddedInOrBefore(majorVersion = 33) getCarEngineOilLevelData(CarEngineOilLevelData dataParam)848 public CarEngineOilLevelData getCarEngineOilLevelData(CarEngineOilLevelData dataParam) { 849 CarEngineOilLevelData data = dataParam; 850 checkType(CarSensorManager.SENSOR_TYPE_ENGINE_OIL_LEVEL); 851 if (data == null) { 852 data = new CarEngineOilLevelData(); 853 } 854 data.timestamp = timestamp; 855 data.engineOilLevel = intValues[0]; 856 return data; 857 } 858 859 /** @hide */ 860 @Override toString()861 public String toString() { 862 StringBuilder sb = new StringBuilder(); 863 sb.append(getClass().getName() + "["); 864 sb.append("type:" + Integer.toHexString(sensorType)); 865 if (floatValues != null && floatValues.length > 0) { 866 sb.append(" float values:"); 867 for (float v: floatValues) { 868 sb.append(" " + v); 869 } 870 } 871 if (intValues != null && intValues.length > 0) { 872 sb.append(" int values:"); 873 for (int v: intValues) { 874 sb.append(" " + v); 875 } 876 } 877 if (longValues != null && longValues.length > 0) { 878 sb.append(" long values:"); 879 for (long v: longValues) { 880 sb.append(" " + v); 881 } 882 } 883 sb.append("]"); 884 return sb.toString(); 885 } 886 } 887