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 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 */ 29 // @SystemApi 30 public class LowpanException extends AndroidException { LowpanException()31 public LowpanException() {} 32 LowpanException(String message)33 public LowpanException(String message) { 34 super(message); 35 } 36 LowpanException(String message, Throwable cause)37 public LowpanException(String message, Throwable cause) { 38 super(message, cause); 39 } 40 LowpanException(Exception cause)41 public LowpanException(Exception cause) { 42 super(cause); 43 } 44 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 */ rethrowFromServiceSpecificException(ServiceSpecificException e)51 static LowpanException rethrowFromServiceSpecificException(ServiceSpecificException e) 52 throws LowpanException { 53 switch (e.errorCode) { 54 case ILowpanInterface.ERROR_DISABLED: 55 throw new InterfaceDisabledException(e); 56 57 case ILowpanInterface.ERROR_WRONG_STATE: 58 throw new WrongStateException(e); 59 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: 88 default: 89 throw new LowpanRuntimeException(e); 90 } 91 } 92 } 93