Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.net.lowpan; |
| 18 | |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 19 | import android.os.ServiceSpecificException; |
| 20 | import android.util.AndroidException; |
| 21 | |
| 22 | /** |
| 23 | * <code>LowpanException</code> is thrown if an action to a LoWPAN interface could not be performed |
| 24 | * or a LoWPAN interface property could not be fetched or changed. |
| 25 | * |
| 26 | * @see LowpanInterface |
| 27 | * @hide |
| 28 | */ |
Robert Quattlebaum | 325b7f5 | 2017-06-06 16:51:41 -0700 | [diff] [blame] | 29 | // @SystemApi |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 30 | public class LowpanException extends AndroidException { |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 31 | public LowpanException() {} |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 32 | |
| 33 | public LowpanException(String message) { |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 34 | super(message); |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 37 | public LowpanException(String message, Throwable cause) { |
| 38 | super(message, cause); |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 41 | public LowpanException(Exception cause) { |
| 42 | super(cause); |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 45 | /* This method returns LowpanException so that the caller |
| 46 | * can add "throw" before the invocation of this method. |
| 47 | * This might seem superfluous, but it is actually to |
| 48 | * help provide a hint to the java compiler that this |
| 49 | * function will not return. |
| 50 | */ |
| 51 | static LowpanException rethrowFromServiceSpecificException(ServiceSpecificException e) |
| 52 | throws LowpanException { |
| 53 | switch (e.errorCode) { |
| 54 | case ILowpanInterface.ERROR_DISABLED: |
| 55 | throw new InterfaceDisabledException(e); |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 56 | |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 57 | case ILowpanInterface.ERROR_WRONG_STATE: |
| 58 | throw new WrongStateException(e); |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 59 | |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 60 | case ILowpanInterface.ERROR_CANCELED: |
| 61 | throw new OperationCanceledException(e); |
| 62 | |
| 63 | case ILowpanInterface.ERROR_JOIN_FAILED_UNKNOWN: |
| 64 | throw new JoinFailedException(e); |
| 65 | |
| 66 | case ILowpanInterface.ERROR_JOIN_FAILED_AT_SCAN: |
| 67 | throw new JoinFailedAtScanException(e); |
| 68 | |
| 69 | case ILowpanInterface.ERROR_JOIN_FAILED_AT_AUTH: |
| 70 | throw new JoinFailedAtAuthException(e); |
| 71 | |
| 72 | case ILowpanInterface.ERROR_FORM_FAILED_AT_SCAN: |
| 73 | throw new NetworkAlreadyExistsException(e); |
| 74 | |
| 75 | case ILowpanInterface.ERROR_FEATURE_NOT_SUPPORTED: |
| 76 | throw new LowpanException( |
| 77 | e.getMessage() != null ? e.getMessage() : "Feature not supported", e); |
| 78 | |
| 79 | case ILowpanInterface.ERROR_NCP_PROBLEM: |
| 80 | throw new LowpanRuntimeException( |
| 81 | e.getMessage() != null ? e.getMessage() : "NCP problem", e); |
| 82 | |
| 83 | case ILowpanInterface.ERROR_INVALID_ARGUMENT: |
| 84 | throw new LowpanRuntimeException( |
| 85 | e.getMessage() != null ? e.getMessage() : "Invalid argument", e); |
| 86 | |
| 87 | case ILowpanInterface.ERROR_UNSPECIFIED: |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 88 | default: |
Robert Quattlebaum | 865fdc7 | 2017-07-14 12:09:59 -0700 | [diff] [blame] | 89 | throw new LowpanRuntimeException(e); |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 90 | } |
Robert Quattlebaum | 4e0c219 | 2017-02-08 12:13:19 -0800 | [diff] [blame] | 91 | } |
| 92 | } |