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