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