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