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