• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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      * TODO: (b/72157869) - Should speed that differentiates moving vs idling be configurable?
48      */
49     public static final int DRIVING_STATE_IDLING = 1;
50     /**
51      * Car is moving.  Gear is not in parked mode and speed of the vehicle is non zero.
52      */
53     public static final int DRIVING_STATE_MOVING = 2;
54 
55     /** @hide */
56     @IntDef({DRIVING_STATE_UNKNOWN,
57             DRIVING_STATE_PARKED,
58             DRIVING_STATE_IDLING,
59             DRIVING_STATE_MOVING})
60     @Retention(RetentionPolicy.SOURCE)
61     public @interface CarDrivingState {
62     }
63 
64     /**
65      * Time at which this driving state was inferred based on the car's sensors.
66      * It is the elapsed time in nanoseconds since system boot.
67      */
68     public final long timeStamp;
69 
70     /**
71      * The Car's driving state.
72      */
73     @CarDrivingState
74     public final int eventValue;
75 
76 
77     @Override
describeContents()78     public int describeContents() {
79         return 0;
80     }
81 
82     @Override
writeToParcel(Parcel dest, int flags)83     public void writeToParcel(Parcel dest, int flags) {
84         dest.writeInt(eventValue);
85         dest.writeLong(timeStamp);
86     }
87 
88     public static final Parcelable.Creator<CarDrivingStateEvent> CREATOR
89             = new Parcelable.Creator<CarDrivingStateEvent>() {
90         public CarDrivingStateEvent createFromParcel(Parcel in) {
91             return new CarDrivingStateEvent(in);
92         }
93 
94         public CarDrivingStateEvent[] newArray(int size) {
95             return new CarDrivingStateEvent[size];
96         }
97     };
98 
CarDrivingStateEvent(int value, long time)99     public CarDrivingStateEvent(int value, long time) {
100         eventValue = value;
101         timeStamp = time;
102     }
103 
CarDrivingStateEvent(Parcel in)104     private CarDrivingStateEvent(Parcel in) {
105         eventValue = in.readInt();
106         timeStamp = in.readLong();
107     }
108 
109     @Override
toString()110     public String toString() {
111         return eventValue + " " + timeStamp;
112     }
113 }
114