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 something unexpected happened in cars. 27 */ 28 public class CarInternalErrorException extends RuntimeException { 29 private static final int VENDOR_ERROR_CODE_SUCCESS = 0; 30 31 private int mVendorErrorCode; 32 CarInternalErrorException(int propertyId, int areaId)33 CarInternalErrorException(int propertyId, int areaId) { 34 this(propertyId, areaId, VENDOR_ERROR_CODE_SUCCESS); 35 } 36 CarInternalErrorException(int propertyId, int areaId, int vendorErrorCode)37 CarInternalErrorException(int propertyId, int areaId, int vendorErrorCode) { 38 super("Property ID: " + VehiclePropertyIds.toString(propertyId) + " area ID: " 39 + toHexString(areaId) + " - raised an internal error in cars with " 40 + "vendor error code: " + vendorErrorCode); 41 mVendorErrorCode = vendorErrorCode; 42 } 43 44 /** 45 * Gets the vendor error codes to allow for more detailed error codes. 46 * 47 * @return Vendor error code if it is set, otherwise 0. A vendor error code will have a range 48 * from 0x0000 to 0xffff. 49 * 50 * @hide 51 */ 52 @SystemApi getVendorErrorCode()53 public int getVendorErrorCode() { 54 return mVendorErrorCode; 55 } 56 } 57