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.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Threading.Tasks;
25 /// This class provides functions for managing telephony service network.
29 private IntPtr _handle;
30 private Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback> _response_map = new Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback>();
31 private int _requestId = 0;
34 /// A public constructor for Network class to create a Network instance for the given tapi handle.
36 /// <param name="handle">The tapi handle.</param>
37 public Network(TapiHandle handle)
41 throw new ArgumentNullException("TapiHandle parameter is null");
44 _handle = handle._handle;
48 /// Request the lower layers to select the network automatically asynchronously.
50 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
51 /// <privlevel>platform</privlevel>
52 /// <feature>http://tizen.org/feature/network.telephony</feature>
53 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
54 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
55 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
56 public Task SelectNetworkAutomatic()
58 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
60 id = (IntPtr)_requestId++;
61 _response_map[id] = (IntPtr handle, int result, IntPtr data, IntPtr key) =>
63 Task resultTask = new Task(() =>
65 if (result != (int)TapiError.Success)
67 Log.Error(TapiUtility.LogTag, "Error occurs during selecting the network, " + (TapiError)result);
68 task.SetException(new InvalidOperationException("Error occurs during selecting the network, " + (TapiError)result));
77 _response_map.Remove(key);
80 int ret = Interop.Tapi.Network.SelectAutoNetwork(_handle, _response_map[id], id);
81 if (ret != (int)TapiError.Success)
83 Log.Error(TapiUtility.LogTag, "Failed to select the network automatically, Error: " + (TapiError)ret);
84 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
91 /// Request the lower layers to select the network which is selected by the user from the network list asynchronously.
93 /// <param name="plmn">The user selected plmn.</param>
94 /// <param name="act">The user selected access technology.</param>
95 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
96 /// <privlevel>platform</privlevel>
97 /// <feature>http://tizen.org/feature/network.telephony</feature>
98 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
99 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
100 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
101 public Task SelectNetworkManual(string plmn, int act)
103 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
105 id = (IntPtr)_requestId++;
106 _response_map[id] = (IntPtr handle, int result, IntPtr data, IntPtr key) =>
108 Task resultTask = new Task(() =>
110 if (result != (int)TapiError.Success)
112 Log.Error(TapiUtility.LogTag, "Error occurs during selecting the network, " + (TapiError)result);
113 task.SetException(new InvalidOperationException("Error occurs during selecting the network, " + (TapiError)result));
117 task.SetResult(true);
122 _response_map.Remove(key);
125 int ret = Interop.Tapi.Network.SelectManualNetwork(_handle, plmn, act, _response_map[id], id);
126 if (ret != (int)TapiError.Success)
128 Log.Error(TapiUtility.LogTag, "Failed to select the network manually, Error: " + (TapiError)ret);
129 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
136 /// Sends a request to do manual search for the available networks and provides the Network List to the user asynchronously.
138 /// <returns>Instance of NetworkPlmnList.</returns>
139 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
140 /// <privlevel>platform</privlevel>
141 /// <feature>http://tizen.org/feature/network.telephony</feature>
142 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
143 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
144 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
145 public Task<NetworkPlmnList> SearchNetwork()
147 TaskCompletionSource<NetworkPlmnList> task = new TaskCompletionSource<NetworkPlmnList>();
149 id = (IntPtr)_requestId++;
150 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
152 Task resultTask = new Task(() =>
154 if (result != (int)TapiError.Success)
156 Log.Error(TapiUtility.LogTag, "Error occurs during manual search for the available networks, " + (TapiError)result);
157 task.SetException(new InvalidOperationException("Error occurs during manual search for the available networks, " + (TapiError)result));
161 NetworkPlmnListStruct listStruct = Marshal.PtrToStructure<NetworkPlmnListStruct>(dataResponse);
162 NetworkPlmnList plmnClass = NetworkStructConversions.ConvertNetworkPlmnListStruct(listStruct);
163 task.SetResult(plmnClass);
168 _response_map.Remove(key);
171 int ret = Interop.Tapi.Network.SearchNetwork(_handle, _response_map[id], id);
172 if (ret != (int)TapiError.Success)
174 Log.Error(TapiUtility.LogTag, "Failed to do manual search for the available networks, Error: " + (TapiError)ret);
175 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
182 /// Get the present network selection mode i.e. automatic or manual asynchronously.
184 /// <returns>Value of NetworkSelectionMode.</returns>
185 /// <privilege>http://tizen.org/privilege/telephony</privilege>
186 /// <feature>http://tizen.org/feature/network.telephony</feature>
187 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
188 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
189 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
190 public Task<NetworkSelectionMode> GetNetworkSelectionMode()
192 TaskCompletionSource<NetworkSelectionMode> task = new TaskCompletionSource<NetworkSelectionMode>();
194 id = (IntPtr)_requestId++;
195 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
197 Task resultTask = new Task(() =>
199 if (result != (int)TapiError.Success)
201 Log.Error(TapiUtility.LogTag, "Error occurs during getting the present network selection mode, " + (TapiError)result);
202 task.SetException(new InvalidOperationException("Error occurs during getting the present network selection mode, " + (TapiError)result));
206 task.SetResult((NetworkSelectionMode)Marshal.ReadInt32(dataResponse));
211 _response_map.Remove(key);
214 int ret = Interop.Tapi.Network.GetNetworkSelectMode(_handle, _response_map[id], id);
215 if (ret != (int)TapiError.Success)
217 Log.Error(TapiUtility.LogTag, "Failed to get the present network selection mode, Error: " + (TapiError)ret);
218 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
225 /// Set the network preferred plmn asynchronously.
227 /// <param name="operation">The operation to be done on the preferred plmn.</param>
228 /// <param name="info">The preferred plmn info.</param>
229 /// <returns>A task indicating whether the SetNetworkPreferredPlmn method is done or not.</returns>
230 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
231 /// <privlevel>platform</privlevel>
232 /// <feature>http://tizen.org/feature/network.telephony</feature>
233 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
234 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
235 /// <exception cref="System.ArgumentNullException">Thrown when NetworkPreferredPlmnInfo argument is null.</exception>
236 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
237 public Task SetNetworkPreferredPlmn(NetworkPreferredPlmnOp operation, NetworkPreferredPlmnInfo info)
241 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
243 id = (IntPtr)_requestId++;
244 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
246 Task resultTask = new Task(() =>
248 if (result != (int)TapiError.Success)
250 Log.Error(TapiUtility.LogTag, "Error occurs during setting the network preferred plmn, " + (TapiError)result);
251 task.SetException(new InvalidOperationException("Error occurs during setting the network preferred plmn, " + (TapiError)result));
255 task.SetResult(true);
260 _response_map.Remove(key);
263 NetworkPreferredPlmnStruct plmnStruct = NetworkClassConversions.ConvertNetworkPreferredPlmn(info);
264 int ret = Interop.Tapi.Network.SetNetworkPreferredPlmn(_handle, operation, ref plmnStruct, _response_map[id], id);
265 if (ret != (int)TapiError.Success)
267 Log.Error(TapiUtility.LogTag, "Failed to set the network preferred plmn, Error: " + (TapiError)ret);
268 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
276 throw new ArgumentNullException("NetworkPreferredPlmnInfo argument is null");
281 /// Get the preferred plmn list asynchronously.
283 /// <returns>List of NetworkPreferredPlmnInfo.</returns>
284 /// <privilege>http://tizen.org/privilege/telephony</privilege>
285 /// <feature>http://tizen.org/feature/network.telephony</feature>
286 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
287 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
288 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
289 public Task<IEnumerable<NetworkPreferredPlmnInfo>> GetNetworkPreferredPlmn()
291 TaskCompletionSource<IEnumerable<NetworkPreferredPlmnInfo>> task = new TaskCompletionSource<IEnumerable<NetworkPreferredPlmnInfo>>();
293 id = (IntPtr)_requestId++;
294 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
296 Task resultTask = new Task(() =>
298 if (result != (int)TapiError.Success)
300 Log.Error(TapiUtility.LogTag, "Error occurs during getting the preferred plmn list, " + (TapiError)result);
301 task.SetException(new InvalidOperationException("Error occurs during getting the preferred plmn list, " + (TapiError)result));
305 NetworkPreferredPlmnListStruct plmnStruct = Marshal.PtrToStructure<NetworkPreferredPlmnListStruct>(dataResponse);
306 IEnumerable<NetworkPreferredPlmnInfo> plmnInfo = NetworkStructConversions.ConvertNetworkPreferredPlmnStruct(plmnStruct);
307 task.SetResult(plmnInfo);
312 _response_map.Remove(key);
315 int ret = Interop.Tapi.Network.GetNetworkPreferredPlmn(_handle, _response_map[id], id);
316 if (ret != (int)TapiError.Success)
318 Log.Error(TapiUtility.LogTag, "Failed to get the preferred plmn list, Error: " + (TapiError)ret);
319 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
326 /// Cancel the triggered manual network search asynchronously.
328 /// <returns>A task indicating whether the CancelNetworkManualSearch method is done or not.</returns>
329 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
330 /// <privlevel>platform</privlevel>
331 /// <feature>http://tizen.org/feature/network.telephony</feature>
332 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
333 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
334 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
335 public Task CancelNetworkManualSearch()
337 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
339 id = (IntPtr)_requestId++;
340 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
342 Task resultTask = new Task(() =>
344 if (result != (int)TapiError.Success)
346 Log.Error(TapiUtility.LogTag, "Error occurs during cancelling the network manual search, " + (TapiError)result);
347 task.SetException(new InvalidOperationException("Error occurs during cancelling the network manual search, " + (TapiError)result));
351 task.SetResult(true);
356 _response_map.Remove(key);
359 int ret = Interop.Tapi.Network.CancelNetworkManualSearch(_handle, _response_map[id], id);
360 if (ret != (int)TapiError.Success)
362 Log.Error(TapiUtility.LogTag, "Failed to cancel the network manual search, Error: " + (TapiError)ret);
363 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
370 /// Get the network serving information asynchronously.
372 /// <returns>Instance of NetworkServing.</returns>
373 /// <privilege>http://tizen.org/privilege/telephony</privilege>
374 /// <feature>http://tizen.org/feature/network.telephony</feature>
375 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
376 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
377 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
378 public Task<NetworkServing> GetNetworkServing()
380 TaskCompletionSource<NetworkServing> task = new TaskCompletionSource<NetworkServing>();
382 id = (IntPtr)_requestId++;
383 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
385 Task resultTask = new Task(() =>
387 if (result != (int)TapiError.Success)
389 Log.Error(TapiUtility.LogTag, "Error occurs during getting the network serving information, " + (TapiError)result);
390 task.SetException(new InvalidOperationException("Error occurs during getting the network serving information, " + (TapiError)result));
394 NetworkServingStruct servStruct = Marshal.PtrToStructure<NetworkServingStruct>(dataResponse);
395 NetworkServing servingInfo = NetworkStructConversions.ConvertNetworkServingStruct(servStruct);
396 task.SetResult(servingInfo);
401 _response_map.Remove(key);
404 int ret = Interop.Tapi.Network.GetNetworkServing(_handle, _response_map[id], id);
405 if (ret != (int)TapiError.Success)
407 Log.Error(TapiUtility.LogTag, "Failed to get the network serving information, Error: " + (TapiError)ret);
408 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
415 /// Set the network mode asynchronously.
417 /// <param name="mode">The network mode.</param>
418 /// <returns>A task indicating whether the SetNetworkMode method is done or not.</returns>
419 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
420 /// <privlevel>platform</privlevel>
421 /// <feature>http://tizen.org/feature/network.telephony</feature>
422 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
423 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
424 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
425 public Task SetNetworkMode(NetworkMode mode)
427 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
429 id = (IntPtr)_requestId++;
430 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
432 Task resultTask = new Task(() =>
434 if (result != (int)TapiError.Success)
436 Log.Error(TapiUtility.LogTag, "Error occurs during getting the network mode, " + (TapiError)result);
437 task.SetException(new InvalidOperationException("Error occurs during getting the network mode, " + (TapiError)result));
441 task.SetResult(true);
446 _response_map.Remove(key);
449 int ret = Interop.Tapi.Network.SetNetworkMode(_handle, (int)mode, _response_map[id], id);
450 if (ret != (int)TapiError.Success)
452 Log.Error(TapiUtility.LogTag, "Failed to get the network mode, Error: " + (TapiError)ret);
453 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
460 /// Get the network mode asynchronously.
462 /// <returns>Value of NetworkMode.</returns>
463 /// <privilege>http://tizen.org/privilege/telephony</privilege>
464 /// <feature>http://tizen.org/feature/network.telephony</feature>
465 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
466 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
467 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
468 public Task<NetworkMode> GetNetworkMode()
470 TaskCompletionSource<NetworkMode> task = new TaskCompletionSource<NetworkMode>();
472 id = (IntPtr)_requestId++;
473 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
475 Task resultTask = new Task(() =>
477 if (result != (int)TapiError.Success)
479 Log.Error(TapiUtility.LogTag, "Error occurs during getting the network mode, " + (TapiError)result);
480 task.SetException(new InvalidOperationException("Error occurs during getting the network mode, " + (TapiError)result));
484 task.SetResult((NetworkMode)Marshal.ReadInt32(dataResponse));
489 _response_map.Remove(key);
492 int ret = Interop.Tapi.Network.GetNetworkMode(_handle, _response_map[id], id);
493 if (ret != (int)TapiError.Success)
495 Log.Error(TapiUtility.LogTag, "Failed to get the network mode, Error: " + (TapiError)ret);
496 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
503 /// Get the neighboring cell info asynchronously.
505 /// <returns>Instance of NetworkNeighboringCell.</returns>
506 /// <privilege>http://tizen.org/privilege/telephony</privilege>
507 /// <feature>http://tizen.org/feature/network.telephony</feature>
508 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
509 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
510 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
511 public Task<NetworkNeighboringCell> GetNeighborCellNetwork()
513 TaskCompletionSource<NetworkNeighboringCell> task = new TaskCompletionSource<NetworkNeighboringCell>();
515 id = (IntPtr)_requestId++;
516 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
518 Task resultTask = new Task(() =>
520 if (result != (int)TapiError.Success)
522 Log.Error(TapiUtility.LogTag, "Error occurs during getting the neigboring cell info, " + (TapiError)result);
523 task.SetException(new InvalidOperationException("Error occurs during getting the neigboring cell info, " + (TapiError)result));
527 NetworkNeighboringCellStruct cellStruct = Marshal.PtrToStructure<NetworkNeighboringCellStruct>(dataResponse);
528 NetworkNeighboringCell cell = NetworkStructConversions.ConvertNeighborCellStruct(cellStruct);
529 task.SetResult(cell);
534 _response_map.Remove(key);
537 int ret = Interop.Tapi.Network.GetNetworkNeighborCell(_handle, _response_map[id], id);
538 if (ret != (int)TapiError.Success)
540 Log.Error(TapiUtility.LogTag, "Failed to get the neigboring cell info, Error: " + (TapiError)ret);
541 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
548 /// Enters or exits the emergency callback mode asynchronously.
550 /// <param name="mode">The emergency callback mode.</param>
551 /// <returns>A task indicating whether the SetEmergencyCallbackMode method is done or not.</returns>
552 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
553 /// <privlevel>platform</privlevel>
554 /// <feature>http://tizen.org/feature/network.telephony</feature>
555 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
556 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
557 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
558 public Task SetEmergencyCallbackMode(NetworkEmergencyCallbackMode mode)
560 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
562 id = (IntPtr)_requestId++;
563 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
565 Task resultTask = new Task(() =>
567 if (result != (int)TapiError.Success)
569 Log.Error(TapiUtility.LogTag, "Error occurs during setting the emergency callback mode, " + (TapiError)result);
570 task.SetException(new InvalidOperationException("Error occurs during setting the emergency callback mode, " + (TapiError)result));
574 task.SetResult(true);
579 _response_map.Remove(key);
582 int ret = Interop.Tapi.Network.SetNetworkEmergencyCallback(_handle, mode, _response_map[id], id);
583 if (ret != (int)TapiError.Success)
585 Log.Error(TapiUtility.LogTag, "Failed to set the emergency callback mode, Error: " + (TapiError)ret);
586 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
593 /// Set the network roaming preference asynchronously.
595 /// <param name="roamPref">The network roaming preference.</param>
596 /// <returns>A task indicating whether the SetRoamingPreference method is done or not.</returns>
597 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
598 /// <privlevel>platform</privlevel>
599 /// <feature>http://tizen.org/feature/network.telephony</feature>
600 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
601 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
602 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
603 public Task SetRoamingPreference(NetworkPreferred roamPref)
605 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
607 id = (IntPtr)_requestId++;
608 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
610 Task resultTask = new Task(() =>
612 if (result != (int)TapiError.Success)
614 Log.Error(TapiUtility.LogTag, "Error occurs during setting the network roaming preference, " + (TapiError)result);
615 task.SetException(new InvalidOperationException("Error occurs during setting the network roaming preference, " + (TapiError)result));
619 task.SetResult(true);
624 _response_map.Remove(key);
627 int ret = Interop.Tapi.Network.SetNetworkRoamPreference(_handle, roamPref, _response_map[id], id);
628 if (ret != (int)TapiError.Success)
630 Log.Error(TapiUtility.LogTag, "Failed to set the network roaming preference, Error: " + (TapiError)ret);
631 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
638 /// Get the network roaming preference asynchronously.
640 /// <returns>Value of NetworkPreferred.</returns>
641 /// <privilege>http://tizen.org/privilege/telephony</privilege>
642 /// <feature>http://tizen.org/feature/network.telephony</feature>
643 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
644 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
645 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
646 public Task<NetworkPreferred> GetRoamingPreference()
648 TaskCompletionSource<NetworkPreferred> task = new TaskCompletionSource<NetworkPreferred>();
650 id = (IntPtr)_requestId++;
651 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
653 Task resultTask = new Task(() =>
655 if (result != (int)TapiError.Success)
657 Log.Error(TapiUtility.LogTag, "Error occurs during getting the network roaming preference, " + (TapiError)result);
658 task.SetException(new InvalidOperationException("Error occurs during getting the network roaming preference, " + (TapiError)result));
662 task.SetResult((NetworkPreferred)Marshal.ReadInt32(dataResponse));
667 _response_map.Remove(key);
670 int ret = Interop.Tapi.Network.GetNetworkRoamPreference(_handle, _response_map[id], id);
671 if (ret != (int)TapiError.Success)
673 Log.Error(TapiUtility.LogTag, "Failed to get the network roaming preference, Error: " + (TapiError)ret);
674 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
681 /// Set the default data subscription asynchronously.
683 /// <returns>A task indicating whether the SetDefaultDataSubscription method is done or not.</returns>
684 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
685 /// <privlevel>platform</privlevel>
686 /// <feature>http://tizen.org/feature/network.telephony</feature>
687 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
688 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
689 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
690 public Task SetDefaultDataSubscription()
692 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
694 id = (IntPtr)_requestId++;
695 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
697 Task resultTask = new Task(() =>
699 if (result != (int)TapiError.Success)
701 Log.Error(TapiUtility.LogTag, "Error occurs during setting the default data subscription, " + (TapiError)result);
702 task.SetException(new InvalidOperationException("Error occurs during setting the default data subscription, " + (TapiError)result));
706 task.SetResult(true);
711 _response_map.Remove(key);
714 int ret = Interop.Tapi.Network.SetNetworkDefaultDataSubs(_handle, _response_map[id], id);
715 if (ret != (int)TapiError.Success)
717 Log.Error(TapiUtility.LogTag, "Failed to set the default data subscription, Error: " + (TapiError)ret);
718 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
725 /// Get the default data subscription.
727 /// <returns>Value of NetworkDefaultDataSubscription.</returns>
728 /// <privilege>http://tizen.org/privilege/telephony</privilege>
729 /// <feature>http://tizen.org/feature/network.telephony</feature>
730 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
731 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
732 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
733 public NetworkDefaultDataSubscription GetDefaultDataSubscription()
735 NetworkDefaultDataSubscription defaultDataSubs;
736 int ret = Interop.Tapi.Network.GetNetworkDefaultDataSubs(_handle, out defaultDataSubs);
737 if (ret != (int)TapiError.Success)
739 Log.Error(TapiUtility.LogTag, "Failed to get the default data subscription, Error: " + (TapiError)ret);
740 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
743 return defaultDataSubs;
747 /// Set the default subscription for voice asynchronously.
749 /// <returns>A task indicating whether the SetNetworkDefaultSubscription method is done or not.</returns>
750 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
751 /// <privlevel>platform</privlevel>
752 /// <feature>http://tizen.org/feature/network.telephony</feature>
753 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
754 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
755 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
756 public Task SetNetworkDefaultSubscription()
758 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
760 id = (IntPtr)_requestId++;
761 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
763 Task resultTask = new Task(() =>
765 if (result != (int)TapiError.Success)
767 Log.Error(TapiUtility.LogTag, "Error occurs during setting the default subscription for voice, " + (TapiError)result);
768 task.SetException(new InvalidOperationException("Error occurs during setting the default subscription for voice, " + (TapiError)result));
772 task.SetResult(true);
777 _response_map.Remove(key);
780 int ret = Interop.Tapi.Network.SetNetworkDefaultDataSubs(_handle, _response_map[id], id);
781 if (ret != (int)TapiError.Success)
783 Log.Error(TapiUtility.LogTag, "Failed to set the default subscription for voice, Error: " + (TapiError)ret);
784 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
791 /// Get the default subscription for voice.
793 /// <returns>Value of NetworkDefaultSubscription.</returns>
794 /// <privilege>http://tizen.org/privilege/telephony</privilege>
795 /// <feature>http://tizen.org/feature/network.telephony</feature>
796 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
797 /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
798 /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
799 public NetworkDefaultSubscription GetNetworkDefaultSubscription()
801 NetworkDefaultSubscription defaultSubs;
802 int ret = Interop.Tapi.Network.GetNetworkDefaultSubs(_handle, out defaultSubs);
803 if (ret != (int)TapiError.Success)
805 Log.Error(TapiUtility.LogTag, "Failed to get the default subscription, Error: " + (TapiError)ret);
806 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");