2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Threading.Tasks;
19 using System.Runtime.InteropServices;
20 using System.Collections.Generic;
25 /// A class which manages Supplementary Services of the SIM.
29 private IntPtr _handle = IntPtr.Zero;
30 private Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback> _callbackMap = new Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback>();
31 private int _requestId = 0;
37 /// A constructor to instantiate Ss class using the Tapi handle.
39 /// <param name="handle">An instance of TapiHandle obtained from InitTapi in TapiManager API.</param>
40 /// <exception cref="ArgumentNullException">Thrown when handle is passed as null.</exception>
41 public Ss(TapiHandle handle)
45 throw new ArgumentNullException("Handle is null");
48 _handle = handle._handle;
52 /// Sends a request to activate/deactivate call barring.
54 /// <param name="info">The information about call barring.</param>
55 /// <returns>A task containing an instance of SsBarringResponse which contains information about barring response.</returns>
56 /// <feature>http://tizen.org/feature/network.telephony</feature>
57 /// <privlevel>platform</privlevel>
58 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
59 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
60 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
61 /// <exception cref="ArgumentNullException">Thrown when barring info is passed as null.</exception>
62 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
63 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
64 public Task<SsBarringResponse> SsSetBarring(SsBarringInfo info)
66 TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
67 IntPtr id = (IntPtr)_requestId++;
68 _callbackMap[id] = (handle, result, data, key) =>
70 Task taskResult = new Task(() =>
72 if (result != (int)SsCause.Success)
74 Log.Error(TapiUtility.LogTag, "Error occurs during setting SS barring info: " + (SsCause)result);
75 task.SetException(new InvalidOperationException("Error occurs during setting SS barring info, " + (SsCause)result));
79 SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
80 task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
84 _callbackMap.Remove(key);
89 throw new ArgumentNullException("Ss barring info is null");
92 SsBarringInfoStruct infoStruct = SsClassConversions.ConvertSsBarringInfo(info);
93 int ret = Interop.Tapi.Ss.SsSetBarring(_handle, ref infoStruct, _callbackMap[id], id);
94 if (ret != (int)TapiError.Success)
96 Log.Error(TapiUtility.LogTag, "Failed to set barring info, Error: " + (TapiError)ret);
97 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
104 /// Gets call barring status.
106 /// <param name="ssClass">The type of call.</param>
107 /// <param name="type">The barring type.</param>
108 /// <returns>A task containing information about barring response.</returns>
109 /// <feature>http://tizen.org/feature/network.telephony</feature>
110 /// <privilege>http://tizen.org/privilege/telephony</privilege>
111 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
112 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
113 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
114 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
115 public Task<SsBarringResponse> SsGetBarringStatus(SsClass ssClass, SsBarringType type)
117 TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
118 IntPtr id = (IntPtr)_requestId++;
119 _callbackMap[id] = (handle, result, data, key) =>
121 Task taskResult = new Task(() =>
123 if (result != (int)SsCause.Success)
125 Log.Error(TapiUtility.LogTag, "Error occurs in getting barring status: " + (SsCause)result);
126 task.SetException(new InvalidOperationException("Error occurs in getting barring status, " + (SsCause)result));
130 SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
131 task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
135 _callbackMap.Remove(key);
138 int ret = Interop.Tapi.Ss.SsGetBarringStatus(_handle, ssClass, type, _callbackMap[id], id);
139 if (ret != (int)TapiError.Success)
141 Log.Error(TapiUtility.LogTag, "Failed to get barring status, Error: " + (TapiError)ret);
142 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
149 /// Allows changing of the barring password in the network.
151 /// <param name="oldPassword">The old password set for Barring in the Network.</param>
152 /// <param name="newPassword">The new password set for Barring in the Network.</param>
153 /// <param name="newPasswordAgain">The new password again.</param>
154 /// <returns>A task indicating whether the change of password is done or not.</returns>
155 /// <feature>http://tizen.org/feature/network.telephony</feature>
156 /// <privlevel>platform</privlevel>
157 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
158 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
159 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
160 /// <exception cref="ArgumentNullException">Thrown when any of the parameter is passed as null.</exception>
161 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
162 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
163 public Task<bool> SsChangeBarringPassword(string oldPassword, string newPassword, string newPasswordAgain)
165 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
166 IntPtr id = (IntPtr)_requestId++;
167 _callbackMap[id] = (handle, result, data, key) =>
169 Task taskResult = new Task(() =>
171 if (result != (int)SsCause.Success)
173 Log.Error(TapiUtility.LogTag, "Error occurs in changing barring password: " + (SsCause)result);
174 task.SetException(new InvalidOperationException("Error occurs in changing barring password, " + (SsCause)result));
178 task.SetResult(true);
182 _callbackMap.Remove(key);
185 if (oldPassword == null || newPassword == null || newPasswordAgain == null)
187 throw new ArgumentNullException("Old password/new password is null");
190 int ret = Interop.Tapi.Ss.SsChangeBarringPassword(_handle, oldPassword, newPassword, newPasswordAgain, _callbackMap[id], id);
191 if (ret != (int)TapiError.Success)
193 Log.Error(TapiUtility.LogTag, "Failed to change barring password, Error: " + (TapiError)ret);
194 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
201 /// Allows to set the (register/erase/activate/deactivate) call forwarding option at the network.
203 /// <param name="info">The Call forward information such as a forward mode, a forward type, and so on.</param>
204 /// <returns>A task containing information about SS forward response.</returns>
205 /// <feature>http://tizen.org/feature/network.telephony</feature>
206 /// <privlevel>platform</privlevel>
207 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
208 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
209 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
210 /// <exception cref="ArgumentNullException">Thrown when forward info is passed as null.</exception>
211 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
212 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
213 public Task<SsForwardResponse> SsSetForwardInfo(SsForwardInfo info)
215 TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
216 IntPtr id = (IntPtr)_requestId++;
217 _callbackMap[id] = (handle, result, data, key) =>
219 Task taskResult = new Task(() =>
221 if (result != (int)SsCause.Success)
223 Log.Error(TapiUtility.LogTag, "Error occurs in setting SS forward info: " + (SsCause)result);
224 task.SetException(new InvalidOperationException("Error occurs in setting SS forward info, " + (SsCause)result));
228 SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
229 task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
233 _callbackMap.Remove(key);
238 throw new ArgumentNullException("Ss forward info is null");
241 SsForwardInfoStruct infoStruct = SsClassConversions.ConvertSsForwardInfo(info);
242 int ret = Interop.Tapi.Ss.SsSetForward(_handle, ref infoStruct, _callbackMap[id], id);
243 if (ret != (int)TapiError.Success)
245 Log.Error(TapiUtility.LogTag, "Failed to set forward info, Error: " + (TapiError)ret);
246 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
253 /// Provides an option to get the call forwarding status of different calls from the Network.
255 /// <param name="ssClass">The Forward call type.</param>
256 /// <param name="condition">The forward condition.</param>
257 /// <returns>A task containing SS forward response information.</returns>
258 /// <feature>http://tizen.org/feature/network.telephony</feature>
259 /// <privilege>http://tizen.org/privilege/telephony</privilege>
260 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
261 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
262 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
263 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
264 public Task<SsForwardResponse> SsGetForwardStatus(SsClass ssClass, SsForwardCondition condition)
266 TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
267 IntPtr id = (IntPtr)_requestId++;
268 _callbackMap[id] = (handle, result, data, key) =>
270 Task taskResult = new Task(() =>
272 if (result != (int)SsCause.Success)
274 Log.Error(TapiUtility.LogTag, "Error occurs in getting SS forward status: " + (SsCause)result);
275 task.SetException(new InvalidOperationException("Error occurs in getting SS forward status, " + (SsCause)result));
279 SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
280 task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
284 _callbackMap.Remove(key);
287 int ret = Interop.Tapi.Ss.SsGetForwardStatus(_handle, ssClass, condition, _callbackMap[id], id);
288 if (ret != (int)TapiError.Success)
290 Log.Error(TapiUtility.LogTag, "Failed to get forward status, Error: " + (TapiError)ret);
291 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
298 /// Activates/deactivates the call waiting service.
300 /// <param name="info">The status of call-waiting service.</param>
301 /// <returns>A task containing SS waiting response information.</returns>
302 /// <feature>http://tizen.org/feature/network.telephony</feature>
303 /// <privlevel>platform</privlevel>
304 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
305 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
306 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
307 /// <exception cref="ArgumentNullException">Thrown when waiting info is passed as null.</exception>
308 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
309 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
310 public Task<SsWaitingResponse> SsSetWaitingInfo(SsWaitingInfo info)
312 TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
313 IntPtr id = (IntPtr)_requestId++;
314 _callbackMap[id] = (handle, result, data, key) =>
316 Task taskResult = new Task(() =>
318 if (result != (int)SsCause.Success)
320 Log.Error(TapiUtility.LogTag, "Error occurs in setting SS waiting info: " + (SsCause)result);
321 task.SetException(new InvalidOperationException("Error occurs in setting SS waiting info, " + (SsCause)result));
325 SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
326 task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
330 _callbackMap.Remove(key);
335 throw new ArgumentNullException("Ss waiting info is null");
338 SsWaitingInfoStruct infoStruct = SsClassConversions.ConvertSsWaitingInfo(info);
339 int ret = Interop.Tapi.Ss.SsSetWaiting(_handle, ref infoStruct, _callbackMap[id], id);
340 if (ret != (int)TapiError.Success)
342 Log.Error(TapiUtility.LogTag, "Failed to set waiting info, Error: " + (TapiError)ret);
343 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
350 /// Gets the status of the call waiting service.
352 /// <param name="ssClass">The call types.</param>
353 /// <returns>A task containing information about SS waiting response.</returns>
354 /// <feature>http://tizen.org/feature/network.telephony</feature>
355 /// <privilege>http://tizen.org/privilege/telephony</privilege>
356 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
357 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
358 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
359 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
360 public Task<SsWaitingResponse> SsGetWaitingInfo(SsClass ssClass)
362 TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
363 IntPtr id = (IntPtr)_requestId++;
364 _callbackMap[id] = (handle, result, data, key) =>
366 Task taskResult = new Task(() =>
368 if (result != (int)SsCause.Success)
370 Log.Error(TapiUtility.LogTag, "Error occurs in getting SS waiting info: " + (SsCause)result);
371 task.SetException(new InvalidOperationException("Error occurs in getting SS waiting info, " + (SsCause)result));
375 SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
376 task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
380 _callbackMap.Remove(key);
383 int ret = Interop.Tapi.Ss.SsGetWaitingStatus(_handle, ssClass, _callbackMap[id], id);
384 if (ret != (int)TapiError.Success)
386 Log.Error(TapiUtility.LogTag, "Failed to get waiting info, Error: " + (TapiError)ret);
387 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
394 /// Activates/deactivates the status of the calling line identity service.
396 /// <param name="type">The Cli service type.</param>
397 /// <param name="status">The Cli Status.</param>
398 /// <returns>A task indicating whether setting of CLI status is done or not.</returns>
399 /// <feature>http://tizen.org/feature/network.telephony</feature>
400 /// <privlevel>platform</privlevel>
401 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
402 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
403 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
404 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
405 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
406 public Task<bool> SsSetCliStatus(SsCliType type, SsCliStatus status)
408 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
409 IntPtr id = (IntPtr)_requestId++;
410 _callbackMap[id] = (handle, result, data, key) =>
412 Task taskResult = new Task(() =>
414 if (result != (int)SsCause.Success)
416 Log.Error(TapiUtility.LogTag, "Error occurs in setting SS CLI status: " + (SsCause)result);
417 task.SetException(new InvalidOperationException("Error occurs in setting SS CLI status, " + (SsCause)result));
421 task.SetResult(true);
425 _callbackMap.Remove(key);
428 int ret = Interop.Tapi.Ss.SsSetCliStatus(_handle, type, status, _callbackMap[id], id);
429 if (ret != (int)TapiError.Success)
431 Log.Error(TapiUtility.LogTag, "Failed to set SS CLI status, Error: " + (TapiError)ret);
432 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
439 /// Gets the status of the calling line identity service.
441 /// <param name="type">The Cli service type.</param>
442 /// <returns>A task containing SS CLI response information.</returns>
443 /// <feature>http://tizen.org/feature/network.telephony</feature>
444 /// <privilege>http://tizen.org/privilege/telephony</privilege>
445 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
446 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
447 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
448 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
449 public Task<SsCliResponse> SsGetCliStatus(SsCliType type)
451 TaskCompletionSource<SsCliResponse> task = new TaskCompletionSource<SsCliResponse>();
452 IntPtr id = (IntPtr)_requestId++;
453 _callbackMap[id] = (handle, result, data, key) =>
455 Task taskResult = new Task(() =>
457 if (result != (int)SsCause.Success)
459 Log.Error(TapiUtility.LogTag, "Error occurs in getting SS CLI status: " + (SsCause)result);
460 task.SetException(new InvalidOperationException("Error occurs in getting SS CLI status, " + (SsCause)result));
464 SsCliResponseStruct response = Marshal.PtrToStructure<SsCliResponseStruct>(data);
465 task.SetResult(SsStructConversions.ConvertSsCliResponseStruct(response));
469 _callbackMap.Remove(key);
472 int ret = Interop.Tapi.Ss.SsGetCliStatus(_handle, type, _callbackMap[id], id);
473 if (ret != (int)TapiError.Success)
475 Log.Error(TapiUtility.LogTag, "Failed to get CLI status, Error: " + (TapiError)ret);
476 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
483 /// Sends a USSD string or User response to the Network.
485 /// <param name="info">The data coding scheme used</param>
486 /// <returns>A task containing SS USSD response information.</returns>
487 /// <feature>http://tizen.org/feature/network.telephony</feature>
488 /// <privlevel>platform</privlevel>
489 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
490 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
491 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
492 /// <exception cref="ArgumentNullException">Thrown when Ussd message info is passed as null.</exception>
493 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
494 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
495 public Task<SsUssdResponse> SsSendUssdRequest(SsUssdMsgInfo info)
497 TaskCompletionSource<SsUssdResponse> task = new TaskCompletionSource<SsUssdResponse>();
498 IntPtr id = (IntPtr)_requestId++;
499 _callbackMap[id] = (handle, result, data, key) =>
501 Task taskResult = new Task(() =>
503 if (result != (int)SsCause.Success)
505 Log.Error(TapiUtility.LogTag, "Error occurs in sending USSD request: " + (SsCause)result);
506 task.SetException(new InvalidOperationException("Error occurs in sending USSD request, " + (SsCause)result));
510 SsUssdResponseStruct response = Marshal.PtrToStructure<SsUssdResponseStruct>(data);
511 task.SetResult(SsStructConversions.ConvertSsUssdResponseStruct(response));
515 _callbackMap.Remove(key);
520 throw new ArgumentNullException("Ussd message info is null");
523 SsUssdMsgInfoStruct msgStruct = SsClassConversions.ConvertSsUssdMsgInfo(info);
524 int ret = Interop.Tapi.Ss.SsSendUssdRequest(_handle, ref msgStruct, _callbackMap[id], id);
525 if (ret != (int)TapiError.Success)
527 Log.Error(TapiUtility.LogTag, "Failed to send USSD request, Error: " + (TapiError)ret);
528 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");