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