1 /*
2  * Copyright (C) 2024 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.FlaggedApi;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.car.feature.Flags;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 
27 /**
28  * Detailed error codes used in vehicle HAL interface.
29  *
30  * The list of error codes may be extended in future releases to include additional values.
31  */
32 @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
33 public final class DetailedErrorCode {
34     /**
35      * General not available error code. Used to support backward compatibility and when other
36      * error codes don't cover the not available reason.
37      */
38     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
39     public static final int NO_DETAILED_ERROR_CODE = 0;
40 
41     /**
42      * For features that are not available because the underlying feature is disabled.
43      */
44     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
45     public static final int NOT_AVAILABLE_DISABLED =
46             PropertyNotAvailableErrorCode.NOT_AVAILABLE_DISABLED;
47     /**
48      * For features that are not available because the vehicle speed is too low.
49      */
50     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
51     public static final int NOT_AVAILABLE_SPEED_LOW =
52             PropertyNotAvailableErrorCode.NOT_AVAILABLE_SPEED_LOW;
53     /**
54      * For features that are not available because the vehicle speed is too high.
55      */
56     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
57     public static final int NOT_AVAILABLE_SPEED_HIGH =
58             PropertyNotAvailableErrorCode.NOT_AVAILABLE_SPEED_HIGH;
59     /**
60      * For features that are not available because of bad camera or sensor visibility. Examples
61      * might be bird poop blocking the camera or a bumper cover blocking an ultrasonic sensor.
62      */
63     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
64     public static final int NOT_AVAILABLE_POOR_VISIBILITY =
65             PropertyNotAvailableErrorCode.NOT_AVAILABLE_POOR_VISIBILITY;
66     /**
67      * The feature cannot be accessed due to safety reasons. Eg. System could be
68      * in a faulty state, an object or person could be blocking the requested
69      * operation such as closing a trunk door, etc..
70      */
71     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
72     public static final int NOT_AVAILABLE_SAFETY =
73             PropertyNotAvailableErrorCode.NOT_AVAILABLE_SAFETY;
74 
75     /**
76      * Returns a user-friendly representation of a {@code DetailedErrorCode}.
77      */
78     @FlaggedApi(Flags.FLAG_CAR_PROPERTY_DETAILED_ERROR_CODES)
79     @NonNull
toString( @etailedErrorCodeInt int detailedErrorCode)80     public static String toString(
81             @DetailedErrorCodeInt int detailedErrorCode) {
82         switch (detailedErrorCode) {
83             case NO_DETAILED_ERROR_CODE:
84                 return "NO_DETAILED_ERROR_CODE";
85             case NOT_AVAILABLE_DISABLED:
86                 return "NOT_AVAILABLE_DISABLED";
87             case NOT_AVAILABLE_SPEED_LOW:
88                 return "NOT_AVAILABLE_SPEED_LOW";
89             case NOT_AVAILABLE_SPEED_HIGH:
90                 return "NOT_AVAILABLE_SPEED_HIGH";
91             case NOT_AVAILABLE_POOR_VISIBILITY:
92                 return "NOT_AVAILABLE_POOR_VISIBILITY";
93             case NOT_AVAILABLE_SAFETY:
94                 return "NOT_AVAILABLE_SAFETY";
95             default:
96                 return Integer.toString(detailedErrorCode);
97         }
98     }
99 
100     /** @hide */
101     @IntDef({NO_DETAILED_ERROR_CODE, NOT_AVAILABLE_DISABLED,
102         NOT_AVAILABLE_SPEED_LOW, NOT_AVAILABLE_SPEED_HIGH,
103         NOT_AVAILABLE_POOR_VISIBILITY, NOT_AVAILABLE_SAFETY})
104     @Retention(RetentionPolicy.SOURCE)
105     public @interface DetailedErrorCodeInt {}
106 
DetailedErrorCode()107     private DetailedErrorCode() {}
108 }
109