1 /* 2 * Copyright (C) 2006 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.os; 18 19 import android.annotation.NonNull; 20 import android.util.AndroidException; 21 22 /** 23 * Parent exception for all Binder remote-invocation errors 24 * 25 * Note: not all exceptions from binder services will be subclasses of this. 26 * For instance, RuntimeException and several subclasses of it may be 27 * thrown as well as OutOfMemoryException. 28 * 29 * One common subclass is {@link DeadObjectException}. 30 */ 31 @android.ravenwood.annotation.RavenwoodKeepWholeClass 32 public class RemoteException extends AndroidException { RemoteException()33 public RemoteException() { 34 super(); 35 } 36 RemoteException(String message)37 public RemoteException(String message) { 38 super(message); 39 } 40 41 /** @hide */ RemoteException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)42 public RemoteException(String message, Throwable cause, boolean enableSuppression, 43 boolean writableStackTrace) { 44 super(message, cause, enableSuppression, writableStackTrace); 45 } 46 47 /** @hide */ RemoteException(Throwable cause)48 public RemoteException(Throwable cause) { 49 this(cause.getMessage(), cause, true, false); 50 } 51 52 /** 53 * Rethrow this as an unchecked runtime exception. 54 * <p> 55 * Apps making calls into other processes may end up persisting internal 56 * state or making security decisions based on the perceived success or 57 * failure of a call, or any default values returned. For this reason, we 58 * want to strongly throw when there was trouble with the transaction. 59 * 60 * @throws RuntimeException 61 */ 62 @NonNull rethrowAsRuntimeException()63 public RuntimeException rethrowAsRuntimeException() { 64 throw new RuntimeException(this); 65 } 66 67 /** 68 * Rethrow this exception when we know it came from the system server. This 69 * gives us an opportunity to throw a nice clean 70 * {@code DeadSystemRuntimeException} signal to avoid spamming logs with 71 * misleading stack traces. 72 * <p> 73 * Apps making calls into the system server may end up persisting internal 74 * state or making security decisions based on the perceived success or 75 * failure of a call, or any default values returned. For this reason, we 76 * want to strongly throw when there was trouble with the transaction. 77 * 78 * @throws RuntimeException 79 */ 80 @NonNull rethrowFromSystemServer()81 public RuntimeException rethrowFromSystemServer() { 82 if (this instanceof DeadObjectException) { 83 throw new DeadSystemRuntimeException(); 84 } else { 85 throw new RuntimeException(this); 86 } 87 } 88 } 89