1 /*
2  * Copyright (C) 2020 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.hardware.property;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 
25 /**
26  * Error codes used in vehicle HAL interface.
27  *
28  * The list of status codes may be extended in future releases to include
29  * additional values.
30  * @hide
31  */
32 public final class VehicleHalStatusCode {
33 
34     /** No error detected in HAL.*/
35     public static final int STATUS_OK = 0;
36     /** Try again. */
37     public static final int STATUS_TRY_AGAIN = 1;
38     /** Invalid argument provide. */
39     public static final int STATUS_INVALID_ARG = 2;
40     /**
41      * This code must be returned when device that associated with the vehicle
42      * property is not available. For example, when client tries to set HVAC
43      * temperature when the whole HVAC unit is turned OFF.
44      */
45     public static final int STATUS_NOT_AVAILABLE = 3;
46     /** Access denied */
47     public static final int STATUS_ACCESS_DENIED = 4;
48     /** Something unexpected has happened in Vehicle HAL */
49     public static final int STATUS_INTERNAL_ERROR = 5;
50 
51     /**
52      * For features that are not available because the underlying feature is disabled.
53      *
54      * For platform versions before {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, this
55      * error will be mapped to {@link #STATUS_NOT_AVAILABLE}.
56      */
57     public static final int STATUS_NOT_AVAILABLE_DISABLED = 6;
58     /**
59      * For features that are not available because the vehicle speed is too low.
60      *
61      * For platform versions before {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, this
62      * error will be mapped to {@link #STATUS_NOT_AVAILABLE}.
63      */
64     public static final int STATUS_NOT_AVAILABLE_SPEED_LOW = 7;
65     /**
66      * For features that are not available because the vehicle speed is too high.
67      *
68      * For platform versions before {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, this
69      * error will be mapped to {@link #STATUS_NOT_AVAILABLE}.
70      */
71     public static final int STATUS_NOT_AVAILABLE_SPEED_HIGH = 8;
72     /**
73      * For features that are not available because of bad camera or sensor visibility. Examples
74      * might be bird poop blocking the camera or a bumper cover blocking an ultrasonic sensor.
75      *
76      * For platform versions before {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, this
77      * error will be mapped to {@link #STATUS_NOT_AVAILABLE}.
78      */
79     public static final int STATUS_NOT_AVAILABLE_POOR_VISIBILITY = 9;
80     /**
81      * The feature cannot be accessed due to safety reasons. Eg. System could be
82      * in a faulty state, an object or person could be blocking the requested
83      * operation such as closing a trunk door, etc.
84      *
85      * For platform versions before {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, this
86      * error will be mapped to {@link #STATUS_NOT_AVAILABLE}.
87      */
88     public static final int STATUS_NOT_AVAILABLE_SAFETY = 10;
89 
90     /**
91      * Returns a user-friendly representation of a {@code VehicleHalStatusCode}.
92      */
93     @NonNull
toString( @ehicleHalStatusCodeInt int vehicleHalStatusCode)94     public static String toString(
95             @VehicleHalStatusCodeInt int vehicleHalStatusCode) {
96         switch (vehicleHalStatusCode) {
97             case STATUS_OK:
98                 return "STATUS_OK";
99             case STATUS_TRY_AGAIN:
100                 return "STATUS_TRY_AGAIN";
101             case STATUS_INVALID_ARG:
102                 return "STATUS_INVALID_ARG";
103             case STATUS_NOT_AVAILABLE:
104                 return "STATUS_NOT_AVAILABLE";
105             case STATUS_ACCESS_DENIED:
106                 return "STATUS_ACCESS_DENIED";
107             case STATUS_INTERNAL_ERROR:
108                 return "STATUS_INTERNAL_ERROR";
109             case STATUS_NOT_AVAILABLE_DISABLED:
110                 return "STATUS_NOT_AVAILABLE_DISABLED";
111             case STATUS_NOT_AVAILABLE_SPEED_LOW:
112                 return "STATUS_NOT_AVAILABLE_SPEED_LOW";
113             case STATUS_NOT_AVAILABLE_SPEED_HIGH:
114                 return "STATUS_NOT_AVAILABLE_SPEED_HIGH";
115             case STATUS_NOT_AVAILABLE_POOR_VISIBILITY:
116                 return "STATUS_NOT_AVAILABLE_POOR_VISIBILITY";
117             case STATUS_NOT_AVAILABLE_SAFETY:
118                 return "STATUS_NOT_AVAILABLE_SAFETY";
119             default:
120                 return Integer.toString(vehicleHalStatusCode);
121         }
122     }
123 
124     /** @hide */
125     @IntDef({STATUS_OK, STATUS_TRY_AGAIN, STATUS_INVALID_ARG, STATUS_NOT_AVAILABLE,
126         STATUS_ACCESS_DENIED, STATUS_INTERNAL_ERROR, STATUS_NOT_AVAILABLE_DISABLED,
127         STATUS_NOT_AVAILABLE_SPEED_LOW, STATUS_NOT_AVAILABLE_SPEED_HIGH,
128         STATUS_NOT_AVAILABLE_POOR_VISIBILITY, STATUS_NOT_AVAILABLE_SAFETY})
129     @Retention(RetentionPolicy.SOURCE)
130     public @interface VehicleHalStatusCodeInt {}
131 
VehicleHalStatusCode()132     private VehicleHalStatusCode() {}
133 }
134