1 /* 2 * Copyright 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.telephony; 18 19 import android.annotation.IntDef; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.RemoteException; 23 import android.telephony.NetworkService.NetworkServiceProvider; 24 25 import com.android.telephony.Rlog; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * Network service callback. Object of this class is passed to NetworkServiceProvider upon 32 * calling requestNetworkRegistrationInfo, to receive asynchronous feedback from 33 * NetworkServiceProvider upon onRequestNetworkRegistrationInfoComplete. It's like a wrapper of 34 * INetworkServiceCallback because INetworkServiceCallback can't be a parameter type in public APIs. 35 * 36 * @hide 37 */ 38 @SystemApi 39 public class NetworkServiceCallback { 40 41 private static final String mTag = NetworkServiceCallback.class.getSimpleName(); 42 43 /** 44 * Result of network requests 45 * @hide 46 */ 47 @Retention(RetentionPolicy.SOURCE) 48 @IntDef({RESULT_SUCCESS, RESULT_ERROR_UNSUPPORTED, RESULT_ERROR_INVALID_ARG, RESULT_ERROR_BUSY, 49 RESULT_ERROR_ILLEGAL_STATE, RESULT_ERROR_FAILED}) 50 public @interface Result {} 51 52 /** Request is completed successfully */ 53 public static final int RESULT_SUCCESS = 0; 54 /** Request is not support */ 55 public static final int RESULT_ERROR_UNSUPPORTED = 1; 56 /** Request contains invalid arguments */ 57 public static final int RESULT_ERROR_INVALID_ARG = 2; 58 /** Service is busy */ 59 public static final int RESULT_ERROR_BUSY = 3; 60 /** Request sent in illegal state */ 61 public static final int RESULT_ERROR_ILLEGAL_STATE = 4; 62 /** Request failed */ 63 public static final int RESULT_ERROR_FAILED = 5; 64 65 private final INetworkServiceCallback mCallback; 66 67 /** @hide */ NetworkServiceCallback(INetworkServiceCallback callback)68 public NetworkServiceCallback(INetworkServiceCallback callback) { 69 mCallback = callback; 70 } 71 72 /** 73 * Called to indicate result of 74 * {@link NetworkServiceProvider#requestNetworkRegistrationInfo(int, NetworkServiceCallback)} 75 * 76 * @param result Result status like {@link NetworkServiceCallback#RESULT_SUCCESS} or 77 * {@link NetworkServiceCallback#RESULT_ERROR_UNSUPPORTED} 78 * @param state The state information to be returned to callback. 79 */ onRequestNetworkRegistrationInfoComplete(int result, @Nullable NetworkRegistrationInfo state)80 public void onRequestNetworkRegistrationInfoComplete(int result, 81 @Nullable NetworkRegistrationInfo state) { 82 if (mCallback != null) { 83 try { 84 mCallback.onRequestNetworkRegistrationInfoComplete(result, state); 85 } catch (RemoteException e) { 86 Rlog.e(mTag, "Failed to onRequestNetworkRegistrationInfoComplete on the remote"); 87 } 88 } else { 89 Rlog.e(mTag, "onRequestNetworkRegistrationInfoComplete callback is null."); 90 } 91 } 92 }