1 /*
2  * Copyright (C) 2018 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.drivingstate;
18 
19 import android.annotation.IntDef;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 
27 /**
28  * Driving State related events.  Driving State of a car conveys if the car is currently parked,
29  * idling or moving.
30  *
31  * @hide
32  */
33 @SystemApi
34 public final class CarDrivingStateEvent implements Parcelable {
35 
36     // New Driving States
37     /**
38      * This is when we don't have enough information to infer the car's driving state.
39      */
40     public static final int DRIVING_STATE_UNKNOWN = -1;
41     /**
42      * Car is parked - Gear is in Parked mode.
43      */
44     public static final int DRIVING_STATE_PARKED = 0;
45     /**
46      * Car is idling.  Gear is not in Parked mode and Speed of the vehicle is zero.
47      */
48     public static final int DRIVING_STATE_IDLING = 1;
49     /**
50      * Car is moving.  Gear is not in parked mode and speed of the vehicle is non zero.
51      */
52     public static final int DRIVING_STATE_MOVING = 2;
53 
54     /** @hide */
55     @IntDef({DRIVING_STATE_UNKNOWN,
56             DRIVING_STATE_PARKED,
57             DRIVING_STATE_IDLING,
58             DRIVING_STATE_MOVING})
59     @Retention(RetentionPolicy.SOURCE)
60     public @interface CarDrivingState {
61     }
62 
63     /**
64      * Time at which this driving state was inferred based on the car's sensors.
65      * It is the elapsed time in nanoseconds since system boot.
66      */
67     public final long timeStamp;
68 
69     /**
70      * The Car's driving state.
71      */
72     @CarDrivingState
73     public final int eventValue;
74 
75 
76     @Override
describeContents()77     public int describeContents() {
78         return 0;
79     }
80 
81     @Override
writeToParcel(Parcel dest, int flags)82     public void writeToParcel(Parcel dest, int flags) {
83         dest.writeInt(eventValue);
84         dest.writeLong(timeStamp);
85     }
86 
87     public static final Parcelable.Creator<CarDrivingStateEvent> CREATOR =
88             new Parcelable.Creator<CarDrivingStateEvent>() {
89 
90                 @Override
91                 public CarDrivingStateEvent createFromParcel(Parcel in) {
92                     return new CarDrivingStateEvent(in);
93                 }
94 
95                 @Override
96                 public CarDrivingStateEvent[] newArray(int size) {
97                     return new CarDrivingStateEvent[size];
98                 }
99             };
100 
CarDrivingStateEvent(int value, long time)101     public CarDrivingStateEvent(int value, long time) {
102         eventValue = value;
103         timeStamp = time;
104     }
105 
CarDrivingStateEvent(Parcel in)106     private CarDrivingStateEvent(Parcel in) {
107         eventValue = in.readInt();
108         timeStamp = in.readLong();
109     }
110 
111     @Override
toString()112     public String toString() {
113         return eventValue + " " + timeStamp;
114     }
115 }
116