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