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.data; 18 19 import android.annotation.IntDef; 20 import android.net.LinkProperties; 21 import android.os.RemoteException; 22 import android.telephony.Rlog; 23 import android.telephony.data.DataService.DataServiceProvider; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.lang.ref.WeakReference; 28 import java.util.List; 29 30 /** 31 * Data service callback, which is for bound data service to invoke for solicited and unsolicited 32 * response. The caller is responsible to create a callback object for each single asynchronous 33 * request. 34 * 35 * @hide 36 */ 37 public class DataServiceCallback { 38 39 private static final String TAG = DataServiceCallback.class.getSimpleName(); 40 41 /** 42 * Result of data requests 43 * @hide 44 */ 45 @Retention(RetentionPolicy.SOURCE) 46 @IntDef({RESULT_SUCCESS, RESULT_ERROR_UNSUPPORTED, RESULT_ERROR_INVALID_ARG, RESULT_ERROR_BUSY, 47 RESULT_ERROR_ILLEGAL_STATE}) 48 public @interface ResultCode {} 49 50 /** Request is completed successfully */ 51 public static final int RESULT_SUCCESS = 0; 52 /** Request is not support */ 53 public static final int RESULT_ERROR_UNSUPPORTED = 1; 54 /** Request contains invalid arguments */ 55 public static final int RESULT_ERROR_INVALID_ARG = 2; 56 /** Service is busy */ 57 public static final int RESULT_ERROR_BUSY = 3; 58 /** Request sent in illegal state */ 59 public static final int RESULT_ERROR_ILLEGAL_STATE = 4; 60 61 private final WeakReference<IDataServiceCallback> mCallback; 62 63 /** @hide */ DataServiceCallback(IDataServiceCallback callback)64 public DataServiceCallback(IDataServiceCallback callback) { 65 mCallback = new WeakReference<>(callback); 66 } 67 68 /** 69 * Called to indicate result for the request {@link DataServiceProvider#setupDataCall(int, 70 * DataProfile, boolean, boolean, int, LinkProperties, DataServiceCallback)} . 71 * 72 * @param result The result code. Must be one of the {@link ResultCode}. 73 * @param response Setup data call response. 74 */ onSetupDataCallComplete(@esultCode int result, DataCallResponse response)75 public void onSetupDataCallComplete(@ResultCode int result, DataCallResponse response) { 76 IDataServiceCallback callback = mCallback.get(); 77 if (callback != null) { 78 try { 79 callback.onSetupDataCallComplete(result, response); 80 } catch (RemoteException e) { 81 Rlog.e(TAG, "Failed to onSetupDataCallComplete on the remote"); 82 } 83 } 84 } 85 86 /** 87 * Called to indicate result for the request {@link DataServiceProvider#deactivateDataCall(int, 88 * int, DataServiceCallback)} 89 * 90 * @param result The result code. Must be one of the {@link ResultCode}. 91 */ onDeactivateDataCallComplete(@esultCode int result)92 public void onDeactivateDataCallComplete(@ResultCode int result) { 93 IDataServiceCallback callback = mCallback.get(); 94 if (callback != null) { 95 try { 96 callback.onDeactivateDataCallComplete(result); 97 } catch (RemoteException e) { 98 Rlog.e(TAG, "Failed to onDeactivateDataCallComplete on the remote"); 99 } 100 } 101 } 102 103 /** 104 * Called to indicate result for the request {@link DataServiceProvider#setInitialAttachApn( 105 * DataProfile, boolean, DataServiceCallback)}. 106 * 107 * @param result The result code. Must be one of the {@link ResultCode}. 108 */ onSetInitialAttachApnComplete(@esultCode int result)109 public void onSetInitialAttachApnComplete(@ResultCode int result) { 110 IDataServiceCallback callback = mCallback.get(); 111 if (callback != null) { 112 try { 113 callback.onSetInitialAttachApnComplete(result); 114 } catch (RemoteException e) { 115 Rlog.e(TAG, "Failed to onSetInitialAttachApnComplete on the remote"); 116 } 117 } 118 } 119 120 /** 121 * Called to indicate result for the request {@link DataServiceProvider#setDataProfile(List, 122 * boolean, DataServiceCallback)}. 123 * 124 * @param result The result code. Must be one of the {@link ResultCode}. 125 */ onSetDataProfileComplete(@esultCode int result)126 public void onSetDataProfileComplete(@ResultCode int result) { 127 IDataServiceCallback callback = mCallback.get(); 128 if (callback != null) { 129 try { 130 callback.onSetDataProfileComplete(result); 131 } catch (RemoteException e) { 132 Rlog.e(TAG, "Failed to onSetDataProfileComplete on the remote"); 133 } 134 } 135 } 136 137 /** 138 * Called to indicate result for the request {@link DataServiceProvider#getDataCallList( 139 * DataServiceCallback)}. 140 * 141 * @param result The result code. Must be one of the {@link ResultCode}. 142 * @param dataCallList List of the current active data connection. 143 */ onGetDataCallListComplete(@esultCode int result, List<DataCallResponse> dataCallList)144 public void onGetDataCallListComplete(@ResultCode int result, 145 List<DataCallResponse> dataCallList) { 146 IDataServiceCallback callback = mCallback.get(); 147 if (callback != null) { 148 try { 149 callback.onGetDataCallListComplete(result, dataCallList); 150 } catch (RemoteException e) { 151 Rlog.e(TAG, "Failed to onGetDataCallListComplete on the remote"); 152 } 153 } 154 } 155 156 /** 157 * Called to indicate that data connection list changed. 158 * 159 * @param dataCallList List of the current active data connection. 160 */ onDataCallListChanged(List<DataCallResponse> dataCallList)161 public void onDataCallListChanged(List<DataCallResponse> dataCallList) { 162 IDataServiceCallback callback = mCallback.get(); 163 if (callback != null) { 164 try { 165 callback.onDataCallListChanged(dataCallList); 166 } catch (RemoteException e) { 167 Rlog.e(TAG, "Failed to onDataCallListChanged on the remote"); 168 } 169 } 170 } 171 } 172