The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 18 | |
Roshan Pius | 148e86e | 2019-11-13 12:40:01 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.util.AndroidException; |
| 21 | |
| 22 | /** |
| 23 | * Parent exception for all Binder remote-invocation errors |
| 24 | */ |
| 25 | public class RemoteException extends AndroidException { |
| 26 | public RemoteException() { |
| 27 | super(); |
| 28 | } |
Jeff Brown | 0bde66a | 2011-11-07 12:50:08 -0800 | [diff] [blame] | 29 | |
| 30 | public RemoteException(String message) { |
| 31 | super(message); |
| 32 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 33 | |
Fyodor Kupolov | a81b8c0 | 2017-11-13 15:51:03 -0800 | [diff] [blame] | 34 | /** @hide */ |
| 35 | public RemoteException(String message, Throwable cause, boolean enableSuppression, |
| 36 | boolean writableStackTrace) { |
| 37 | super(message, cause, enableSuppression, writableStackTrace); |
| 38 | } |
| 39 | |
Roshan Pius | 148e86e | 2019-11-13 12:40:01 -0800 | [diff] [blame] | 40 | /** |
| 41 | * Rethrow this as an unchecked runtime exception. |
| 42 | * <p> |
| 43 | * Apps making calls into other processes may end up persisting internal |
| 44 | * state or making security decisions based on the perceived success or |
| 45 | * failure of a call, or any default values returned. For this reason, we |
| 46 | * want to strongly throw when there was trouble with the transaction. |
Roshan Pius | 866e911 | 2019-11-20 14:47:51 -0800 | [diff] [blame] | 47 | * |
| 48 | * @throws RuntimeException |
Roshan Pius | 148e86e | 2019-11-13 12:40:01 -0800 | [diff] [blame] | 49 | */ |
| 50 | @NonNull |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 51 | public RuntimeException rethrowAsRuntimeException() { |
| 52 | throw new RuntimeException(this); |
| 53 | } |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Rethrow this exception when we know it came from the system server. This |
| 57 | * gives us an opportunity to throw a nice clean |
| 58 | * {@link DeadSystemException} signal to avoid spamming logs with |
| 59 | * misleading stack traces. |
| 60 | * <p> |
| 61 | * Apps making calls into the system server may end up persisting internal |
| 62 | * state or making security decisions based on the perceived success or |
| 63 | * failure of a call, or any default values returned. For this reason, we |
| 64 | * want to strongly throw when there was trouble with the transaction. |
Roshan Pius | 866e911 | 2019-11-20 14:47:51 -0800 | [diff] [blame] | 65 | * |
| 66 | * @throws RuntimeException |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 67 | */ |
Roshan Pius | 148e86e | 2019-11-13 12:40:01 -0800 | [diff] [blame] | 68 | @NonNull |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 69 | public RuntimeException rethrowFromSystemServer() { |
| 70 | if (this instanceof DeadObjectException) { |
| 71 | throw new RuntimeException(new DeadSystemException()); |
| 72 | } else { |
| 73 | throw new RuntimeException(this); |
| 74 | } |
| 75 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | } |