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 static com.android.car.internal.util.DebugUtils.toAreaIdString; 20 21 import android.annotation.SystemApi; 22 import android.car.VehiclePropertyIds; 23 24 /** 25 * Exception thrown when the vehicle property is not available because of the current state of the 26 * vehicle. 27 * 28 * <p>For example, {@link android.car.VehiclePropertyIds#HVAC_FAN_SPEED} is unavailable because 29 * {@link android.car.VehiclePropertyIds#HVAC_POWER_ON} is {@code false}. 30 */ 31 public class PropertyNotAvailableException extends IllegalStateException { 32 private int mDetailedErrorCode = PropertyNotAvailableErrorCode.NOT_AVAILABLE; 33 private int mVendorErrorCode; 34 35 /** 36 * @hide 37 */ PropertyNotAvailableException(int propertyId, int areaId, int vendorErrorCode)38 public PropertyNotAvailableException(int propertyId, int areaId, int vendorErrorCode) { 39 super("Property ID: " + VehiclePropertyIds.toString(propertyId) + " area ID: " 40 + toAreaIdString(propertyId, areaId) 41 + " - is not available because of vendor error code: " + vendorErrorCode); 42 mVendorErrorCode = vendorErrorCode; 43 } 44 45 /** 46 * @hide 47 */ PropertyNotAvailableException(int propertyId, int areaId, int detailedErrorCode, int vendorErrorCode)48 public PropertyNotAvailableException(int propertyId, int areaId, int detailedErrorCode, 49 int vendorErrorCode) { 50 super("Property ID: " + VehiclePropertyIds.toString(propertyId) + " area ID: " 51 + toAreaIdString(propertyId, areaId) 52 + " - is not available because of status code: " 53 + PropertyNotAvailableErrorCode.toString(detailedErrorCode)); 54 mDetailedErrorCode = detailedErrorCode; 55 mVendorErrorCode = vendorErrorCode; 56 } 57 58 /** 59 * {@link PropertyNotAvailableErrorCode} provides more detailed information on why the vehicle 60 * property is not available. These must be a value defined in 61 * {@link PropertyNotAvailableErrorCode}. The values in {@link PropertyNotAvailableErrorCode} 62 * may be extended in the future to include additional error codes. 63 */ getDetailedErrorCode()64 public int getDetailedErrorCode() { 65 return mDetailedErrorCode; 66 } 67 68 /** 69 * Gets the vendor error codes to allow for more detailed error codes. 70 * 71 * @return Vendor error code if it is set, otherwise 0. A vendor error code will have a range 72 * from 0x0000 to 0xffff. 73 * 74 * @hide 75 */ 76 @SystemApi getVendorErrorCode()77 public int getVendorErrorCode() { 78 return mVendorErrorCode; 79 } 80 } 81