blob: bd553ce3be375a2671da16b8c2e48f977afa5c1a [file] [log] [blame]
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -08001/*
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
17package android.car.drivingstate;
18
19import android.annotation.IntDef;
20import android.annotation.SystemApi;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.lang.annotation.Retention;
25import 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
Yao, Yuxing64cca8d2019-03-20 10:41:47 -070034public final class CarDrivingStateEvent implements Parcelable {
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080035
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.
Ram Periathiruvadi25c16f12017-11-17 16:48:37 -080047 */
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
77 public int describeContents() {
78 return 0;
79 }
80
81 @Override
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 public CarDrivingStateEvent createFromParcel(Parcel in) {
90 return new CarDrivingStateEvent(in);
91 }
92
93 public CarDrivingStateEvent[] newArray(int size) {
94 return new CarDrivingStateEvent[size];
95 }
96 };
97
98 public CarDrivingStateEvent(int value, long time) {
99 eventValue = value;
100 timeStamp = time;
101 }
102
103 private CarDrivingStateEvent(Parcel in) {
104 eventValue = in.readInt();
105 timeStamp = in.readLong();
106 }
107
108 @Override
109 public String toString() {
110 return eventValue + " " + timeStamp;
111 }
112}