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.Collections.Generic;
20 using System.Collections.Specialized;
21 using System.Runtime.InteropServices;
23 namespace Tizen.Network.Bluetooth {
26 /// This is the BluetoothLeAdvertiser class. It handles the LE advertising operation amd callback.
28 public class BluetoothLeAdvertiser
30 private static readonly BluetoothLeAdvertiser _instance = new BluetoothLeAdvertiser();
32 internal static BluetoothLeAdvertiser Instance
40 private BluetoothLeAdvertiser()
45 /// This event is called when the LE advertising state changes.
47 public event EventHandler<AdvertisingStateChangedEventArgs> AdvertisingStateChanged
51 BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged += value;
55 BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged -= value;
59 /// Starts advertising using the advertise data object.
62 /// The Bluetooth must be enabled.
64 /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
65 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
66 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
67 public void StartAdvertising(BluetoothLeAdvertiseData advertiseData)
69 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
71 int ret = BluetoothLeImplAdapter.Instance.StartAdvertising (advertiseData.GetHandle ());
72 if (ret != (int)BluetoothError.None) {
73 Log.Error (Globals.LogTag, "Failed to start advertising- " + (BluetoothError)ret);
74 BluetoothErrorFactory.ThrowBluetoothException(ret);
79 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
84 /// Stops the advertising.
87 /// The Bluetooth must be enabled.
89 /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
90 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
91 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
92 public void StopAdvertising(BluetoothLeAdvertiseData advertiseData)
94 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
96 int ret = BluetoothLeImplAdapter.Instance.StopAdvertising (advertiseData.GetHandle ());
97 if (ret != (int)BluetoothError.None) {
98 Log.Error (Globals.LogTag, "Failed to stop advertising operation- " + (BluetoothError)ret);
99 BluetoothErrorFactory.ThrowBluetoothException(ret);
104 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
110 /// This is the BluetoothLeDevice class.
111 /// It handles the LE device operations like getting data from the scan result information.
113 public class BluetoothLeDevice
115 //properties of Bluetoothlesacandata
116 private string _remoteAddress;
117 private BluetoothLeDeviceAddressType _addressType;
119 private byte[] _advDataValue;
120 private byte[] _scanDataValue;
121 private BluetoothLePacketType _packetType;
122 private BluetoothLeScanData _scanData;
125 /// This event is called when the GATT client connects/disconnects with the server.
127 public event EventHandler<GattConnectionStateChangedEventArgs> GattConnectionStateChanged
131 BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged += value;
135 BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged -= value;
139 internal BluetoothLeDevice(BluetoothLeScanData scanData)
141 _scanData = new BluetoothLeScanData ();
142 _scanData = scanData;
144 Log.Info (Globals.LogTag, "Rssi" + _scanData.Rssi);
145 _rssi = scanData.Rssi;
146 Log.Info (Globals.LogTag, "RemoteAddress" + _scanData.RemoteAddress);
147 if (scanData.RemoteAddress != null)
148 _remoteAddress = scanData.RemoteAddress;
149 Log.Info (Globals.LogTag, "AddressType" + _scanData.AddressType);
150 _addressType = scanData.AddressType;
152 Log.Info (Globals.LogTag, "AdvDataLength" + _scanData.AdvDataLength);
153 if (_scanData.AdvDataLength > 0)
155 _advDataValue = new byte[_scanData.AdvDataLength];
156 scanData.AdvData.CopyTo(_advDataValue, 0);
159 Log.Info(Globals.LogTag, "ScanDataLength" + _scanData.ScanDataLength);
160 // Check length before copying
161 if (_scanData.ScanDataLength > 0)
163 _scanDataValue = new byte[_scanData.ScanDataLength];
164 scanData.ScanData.CopyTo(_scanDataValue, 0);
170 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
172 BluetoothLeImplAdapter.Instance.FreeServiceDataList();
177 /// The remote address.
179 public string RemoteAddress
183 return _remoteAddress;
188 /// The type of the address.
190 public BluetoothLeDeviceAddressType AddressType
210 /// The advertsing data information.
212 public byte[] AdvertsingDataInformation
216 return _advDataValue;
221 /// The scan data information.
223 public byte[] ScanDataInformation
227 return _scanDataValue;
232 /// The type of the packet.
234 public BluetoothLePacketType PacketType
247 /// Gets the service UUIDs list from the LE scan result information.
249 /// <value> Gets the list of the string service UUIDs.</value>
251 /// The Bluetooth must be enabled.
253 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
254 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
255 public IEnumerable<string> ServiceUuid
259 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
261 Log.Info(Globals.LogTag, "Retrieving Service uuid- ");
262 return BluetoothLeImplAdapter.Instance.GetLeScanResultServiceUuids(_scanData, _packetType);
269 /// Gets the device name from the LE scan result information.
271 /// <value> Gets the device name.</value>
273 /// The Bluetooth must be enabled.
275 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
276 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
277 public string DeviceName
281 Log.Info(Globals.LogTag, "Retrieving device name- ");
282 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
284 return BluetoothLeImplAdapter.Instance.GetLeScanResultDeviceName(_scanData, _packetType);
290 /// Gets the transmission power level from the LE scan result information.
292 /// <value> Gets the transmission power level in dB.</value>
294 /// The Bluetooth must be enabled.
296 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
297 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
298 public int TxPowerLevel
302 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
304 return BluetoothLeImplAdapter.Instance.GetScanResultTxPowerLevel(_scanData, _packetType);
311 /// Gets the service solicitation UUID list from the scan result information.
313 /// <value> Gets the list of the service solicitation UUIDs.</value>
315 /// The Bluetooth must be enabled.
317 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
318 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
319 public IEnumerable<string> ServiceSolictationUuid
323 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
325 return BluetoothLeImplAdapter.Instance.GetScanResultSvcSolicitationUuids(_scanData, _packetType);
331 /// Gets the manufacturer data from the scan result information.
333 /// <value> Gets the appearance value.</value>
335 /// The Bluetooth must be enabled.
337 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
338 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
339 public int Appearance
343 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
345 return BluetoothLeImplAdapter.Instance.GetScanResultAppearance(_scanData, _packetType);
351 /// Gets the manufacturer data from the scan result information.
353 /// <value> Gets the manufacturer data containing the manucturer data and ID information.</value>
355 /// The Bluetooth must be enabled.
357 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
358 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>///
359 public ManufacturerData ManufacturerData
363 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
365 return BluetoothLeImplAdapter.Instance.GetScanResultManufacturerData(_scanData, _packetType);
372 /// Gets the service data list from the scan result information.
375 /// The Bluetooth must be enabled.
377 /// <returns> Returns the service data list.</returns>
378 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
379 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
380 public IEnumerable<BluetoothLeServiceData> GetServiceDataList()
382 int serviceCount = 0;
383 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
385 return BluetoothLeImplAdapter.Instance.GetScanResultServiceDataList(_scanData,
386 _packetType, out serviceCount);
393 /// Creates a GATT connection with the remote device.
396 /// The Bluetooth must be enabled.
398 /// <param name="autoConnect"> The auto connect flag.</param>
399 /// <returns>client instance</returns>
400 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
401 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
402 /// or when the gatt connection attempt to remote device fails.</exception>
403 public BluetoothGattClient GattConnect(bool autoConnect)
405 BluetoothGattClient client = null;
406 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
408 int ret = BluetoothLeImplAdapter.Instance.GattConnect (_remoteAddress, autoConnect);
409 if (ret != (int)BluetoothError.None) {
410 Log.Error (Globals.LogTag, "Failed to create GATT Connection with remote device- " + (BluetoothError)ret);
414 client = BluetoothGattClient.CreateClient(_remoteAddress);
419 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
425 /// Disconnects a GATT connection with the remote device.
428 /// The Bluetooth must be enabled.
430 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
431 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
432 /// or when the GATT disconnection attempt to remote device fails.</exception>
433 public void GattDisconnect()
435 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
437 int ret = BluetoothLeImplAdapter.Instance.GattDisconnect (_remoteAddress);
438 if (ret != (int)BluetoothError.None) {
439 Log.Error (Globals.LogTag, "Failed to disconnect GATT connection with remote device- " + (BluetoothError)ret);
444 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
450 /// Bluetooth LE advertise data. Handles the data advertising.
452 public class BluetoothLeAdvertiseData:IDisposable
454 private IntPtr _handle = IntPtr.Zero;
455 private BluetoothLeAdvertisingMode _mode;
456 private bool _advertisingConnectable;
457 private BluetoothLePacketType _packetType;
458 private int _appearance;
459 private bool _includePowerLevel;
460 private bool _includeDeviceName;
463 /// The default constructor initializes an object of the BluetoothLeAdvertiseData.
465 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
466 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
467 /// or when create advertiser fails.</exception>
468 public BluetoothLeAdvertiseData()
470 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
472 Log.Debug(Globals.LogTag, " Creating LeAdvertiser()");
473 int ret = Interop.Bluetooth.CreateAdvertiser(out _handle);
474 if (ret != (int)BluetoothError.None)
476 Log.Error(Globals.LogTag, "Failed to create advertiser object- " + (BluetoothError)ret);
477 BluetoothErrorFactory.ThrowBluetoothException(ret);
482 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
486 ~BluetoothLeAdvertiseData()
488 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
491 ClearAdvertisingData (BluetoothLePacketType.BluetoothLeAdvertisingPacket);
492 ClearAdvertisingData (BluetoothLePacketType.BluetoothLeScanResponsePacket);
493 BluetoothLeImplAdapter.Instance.DestroyAdvertiser (_handle);
498 internal IntPtr GetHandle()
504 /// The advertising mode to control the advertising power and latency.
507 /// The Bluetooth must be enabled.
509 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
510 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
511 /// or when the set advertising mode fails.</exception>
512 public BluetoothLeAdvertisingMode AdvertisingMode
520 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
523 int ret = Interop.Bluetooth.SetAdvertisingMode (GetHandle (), _mode);
524 if (ret != (int)BluetoothError.None) {
525 Log.Error (Globals.LogTag, "Failed to set advertising mode- " + (BluetoothError)ret);
526 BluetoothErrorFactory.ThrowBluetoothException (ret);
533 /// The advertising connectable type.
536 /// The Bluetooth must be enabled.
538 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
539 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
540 /// or when the set advertising connectable mode fails.</exception>
541 public bool AdvertisingConnectable
545 return _advertisingConnectable;
549 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
551 _advertisingConnectable = value;
552 int ret = Interop.Bluetooth.SetAdvertisingConnectable (GetHandle (), _advertisingConnectable);
553 if (ret != (int)BluetoothError.None) {
554 Log.Error (Globals.LogTag, "Failed to set advertising connectable value- " + (BluetoothError)ret);
555 BluetoothErrorFactory.ThrowBluetoothException (ret);
561 public void Dispose()
564 GC.SuppressFinalize(this);
567 private void Dispose(bool disposing)
573 /// The type of the packet.
575 public BluetoothLePacketType PacketType
587 /// Sets the external appearance of this device to the advertise or the scan response data.
588 /// Please refer to the adopted Bluetooth specification for the appearance.
591 /// The Bluetooth must be enabled.
593 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
594 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
595 /// or when the set appearance fails.</exception>
596 public int Appearance
605 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize) {
606 int ret = Interop.Bluetooth.SetAdvertisingAppearance (GetHandle (), _packetType, _appearance);
607 if (ret != (int)BluetoothError.None) {
608 Log.Error (Globals.LogTag, "Failed to add appearance value to advertising data- " + (BluetoothError)ret);
609 BluetoothErrorFactory.ThrowBluetoothException(ret);
615 /// Sets whether the device name has to be included in the advertise or the scan response data.
616 /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
619 /// The Bluetooth must be enabled.
621 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
622 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
623 /// or when the set advertising device name fails.</exception>
624 public bool IncludeDeviceName
628 return _includeDeviceName;
632 _includeDeviceName = value;
633 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
635 int ret = Interop.Bluetooth.SetAdvertisingDeviceName(GetHandle(), _packetType, _includeDeviceName);
636 if (ret != (int)BluetoothError.None) {
637 Log.Error (Globals.LogTag, "Failed to add device name to advertising data- " + (BluetoothError)ret);
638 BluetoothErrorFactory.ThrowBluetoothException(ret);
646 /// Sets whether the transmission power level should be included in the advertise or the scan response data.
647 /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
650 /// The Bluetooth must be enabled.
652 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
653 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
654 /// or when the set advertising TC power level fails.</exception>
655 public bool IncludeTxPowerLevel
659 return _includePowerLevel;
663 _includePowerLevel = value;
664 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
666 int ret = Interop.Bluetooth.SetAdvertisingTxPowerLevel(GetHandle(), _packetType, _includePowerLevel);
667 if (ret != (int)BluetoothError.None)
669 Log.Error(Globals.LogTag, "Failed to add advertising service solicitation uuid- " + (BluetoothError)ret);
675 /// Adds a service UUID to the advertise or the scan response data.
676 /// The maximum advertised or responded data size is 31 bytes
677 /// including the data type and the system wide data.
680 /// The Bluetooth must be enabled.
682 /// <param name="packetType">The packet type.</param>
683 /// <param name="serviceUuid"> The service UUID to add to advertise data.</param>
684 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
685 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
686 /// or when the add advertising service UUID procedure fails.</exception>
687 public void AddAdvertisingServiceUuid(BluetoothLePacketType packetType, string serviceUuid)
689 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
691 int ret = Interop.Bluetooth.AddAdvertisingServiceUuid (GetHandle (), packetType, serviceUuid);
692 if (ret != (int)BluetoothError.None) {
693 Log.Error (Globals.LogTag, "Failed to add service uuid to advertising data- " + (BluetoothError)ret);
694 BluetoothErrorFactory.ThrowBluetoothException (ret);
699 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
704 /// Adds a service solicitation UUID to advertise or scan the response data.
705 /// The maximum advertised or responded data size is 31 bytes
706 /// including the data type and the system wide data.
709 /// The Bluetooth must be enabled.
711 /// <param name="packetType">The packet type.</param>
712 /// <param name="serviceSolicitationUuid"> The service solicitation UUID to add to advertise data.</param>
713 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
714 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
715 /// or when the add advertising service solicitation UUID procedure fails.</exception>
716 public void AddAdvertisingServiceSolicitationUuid(BluetoothLePacketType packetType,
717 string serviceSolicitationUuid)
719 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
721 int ret = Interop.Bluetooth.AddAdvertisingServiceSolicitationUuid(GetHandle(), packetType,
722 serviceSolicitationUuid);
723 if (ret != (int)BluetoothError.None) {
724 Log.Error (Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
725 BluetoothErrorFactory.ThrowBluetoothException(ret);
730 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
735 /// Adds a service data to the advertise or the scan response data.
736 /// The maximum advertised or responded data size is 31 bytes
737 /// including data type and system wide data.
740 /// The Bluetooth must be enabled.
742 /// <param name="packetType">The packet type.</param>
743 /// <param name="data"> The service data to be added to advertising.</param>
744 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
745 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
746 /// or when the add advertising data procedure fails.</exception>
747 public void AddAdvertisingServiceData(BluetoothLePacketType packetType, BluetoothServiceData data)
749 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
751 IntPtr serviceDataPtr;
752 serviceDataPtr = Marshal.AllocHGlobal(data.DataLength);
753 Marshal.Copy(data.Data, 0, serviceDataPtr, data.DataLength);
755 for (int i = 0; i < 3; i++)
756 Log.Error (Globals.LogTag, " service data is " + data.Data [i]);
757 int ret = Interop.Bluetooth.AddAdvertisingServiceData(GetHandle(), packetType,
758 data.Uuid, serviceDataPtr, data.DataLength);
759 if (ret != (int)BluetoothError.None)
761 Log.Error(Globals.LogTag, "Failed to add service data to advertising data- " + (BluetoothError)ret);
762 BluetoothErrorFactory.ThrowBluetoothException(ret);
767 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
772 /// Adds the manufacturer specific data to the advertise or the scan response data.
773 /// Please refer to the adopted Bluetooth specification for the the appearance.
776 /// The Bluetooth must be enabled.
778 /// <param name="packetType">The packet type.</param>
779 /// <param name="manufacturerData"> The manufacturer specific data.</param>
780 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
781 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
782 /// or when the add advertising manufacturer data procedure fails.</exception>
783 public void AddAdvertisingManufacturerData(BluetoothLePacketType packetType,
784 ManufacturerData manufacturerData)
786 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
789 manufDataPtr = Marshal.AllocHGlobal(manufacturerData.DataLength);
790 Marshal.Copy(manufacturerData.Data, 0, manufDataPtr, manufacturerData.DataLength);
792 int ret = Interop.Bluetooth.AddAdvertisingManufData(GetHandle(), packetType,
793 manufacturerData.Id, manufDataPtr, manufacturerData.DataLength);
794 if (ret != (int)BluetoothError.None)
796 Log.Error(Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
797 BluetoothErrorFactory.ThrowBluetoothException(ret);
802 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
807 /// Clears all data to be advertised or responded to the scan request from the LE scanning device.
810 /// The Bluetooth must be enabled.
812 /// <param name="packetType">The packet type to be cleared.</param>
813 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
814 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
815 /// or when the clear advertising data procedure fails.</exception>
816 internal void ClearAdvertisingData(BluetoothLePacketType packetType)
818 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
820 int ret = Interop.Bluetooth.ClearAdvertisingData (GetHandle (), packetType);
821 if (ret != (int)BluetoothError.None) {
822 Log.Error (Globals.LogTag, "Failed to Clear Advertising Data- " + (BluetoothError)ret);
827 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);