Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 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; |
Jack Yu | 7338e5c | 2019-03-05 11:00:12 -0800 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
| 22 | import android.os.RemoteException; |
| 23 | import android.telephony.NetworkService.NetworkServiceProvider; |
| 24 | |
Meng Wang | 1dbea2f | 2020-01-30 12:25:08 -0800 | [diff] [blame] | 25 | import com.android.telephony.Rlog; |
| 26 | |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 27 | import java.lang.annotation.Retention; |
| 28 | import java.lang.annotation.RetentionPolicy; |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Network service callback. Object of this class is passed to NetworkServiceProvider upon |
Jack Yu | 806b642 | 2019-03-18 00:12:03 -0700 | [diff] [blame] | 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. |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 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 | |
Jack Yu | 09ef1cb | 2019-08-18 18:51:30 -0700 | [diff] [blame] | 65 | private final INetworkServiceCallback mCallback; |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 66 | |
| 67 | /** @hide */ |
| 68 | public NetworkServiceCallback(INetworkServiceCallback callback) { |
Jack Yu | 09ef1cb | 2019-08-18 18:51:30 -0700 | [diff] [blame] | 69 | mCallback = callback; |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Called to indicate result of |
Jack Yu | 806b642 | 2019-03-18 00:12:03 -0700 | [diff] [blame] | 74 | * {@link NetworkServiceProvider#requestNetworkRegistrationInfo(int, NetworkServiceCallback)} |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 75 | * |
| 76 | * @param result Result status like {@link NetworkServiceCallback#RESULT_SUCCESS} or |
Jack Yu | 806b642 | 2019-03-18 00:12:03 -0700 | [diff] [blame] | 77 | * {@link NetworkServiceCallback#RESULT_ERROR_UNSUPPORTED} |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 78 | * @param state The state information to be returned to callback. |
| 79 | */ |
Jack Yu | 806b642 | 2019-03-18 00:12:03 -0700 | [diff] [blame] | 80 | public void onRequestNetworkRegistrationInfoComplete(int result, |
| 81 | @Nullable NetworkRegistrationInfo state) { |
Jack Yu | 09ef1cb | 2019-08-18 18:51:30 -0700 | [diff] [blame] | 82 | if (mCallback != null) { |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 83 | try { |
Jack Yu | 09ef1cb | 2019-08-18 18:51:30 -0700 | [diff] [blame] | 84 | mCallback.onRequestNetworkRegistrationInfoComplete(result, state); |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 85 | } catch (RemoteException e) { |
Jack Yu | 806b642 | 2019-03-18 00:12:03 -0700 | [diff] [blame] | 86 | Rlog.e(mTag, "Failed to onRequestNetworkRegistrationInfoComplete on the remote"); |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 87 | } |
Malcolm Chen | 4514425 | 2018-03-29 19:05:12 -0700 | [diff] [blame] | 88 | } else { |
Jack Yu | 09ef1cb | 2019-08-18 18:51:30 -0700 | [diff] [blame] | 89 | Rlog.e(mTag, "onRequestNetworkRegistrationInfoComplete callback is null."); |
Jack Yu | d5f1de1 | 2017-12-21 11:00:05 -0800 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | } |