blob: e8e73ee86f589dc766abd96a01b454224aabd38b [file] [log] [blame]
Jack Yud5f1de12017-12-21 11:00:05 -08001/*
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
17package android.telephony;
18
19import android.annotation.IntDef;
Jack Yu7338e5c2019-03-05 11:00:12 -080020import android.annotation.Nullable;
Jack Yud5f1de12017-12-21 11:00:05 -080021import android.annotation.SystemApi;
22import android.os.RemoteException;
23import android.telephony.NetworkService.NetworkServiceProvider;
24
Meng Wang1dbea2f2020-01-30 12:25:08 -080025import com.android.telephony.Rlog;
26
Jack Yud5f1de12017-12-21 11:00:05 -080027import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
Jack Yud5f1de12017-12-21 11:00:05 -080029
30/**
31 * Network service callback. Object of this class is passed to NetworkServiceProvider upon
Jack Yu806b6422019-03-18 00:12:03 -070032 * 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.
Jack Yud5f1de12017-12-21 11:00:05 -080035 *
36 * @hide
37 */
38@SystemApi
39public 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
Jack Yu09ef1cb2019-08-18 18:51:30 -070065 private final INetworkServiceCallback mCallback;
Jack Yud5f1de12017-12-21 11:00:05 -080066
67 /** @hide */
68 public NetworkServiceCallback(INetworkServiceCallback callback) {
Jack Yu09ef1cb2019-08-18 18:51:30 -070069 mCallback = callback;
Jack Yud5f1de12017-12-21 11:00:05 -080070 }
71
72 /**
73 * Called to indicate result of
Jack Yu806b6422019-03-18 00:12:03 -070074 * {@link NetworkServiceProvider#requestNetworkRegistrationInfo(int, NetworkServiceCallback)}
Jack Yud5f1de12017-12-21 11:00:05 -080075 *
76 * @param result Result status like {@link NetworkServiceCallback#RESULT_SUCCESS} or
Jack Yu806b6422019-03-18 00:12:03 -070077 * {@link NetworkServiceCallback#RESULT_ERROR_UNSUPPORTED}
Jack Yud5f1de12017-12-21 11:00:05 -080078 * @param state The state information to be returned to callback.
79 */
Jack Yu806b6422019-03-18 00:12:03 -070080 public void onRequestNetworkRegistrationInfoComplete(int result,
81 @Nullable NetworkRegistrationInfo state) {
Jack Yu09ef1cb2019-08-18 18:51:30 -070082 if (mCallback != null) {
Jack Yud5f1de12017-12-21 11:00:05 -080083 try {
Jack Yu09ef1cb2019-08-18 18:51:30 -070084 mCallback.onRequestNetworkRegistrationInfoComplete(result, state);
Jack Yud5f1de12017-12-21 11:00:05 -080085 } catch (RemoteException e) {
Jack Yu806b6422019-03-18 00:12:03 -070086 Rlog.e(mTag, "Failed to onRequestNetworkRegistrationInfoComplete on the remote");
Jack Yud5f1de12017-12-21 11:00:05 -080087 }
Malcolm Chen45144252018-03-29 19:05:12 -070088 } else {
Jack Yu09ef1cb2019-08-18 18:51:30 -070089 Rlog.e(mTag, "onRequestNetworkRegistrationInfoComplete callback is null.");
Jack Yud5f1de12017-12-21 11:00:05 -080090 }
91 }
92}