• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.net.LinkProperties;
24 import android.os.RemoteException;
25 import android.telephony.data.DataService.DataServiceProvider;
26 
27 import com.android.telephony.Rlog;
28 
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 import java.util.List;
32 
33 /**
34  * Data service callback, which is for bound data service to invoke for solicited and unsolicited
35  * response. The caller is responsible to create a callback object for each single asynchronous
36  * request.
37  *
38  * @hide
39  */
40 @SystemApi
41 public class DataServiceCallback {
42 
43     private static final String TAG = DataServiceCallback.class.getSimpleName();
44 
45     private static final boolean DBG = true;
46 
47     /**
48      * Result of data requests
49      * @hide
50      */
51     @Retention(RetentionPolicy.SOURCE)
52     @IntDef({RESULT_SUCCESS, RESULT_ERROR_UNSUPPORTED, RESULT_ERROR_INVALID_ARG, RESULT_ERROR_BUSY,
53             RESULT_ERROR_ILLEGAL_STATE})
54     public @interface ResultCode {}
55 
56     /** Request is completed successfully */
57     public static final int RESULT_SUCCESS              = 0;
58     /** Request is not support */
59     public static final int RESULT_ERROR_UNSUPPORTED    = 1;
60     /** Request contains invalid arguments */
61     public static final int RESULT_ERROR_INVALID_ARG    = 2;
62     /** Service is busy */
63     public static final int RESULT_ERROR_BUSY           = 3;
64     /** Request sent in illegal state */
65     public static final int RESULT_ERROR_ILLEGAL_STATE  = 4;
66     /**
67      * Service is temporarily unavailable. Frameworks should retry the request again.
68      * @hide
69      */
70     public static final int RESULT_ERROR_TEMPORARILY_UNAVAILABLE = 5;
71 
72     private final IDataServiceCallback mCallback;
73 
74     /** @hide */
DataServiceCallback(IDataServiceCallback callback)75     public DataServiceCallback(IDataServiceCallback callback) {
76         mCallback = callback;
77     }
78 
79     /**
80      * Called to indicate result for the request {@link DataServiceProvider#setupDataCall(int,
81      * DataProfile, boolean, boolean, int, LinkProperties, DataServiceCallback)} .
82      *
83      * @param result The result code. Must be one of the {@link ResultCode}.
84      * @param response Setup data call response.
85      */
onSetupDataCallComplete(@esultCode int result, @Nullable DataCallResponse response)86     public void onSetupDataCallComplete(@ResultCode int result,
87             @Nullable DataCallResponse response) {
88         if (mCallback != null) {
89             try {
90                 if (DBG) Rlog.d(TAG, "onSetupDataCallComplete");
91                 mCallback.onSetupDataCallComplete(result, response);
92             } catch (RemoteException e) {
93                 Rlog.e(TAG, "Failed to onSetupDataCallComplete on the remote");
94             }
95         } else {
96             Rlog.e(TAG, "onSetupDataCallComplete: callback is null!");
97         }
98     }
99 
100     /**
101      * Called to indicate result for the request {@link DataServiceProvider#deactivateDataCall(int,
102      * int, DataServiceCallback)}
103      *
104      * @param result The result code. Must be one of the {@link ResultCode}.
105      */
onDeactivateDataCallComplete(@esultCode int result)106     public void onDeactivateDataCallComplete(@ResultCode int result) {
107         if (mCallback != null) {
108             try {
109                 if (DBG) Rlog.d(TAG, "onDeactivateDataCallComplete");
110                 mCallback.onDeactivateDataCallComplete(result);
111             } catch (RemoteException e) {
112                 Rlog.e(TAG, "Failed to onDeactivateDataCallComplete on the remote");
113             }
114         } else {
115             Rlog.e(TAG, "onDeactivateDataCallComplete: callback is null!");
116         }
117     }
118 
119     /**
120      * Called to indicate result for the request {@link DataServiceProvider#setInitialAttachApn(
121      * DataProfile, boolean, DataServiceCallback)}.
122      *
123      * @param result The result code. Must be one of the {@link ResultCode}.
124      */
onSetInitialAttachApnComplete(@esultCode int result)125     public void onSetInitialAttachApnComplete(@ResultCode int result) {
126         if (mCallback != null) {
127             try {
128                 mCallback.onSetInitialAttachApnComplete(result);
129             } catch (RemoteException e) {
130                 Rlog.e(TAG, "Failed to onSetInitialAttachApnComplete on the remote");
131             }
132         } else {
133             Rlog.e(TAG, "onSetInitialAttachApnComplete: callback is null!");
134         }
135     }
136 
137     /**
138      * Called to indicate result for the request {@link DataServiceProvider#setDataProfile(List,
139      * boolean, DataServiceCallback)}.
140      *
141      * @param result The result code. Must be one of the {@link ResultCode}.
142      */
onSetDataProfileComplete(@esultCode int result)143     public void onSetDataProfileComplete(@ResultCode int result) {
144         if (mCallback != null) {
145             try {
146                 mCallback.onSetDataProfileComplete(result);
147             } catch (RemoteException e) {
148                 Rlog.e(TAG, "Failed to onSetDataProfileComplete on the remote");
149             }
150         } else {
151             Rlog.e(TAG, "onSetDataProfileComplete: callback is null!");
152         }
153     }
154 
155     /**
156      * Called to indicate result for the request {@link DataServiceProvider#requestDataCallList(
157      * DataServiceCallback)}.
158      *
159      * @param result The result code. Must be one of the {@link ResultCode}.
160      * @param dataCallList List of the current active data connection. If no data call is presented,
161      * set it to an empty list.
162      */
onRequestDataCallListComplete(@esultCode int result, @NonNull List<DataCallResponse> dataCallList)163     public void onRequestDataCallListComplete(@ResultCode int result,
164             @NonNull List<DataCallResponse> dataCallList) {
165         if (mCallback != null) {
166             try {
167                 mCallback.onRequestDataCallListComplete(result, dataCallList);
168             } catch (RemoteException e) {
169                 Rlog.e(TAG, "Failed to onRequestDataCallListComplete on the remote");
170             }
171         } else {
172             Rlog.e(TAG, "onRequestDataCallListComplete: callback is null!");
173         }
174     }
175 
176     /**
177      * Called to indicate that data connection list changed. If no data call is presented, set it to
178      * an empty list.
179      *
180      * @param dataCallList List of the current active data connection.
181      */
onDataCallListChanged(@onNull List<DataCallResponse> dataCallList)182     public void onDataCallListChanged(@NonNull List<DataCallResponse> dataCallList) {
183         if (mCallback != null) {
184             try {
185                 if (DBG) Rlog.d(TAG, "onDataCallListChanged");
186                 mCallback.onDataCallListChanged(dataCallList);
187             } catch (RemoteException e) {
188                 Rlog.e(TAG, "Failed to onDataCallListChanged on the remote");
189             }
190         } else {
191             Rlog.e(TAG, "onDataCallListChanged: callback is null!");
192         }
193     }
194 
195     /**
196      * Called to indicate result for the request {@link DataService#startHandover}.
197      *
198      * @param result The result code. Must be one of the {@link ResultCode}
199      *
200      * @hide
201      */
onHandoverStarted(@esultCode int result)202     public void onHandoverStarted(@ResultCode int result) {
203         if (mCallback != null) {
204             try {
205                 if (DBG) Rlog.d(TAG, "onHandoverStarted");
206                 mCallback.onHandoverStarted(result);
207             } catch (RemoteException e) {
208                 Rlog.e(TAG, "Failed to onHandoverStarted on the remote");
209             }
210         } else {
211             Rlog.e(TAG, "onHandoverStarted: callback is null!");
212         }
213     }
214 
215     /**
216      * Called to indicate result for the request {@link DataService#cancelHandover}.
217      *
218      * @param result The result code. Must be one of the {@link ResultCode}
219      *
220      * @hide
221      */
onHandoverCancelled(@esultCode int result)222     public void onHandoverCancelled(@ResultCode int result) {
223         if (mCallback != null) {
224             try {
225                 if (DBG) Rlog.d(TAG, "onHandoverCancelled");
226                 mCallback.onHandoverCancelled(result);
227             } catch (RemoteException e) {
228                 Rlog.e(TAG, "Failed to onHandoverCancelled on the remote");
229             }
230         } else {
231             Rlog.e(TAG, "onHandoverCancelled: callback is null!");
232         }
233     }
234 
235     /**
236      * Get the result code as a string
237      *
238      * @param resultCode The result code. Must be one of the {@link ResultCode}
239      * @return the string representation
240      *
241      * @hide
242      */
243     @NonNull
resultCodeToString(@ataServiceCallback.ResultCode int resultCode)244     public static String resultCodeToString(@DataServiceCallback.ResultCode int resultCode) {
245         switch (resultCode) {
246             case RESULT_SUCCESS:
247                 return "RESULT_SUCCESS";
248             case RESULT_ERROR_UNSUPPORTED:
249                 return "RESULT_ERROR_UNSUPPORTED";
250             case RESULT_ERROR_INVALID_ARG:
251                 return "RESULT_ERROR_INVALID_ARG";
252             case RESULT_ERROR_BUSY:
253                 return "RESULT_ERROR_BUSY";
254             case RESULT_ERROR_ILLEGAL_STATE:
255                 return "RESULT_ERROR_ILLEGAL_STATE";
256             default:
257                 return "Missing case for result code=" + resultCode;
258         }
259     }
260 
261     /**
262      * Unthrottles the APN on the current transport.  There is no matching "APN throttle" method.
263      * Instead, the APN is throttled for the time specified in
264      * {@link DataCallResponse#getRetryDurationMillis}.
265      * <p/>
266      * see: {@link DataCallResponse#getRetryDurationMillis}
267      *
268      * @param apn Access Point Name defined by the carrier.
269      */
onApnUnthrottled(final @NonNull String apn)270     public void onApnUnthrottled(final @NonNull String apn) {
271         if (mCallback != null) {
272             try {
273                 if (DBG) Rlog.d(TAG, "onApnUnthrottled");
274                 mCallback.onApnUnthrottled(apn);
275             } catch (RemoteException e) {
276                 Rlog.e(TAG, "onApnUnthrottled: remote exception", e);
277             }
278         } else {
279             Rlog.e(TAG, "onApnUnthrottled: callback is null!");
280         }
281     }
282 }
283