2500e55f51897ef68d6b2aac297b43e59b008fdc
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Bluetooth / Tizen.Network.Bluetooth / BluetoothDevice.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Collections.Concurrent;
21 using System.Collections.ObjectModel;
22 using System.Collections.Specialized;
23 using System.Reflection;
24
25 namespace Tizen.Network.Bluetooth
26 {
27     /// <summary>
28     /// This class is used to handle the connection with other devices and set authorization of other devices.<br/>
29     /// The BluetoothDevice class is used to search for services available on remote devices.
30     /// </summary>
31     /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
32     /// <since_tizen> 3 </since_tizen>
33     public class BluetoothDevice
34     {
35         private event EventHandler<BondCreatedEventArgs> _bondCreated;
36         private event EventHandler<BondDestroyedEventArgs> _bondDestroyed;
37         private event EventHandler<AuthorizationChangedEventArgs> _authorizationChanged;
38         private event EventHandler<ServiceSearchedEventArgs> _serviceSearched;
39         private event EventHandler<DeviceConnectionStateChangedEventArgs> _connectionChanged;
40
41         private Interop.Bluetooth.BondCreatedCallback _bondCreatedCallback;
42         private Interop.Bluetooth.BondDestroyedCallback _bondDestroyedCallback;
43         private Interop.Bluetooth.AuthorizationChangedCallback _authorizationChangedCallback;
44         private Interop.Bluetooth.ServiceSearchedCallback _serviceSearchedCallback;
45         private Interop.Bluetooth.DeviceConnectionStateChangedCallback _connectionChangedCallback;
46         private Interop.Bluetooth.ConnectedProfileCallback _connectedProfileCallback;
47
48         internal string RemoteDeviceAddress;
49         internal string RemoteDeviceName;
50         internal int RemoteDeviceRssi;
51         internal BluetoothClass RemoteDeviceClass;
52         internal Collection<string> RemoteDeviceService;
53         internal int RemoteDeviceCount;
54         internal bool RemotePaired;
55         internal bool RemoteAuthorized;
56         internal bool RemoteConnected;
57         internal BluetoothAppearanceType RemoteAppearance;
58         internal int RemoteManufLength;
59         internal string RemoteManufData;
60
61         internal BluetoothDevice()
62         {
63         }
64
65         /// <summary>
66         /// The address of the device.
67         /// </summary>
68         /// <since_tizen> 3 </since_tizen>
69         public string Address
70         {
71             get
72             {
73                 return RemoteDeviceAddress;
74             }
75         }
76         /// <summary>
77         /// The name of the device.
78         /// </summary>
79         /// <since_tizen> 3 </since_tizen>
80         public string Name
81         {
82             get
83             {
84                 return RemoteDeviceName;
85             }
86         }
87         /// <summary>
88         /// The strength indicator of received signal of the device.
89         /// </summary>
90         /// <since_tizen> 3 </since_tizen>
91         public int Rssi
92         {
93             get
94             {
95                 return RemoteDeviceRssi;
96             }
97         }
98         /// <summary>
99         /// The class of the device.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         public BluetoothClass Class
103         {
104             get
105             {
106                 return RemoteDeviceClass;
107             }
108         }
109         /// <summary>
110         /// The service UUID list of the device.
111         /// </summary>
112         /// <since_tizen> 3 </since_tizen>
113         public IEnumerable<string> ServiceUuidList
114         {
115             get
116             {
117                 return RemoteDeviceService;
118             }
119         }
120         /// <summary>
121         /// The number of services.
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         public int ServiceCount
125         {
126             get
127             {
128                 return RemoteDeviceCount;
129             }
130         }
131         /// <summary>
132         /// The paired state of the device.
133         /// </summary>
134         /// <since_tizen> 3 </since_tizen>
135         public bool IsPaired
136         {
137             get
138             {
139                 return RemotePaired;
140             }
141         }
142         /// <summary>
143         /// The connection state of the device.
144         /// </summary>
145         /// <since_tizen> 3 </since_tizen>
146         public bool IsConnected
147         {
148             get
149             {
150                 return RemoteConnected;
151             }
152         }
153         /// <summary>
154         /// The authorization state of the device.
155         /// </summary>
156         /// <since_tizen> 3 </since_tizen>
157         public bool IsAuthorized
158         {
159             get
160             {
161                 return RemoteAuthorized;
162             }
163         }
164         /// <summary>
165         /// The Bluetooth appearance.
166         /// </summary>
167         /// <since_tizen> 3 </since_tizen>
168         public BluetoothAppearanceType AppearanceType
169         {
170             get
171             {
172                 return RemoteAppearance;
173             }
174         }
175
176         /// <summary>
177         /// The length of the manufacturer data.
178         /// </summary>
179         /// <since_tizen> 3 </since_tizen>
180         public int ManufacturerDataLength
181         {
182             get
183             {
184                 return RemoteManufLength;
185             }
186         }
187         /// <summary>
188         /// The manufacturer data.
189         /// </summary>
190         /// <since_tizen> 3 </since_tizen>
191         public string ManufacturerData
192         {
193             get
194             {
195                 return RemoteManufData;
196             }
197         }
198
199         /// <summary>
200         /// The BondCreated event is raised when the process of creating the bond is finished.
201         /// </summary>
202         /// <since_tizen> 3 </since_tizen>
203         public event EventHandler<BondCreatedEventArgs> BondCreated
204         {
205             add
206             {
207                 if (_bondCreated == null)
208                 {
209                     RegisterBondCreatedEvent();
210                 }
211                 _bondCreated += value;
212             }
213             remove
214             {
215                 _bondCreated -= value;
216                 if (_bondCreated == null)
217                 {
218                     UnregisterBondCreatedEvent();
219                 }
220             }
221         }
222
223         /// <summary>
224         /// The BondDestroyed event is raised when the bond is destroyed.
225         /// </summary>
226         /// <since_tizen> 3 </since_tizen>
227         public event EventHandler<BondDestroyedEventArgs> BondDestroyed
228         {
229             add
230             {
231                 if (_bondDestroyed == null)
232                 {
233                     RegisterBondDestroyedEvent();
234                 }
235                 _bondDestroyed += value;
236             }
237             remove
238             {
239                 _bondDestroyed -= value;
240                 if (_bondDestroyed == null)
241                 {
242                     UnregisterBondDestroyedEvent();
243                 }
244             }
245         }
246
247         /// <summary>
248         /// The AuthorizationChanged event is raised when the authorization of the device is changed.
249         /// </summary>
250         /// <since_tizen> 3 </since_tizen>
251         public event EventHandler<AuthorizationChangedEventArgs> AuthorizationChanged
252         {
253             add
254             {
255                 if (_authorizationChanged == null)
256                 {
257                     RegisterAuthorizationChangedEvent();
258                 }
259                 _authorizationChanged += value;
260             }
261             remove
262             {
263                 _authorizationChanged -= value;
264                 if (_authorizationChanged == null)
265                 {
266                     UnregisterAuthorizationChangedEvent();
267                 }
268             }
269         }
270
271         /// <summary>
272         /// The ServiceSearched event is raised when the process of service searched is finished.
273         /// </summary>
274         /// <since_tizen> 3 </since_tizen>
275         public event EventHandler<ServiceSearchedEventArgs> ServiceSearched
276         {
277             add
278             {
279                 if (_serviceSearched == null)
280                 {
281                     RegisterServiceSearchedEvent();
282                 }
283                 _serviceSearched += value;
284             }
285             remove
286             {
287                 _serviceSearched -= value;
288                 if (_serviceSearched == null)
289                 {
290                     UnregisterServiceSearchedEvent();
291                 }
292             }
293         }
294
295         /// <summary>
296         /// The ConnectionStateChanged event is raised when the connection state is changed.
297         /// </summary>
298         /// <since_tizen> 3 </since_tizen>
299         public event EventHandler<DeviceConnectionStateChangedEventArgs> ConnectionStateChanged
300         {
301             add
302             {
303                 if (_connectionChanged == null)
304                 {
305                     RegisterConnectionChangedEvent();
306                 }
307                 _connectionChanged += value;
308             }
309             remove
310             {
311                 _connectionChanged -= value;
312                 if (_connectionChanged == null)
313                 {
314                     UnregisterConnectionChangedEvent();
315                 }
316             }
317         }
318
319         private void RegisterBondCreatedEvent()
320         {
321             _bondCreatedCallback = (int result, ref BluetoothDeviceStruct device, IntPtr userData) =>
322             {
323                 if (_bondCreated != null)
324                 {
325                     BluetoothError res = (BluetoothError)result;
326                     _bondCreated(null, new BondCreatedEventArgs(res, BluetoothUtils.ConvertStructToDeviceClass(device)));
327                 }
328             };
329             int ret = Interop.Bluetooth.SetBondCreatedCallback(_bondCreatedCallback, IntPtr.Zero);
330             if (ret != (int)BluetoothError.None)
331             {
332                 Log.Error(Globals.LogTag, "Failed to set bond created callback, Error - " + (BluetoothError)ret);
333             }
334         }
335
336         private void UnregisterBondCreatedEvent()
337         {
338             int ret = Interop.Bluetooth.UnsetBondCreatedCallback();
339             if (ret != (int)BluetoothError.None)
340             {
341                 Log.Error(Globals.LogTag, "Failed to unset bond created callback, Error - " + (BluetoothError)ret);
342             }
343         }
344
345         private void RegisterBondDestroyedEvent()
346         {
347             _bondDestroyedCallback = (int result, string deviceAddress, IntPtr userData) =>
348             {
349                 if (_bondDestroyed != null)
350                 {
351                     BluetoothError res = (BluetoothError)result;
352                     _bondDestroyed(null, new BondDestroyedEventArgs(res, deviceAddress));
353                 }
354             };
355             int ret = Interop.Bluetooth.SetBondDestroyedCallback(_bondDestroyedCallback, IntPtr.Zero);
356             if (ret != (int)BluetoothError.None)
357             {
358                 Log.Error(Globals.LogTag, "Failed to set bond destroyed callback, Error - " + (BluetoothError)ret);
359             }
360         }
361
362         private void UnregisterBondDestroyedEvent()
363         {
364             int ret = Interop.Bluetooth.UnsetBondDestroyedCallback();
365             if (ret != (int)BluetoothError.None)
366             {
367                 Log.Error(Globals.LogTag, "Failed to unset bond destroyed callback, Error - " + (BluetoothError)ret);
368             }
369         }
370
371         private void RegisterServiceSearchedEvent()
372         {
373             _serviceSearchedCallback = (int result, ref BluetoothDeviceSdpStruct sdp, IntPtr userData) =>
374             {
375                 Log.Info(Globals.LogTag, "Servicesearched cb is called");
376                 if (_serviceSearched != null)
377                 {
378                     BluetoothError res = (BluetoothError)result;
379                     _serviceSearched(null, new ServiceSearchedEventArgs(res, BluetoothUtils.ConvertStructToSdpData(sdp)));
380                 }
381             };
382             int ret = Interop.Bluetooth.SetServiceSearchedCallback(_serviceSearchedCallback, IntPtr.Zero);
383             if (ret != (int)BluetoothError.None)
384             {
385                 Log.Error(Globals.LogTag, "Failed to set service searched callback, Error - " + (BluetoothError)ret);
386             }
387         }
388
389         private void UnregisterServiceSearchedEvent()
390         {
391             int ret = Interop.Bluetooth.UnsetServiceSearchedCallback();
392             if (ret != (int)BluetoothError.None)
393             {
394                 Log.Error(Globals.LogTag, "Failed to unset service searched callback, Error - " + (BluetoothError)ret);
395             }
396         }
397
398         private void RegisterAuthorizationChangedEvent()
399         {
400             _authorizationChangedCallback = (int authorization, string deviceAddress, IntPtr userData) =>
401             {
402                 Log.Info(Globals.LogTag, "Authorization changed cb is called");
403                 if (_authorizationChanged != null)
404                 {
405                     BluetoothAuthorizationType auth = (BluetoothAuthorizationType)authorization;
406                     _authorizationChanged(null, new AuthorizationChangedEventArgs(auth, deviceAddress));
407                 }
408             };
409             int ret = Interop.Bluetooth.SetAuthorizationChangedCallback(_authorizationChangedCallback, IntPtr.Zero);
410             if (ret != (int)BluetoothError.None)
411             {
412                 Log.Error(Globals.LogTag, "Failed to set authroization changed callback, Error - " + (BluetoothError)ret);
413             }
414         }
415
416         private void UnregisterAuthorizationChangedEvent()
417         {
418             int ret = Interop.Bluetooth.UnsetAuthorizationChangedCallback();
419             if (ret != (int)BluetoothError.None)
420             {
421                 Log.Error(Globals.LogTag, "Failed to unset authroization changed callback, Error - " + (BluetoothError)ret);
422             }
423         }
424
425         private void RegisterConnectionChangedEvent()
426         {
427             _connectionChangedCallback = (bool connected, ref BluetoothDeviceConnectionStruct device, IntPtr userData) =>
428             {
429                 Log.Info(Globals.LogTag, "Connection state changed cb is called");
430                 if (_connectionChanged != null)
431                 {
432                     _connectionChanged(null, new DeviceConnectionStateChangedEventArgs(connected, BluetoothUtils.ConvertStructToConnectionData(device)));
433                 }
434             };
435
436             int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(_connectionChangedCallback, IntPtr.Zero);
437             if (ret != (int)BluetoothError.None)
438             {
439                 Log.Error(Globals.LogTag, "Failed to set connection state changed callback, Error - " + (BluetoothError)ret);
440             }
441         }
442
443         private void UnregisterConnectionChangedEvent()
444         {
445             int ret = Interop.Bluetooth.UnsetConnectionStateChangedCallback();
446             if (ret != (int)BluetoothError.None)
447             {
448                 Log.Error(Globals.LogTag, "Failed to unset connection state changed callback, Error - " + (BluetoothError)ret);
449             }
450         }
451
452         /// <summary>
453         /// Creates a bond with the remote Bluetooth device.
454         /// </summary>
455         /// <remarks>
456         /// The Bluetooth must be enabled and the remote device must be discoverable by StartDiscovery(). The bond can be destroyed by DestroyBond().
457         /// The bonding request can be cancelled by CancelBonding(). If this succeeds, the BondCreated event will be invoked.
458         /// </remarks>
459         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
460         /// or when the create bonding process to the remote device fails.</exception>
461         /// <since_tizen> 3 </since_tizen>
462         public void CreateBond()
463         {
464             if (BluetoothAdapter.IsBluetoothEnabled)
465             {
466                 int ret = Interop.Bluetooth.CreateBond(RemoteDeviceAddress);
467                 if (ret != (int)BluetoothError.None)
468                 {
469                     Log.Error(Globals.LogTag, "Failed to create bond, Error - " + (BluetoothError)ret);
470                     BluetoothErrorFactory.ThrowBluetoothException(ret);
471                 }
472             }
473         }
474
475         /// <summary>
476         /// Cancels the bonding process.
477         /// </summary>
478         /// <remarks>
479         /// Bonding must be in progress by CreateBond().
480         /// </remarks>
481         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
482         /// or when the cancel bonding procedure to remote device fails.</exception>
483         /// <since_tizen> 3 </since_tizen>
484         public void CancelBonding()
485         {
486             int ret = Interop.Bluetooth.CancelBonding();
487             if (ret != (int)BluetoothError.None)
488             {
489                 Log.Error(Globals.LogTag, "Failed to cancel bonding process, Error - " + (BluetoothError)ret);
490                 BluetoothErrorFactory.ThrowBluetoothException(ret);
491             }
492         }
493
494         /// <summary>
495         /// Destroys the bond.
496         /// </summary>
497         /// <remarks>
498         /// The Bluetooth must be enabled and the bond must be created by CreateBond().
499         /// If this succeeds, the BondDestroyed event will be invoked.
500         /// </remarks>
501         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
502         /// or when the destroy bonding procedure fails.</exception>
503         /// <since_tizen> 3 </since_tizen>
504         public void DestroyBond()
505         {
506             if (BluetoothAdapter.IsBluetoothEnabled)
507             {
508                 int ret = Interop.Bluetooth.DestroyBond(RemoteDeviceAddress);
509                 if (ret != (int)BluetoothError.None)
510                 {
511                     Log.Error(Globals.LogTag, "Failed to destroy bond, Error - " + (BluetoothError)ret);
512                     BluetoothErrorFactory.ThrowBluetoothException(ret);
513                 }
514             }
515         }
516
517         /// <summary>
518         /// Sets an alias for the bonded device.
519         /// </summary>
520         /// <remarks>
521         /// The Bluetooth must be enabled and the bond must be created by CreateBond().
522         /// </remarks>
523         /// <param name="aliasName">The alias name of the remote device.</param>
524         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
525         /// or when the set alias name to remote device fails.</exception>
526         /// <since_tizen> 3 </since_tizen>
527         public void SetAlias(string aliasName)
528         {
529             if (BluetoothAdapter.IsBluetoothEnabled)
530             {
531                 int ret = Interop.Bluetooth.SetAlias(RemoteDeviceAddress, aliasName);
532                 if (ret != (int)BluetoothError.None)
533                 {
534                     Log.Error(Globals.LogTag, "Failed to set alias name, Error - " + (BluetoothError)ret);
535                     BluetoothErrorFactory.ThrowBluetoothException(ret);
536                 }
537             }
538         }
539
540         /// <summary>
541         /// Sets the authorization of a bonded device.
542         /// </summary>
543         /// <remarks>
544         /// The Bluetooth must be enabled and the bond must be created by CreateBond().
545         /// If this succeeds, the AuthorizationChanged event will be invoked.
546         /// </remarks>
547         /// <param name="authorizationState">The authorization state.</param>
548         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
549         /// or when the set authorization to remote device fails.</exception>
550         /// <since_tizen> 3 </since_tizen>
551         public void SetAuthorization(BluetoothAuthorizationType authorizationState)
552         {
553             if (BluetoothAdapter.IsBluetoothEnabled)
554             {
555                 int ret = Interop.Bluetooth.SetAuthorization(RemoteDeviceAddress, (int)authorizationState);
556                 if (ret != (int)BluetoothError.None)
557                 {
558                     Log.Error(Globals.LogTag, "Failed to set authroization state, Error - " + (BluetoothError)ret);
559                     BluetoothErrorFactory.ThrowBluetoothException(ret);
560                 }
561             }
562         }
563
564         /// <summary>
565         /// Gets the mask from the UUID.
566         /// </summary>
567         /// <returns>The service mask list converted from the given UUID list.</returns>
568         /// <param name="uuids">The UUID list of the device.</param>
569         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
570         /// or when the get Mask from UUID fails.</exception>
571         /// <since_tizen> 3 </since_tizen>
572         public BluetoothServiceClassType GetMaskFromUuid(string[] uuids)
573         {
574             BluetoothServiceClassType serviceMask;
575
576             int ret = Interop.Bluetooth.GetMaskFromUuid(uuids, uuids.Length, out serviceMask);
577             if (ret != (int)BluetoothError.None)
578             {
579                 Log.Error(Globals.LogTag, "Failed to get service mask, Error - " + (BluetoothError)ret);
580                 BluetoothErrorFactory.ThrowBluetoothException(ret);
581             }
582             return serviceMask;
583         }
584
585         /// <summary>
586         /// Starts the search for services supported by the specified device.
587         /// </summary>
588         /// <remarks>
589         /// The Bluetooth must be enabled and remote device must be discoverable by StartDiscovery(). The bond must be created by CreateBond().
590         /// If this succeeds, the ServiceSearched event will be invoked.
591         /// </remarks>
592         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
593         /// or when the remote device service search fails.</exception>
594         /// <since_tizen> 3 </since_tizen>
595         public void StartServiceSearch()
596         {
597             Log.Info(Globals.LogTag, "startservicesearch entry");
598             if (BluetoothAdapter.IsBluetoothEnabled)
599             {
600                 int ret = Interop.Bluetooth.StartServiceSearch(RemoteDeviceAddress);
601                 if (ret != (int)BluetoothError.None)
602                 {
603                     Log.Error(Globals.LogTag, "Failed to start service search, Error - " + (BluetoothError)ret);
604                     BluetoothErrorFactory.ThrowBluetoothException(ret);
605                 }
606             }
607         }
608
609         /// <summary>
610         /// Gets the connected profiles.
611         /// </summary>
612         /// <remarks>
613         /// The Bluetooth must be enabled.
614         /// </remarks>
615         /// <returns>The connected Bluetooth profiles.</returns>
616         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
617         /// or when there is no BT connection.</exception>
618         /// <since_tizen> 3 </since_tizen>
619         public IEnumerable<BluetoothProfileType> GetConnectedProfiles()
620         {
621             if (BluetoothAdapter.IsBluetoothEnabled)
622             {
623                 List<BluetoothProfileType> profileList = new List<BluetoothProfileType>();
624                 _connectedProfileCallback = (int profile, IntPtr userData) =>
625                 {
626                     if (!profile.Equals(null))
627                     {
628                         profileList.Add((BluetoothProfileType)profile);
629                     }
630                     return true;
631                 };
632                 int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, _connectedProfileCallback, IntPtr.Zero);
633                 if (ret != (int)BluetoothError.None)
634                 {
635                     Log.Error(Globals.LogTag, "Failed to get connected profiles, Error - " + (BluetoothError)ret);
636                     BluetoothErrorFactory.ThrowBluetoothException(ret);
637                 }
638                 return profileList;
639             }
640             else
641             {
642                 return null;
643             }
644         }
645
646         /// <summary>
647         /// Determines if profile is connected to the specified remote device.
648         /// </summary>
649         /// <remarks>
650         /// The Bluetooth must be enabled.
651         /// </remarks>
652         /// <returns><c>true</c> if profile is connected, otherwise <c>false</c>.</returns>
653         /// <param name="profileType">The Bluetooth profile type.</param>
654         /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
655         /// or when there is no BT connection.</exception>
656         /// <since_tizen> 3 </since_tizen>
657         public bool IsProfileConnected(BluetoothProfileType profileType)
658         {
659             if (BluetoothAdapter.IsBluetoothEnabled)
660             {
661                 bool isConnected;
662                 int ret = Interop.Bluetooth.IsProfileConnected(RemoteDeviceAddress, (int)profileType, out isConnected);
663                 if (ret != (int)BluetoothError.None)
664                 {
665                     Log.Error(Globals.LogTag, "Failed to get profile connected state, Error - " + (BluetoothError)ret);
666                 }
667                 return isConnected;
668             }
669             else
670             {
671                 return false;
672             }
673         }
674
675         /// <summary>
676         /// Returns the instance of the Bluetooth profile type.
677         /// </summary>
678         /// <remarks>
679         /// The Bluetooth must be enabled.
680         /// </remarks>
681         /// <returns>The profile instance.</returns>
682         /// <since_tizen> 3 </since_tizen>
683         public T GetProfile<T>() where T : BluetoothProfile
684         {
685             try
686             {
687                 // TODO : Need to check capability of supporting profiles
688                 var profile = (T)Activator.CreateInstance(typeof(T), true);
689                 profile.RemoteAddress = RemoteDeviceAddress;
690                 return profile;
691             }
692             catch (TargetInvocationException err)
693             {
694                 throw err.InnerException;
695             }
696         }
697
698         /// <summary>
699         /// Creates the client socket.
700         /// </summary>
701         /// <returns>The IBluetoothClientSocket instance.</returns>
702         /// <param name="serviceUuid">The UUID of the service.</param>
703         /// <since_tizen> 3 </since_tizen>
704         public IBluetoothClientSocket CreateSocket(string serviceUuid)
705         {
706             BluetoothSocket clientSocket = new BluetoothSocket();
707             clientSocket.remoteAddress = this.Address;
708             clientSocket.serviceUuid = serviceUuid;
709             return (IBluetoothClientSocket)clientSocket;
710         }
711     }
712 }