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 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 CarDrivingStateEvent(int value, long time)98 public CarDrivingStateEvent(int value, long time) { 99 eventValue = value; 100 timeStamp = time; 101 } 102 CarDrivingStateEvent(Parcel in)103 private CarDrivingStateEvent(Parcel in) { 104 eventValue = in.readInt(); 105 timeStamp = in.readLong(); 106 } 107 108 @Override toString()109 public String toString() { 110 return eventValue + " " + timeStamp; 111 } 112 } 113