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