blob: 5dfce48d3f17d4433f80c7c8600c82ad82c3b673 [file] [log] [blame]
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -08001/*
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
17package android.net.lowpan;
18
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080019import android.os.ServiceSpecificException;
20import 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 Quattlebaum325b7f52017-06-06 16:51:41 -070029// @SystemApi
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080030public class LowpanException extends AndroidException {
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070031 public LowpanException() {}
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080032
33 public LowpanException(String message) {
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070034 super(message);
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080035 }
36
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070037 public LowpanException(String message, Throwable cause) {
38 super(message, cause);
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080039 }
40
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070041 public LowpanException(Exception cause) {
42 super(cause);
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080043 }
44
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070045 /* 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 Quattlebaum4e0c2192017-02-08 12:13:19 -080056
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070057 case ILowpanInterface.ERROR_WRONG_STATE:
58 throw new WrongStateException(e);
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080059
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070060 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 Quattlebaum4e0c2192017-02-08 12:13:19 -080088 default:
Robert Quattlebaum865fdc72017-07-14 12:09:59 -070089 throw new LowpanRuntimeException(e);
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080090 }
Robert Quattlebaum4e0c2192017-02-08 12:13:19 -080091 }
92}