1 /* 2 * Copyright (C) 2019 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 com.android.server.soundtrigger_middleware; 18 19 import android.annotation.NonNull; 20 21 /** 22 * This exception represents a non-zero status code returned by a HAL invocation. 23 * Depending on the operation that threw the error, the integrity of the HAL implementation and the 24 * client's tolerance to error, this error may or may not be recoverable. The HAL itself is expected 25 * to retain the state it had prior to the invocation (so, unless the error is a result of a HAL 26 * bug, normal operation may resume). 27 * <p> 28 * The reason why this is a RuntimeException, even though the HAL interface allows returning them 29 * is because we expect none of them to actually occur as part of correct usage of the HAL. 30 * 31 * @hide 32 */ 33 public class HalException extends RuntimeException { 34 public final int errorCode; 35 HalException(int errorCode, @NonNull String message)36 public HalException(int errorCode, @NonNull String message) { 37 super(message); 38 this.errorCode = errorCode; 39 } 40 HalException(int errorCode)41 public HalException(int errorCode) { 42 this.errorCode = errorCode; 43 } 44 45 @Override toString()46 public @NonNull String toString() { 47 return super.toString() + " (code " + errorCode + ")"; 48 } 49 } 50