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