/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.ComponentModel;
namespace Tizen.Network.Bluetooth
{
///
/// This class is used to handle the connection with other Bluetooth audio devices
/// like headset, hands-free, and headphone.
///
/// http://tizen.org/privilege/bluetooth
/// 3
public class BluetoothAudio : BluetoothProfile
{
internal BluetoothAudio()
{
}
///
/// The AudioConnectionStateChanged event is called when the audio connection state is changed.
///
/// 3
public event EventHandler AudioConnectionStateChanged
{
add
{
BluetoothAudioImpl.Instance.AudioConnectionStateChanged += value;
}
remove
{
BluetoothAudioImpl.Instance.AudioConnectionStateChanged -= value;
}
}
///
/// Connects the remote device with the given audio profile.
///
///
/// The device must be bonded with the remote device by CreateBond(). If connection request succeeds, the AudioConnectionStateChanged event will be invoked.
/// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp
/// and AdvancedAudioDistribution is connected.
///
/// The type of the audio profile.
/// Thrown when the Bluetooth is not supported.
/// Thrown when the Bluetooth is not enabled
/// or when the connection attempt fails.
/// 3
public void Connect(BluetoothAudioProfileType profileType)
{
if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
{
int ret = BluetoothAudioImpl.Instance.Connect(RemoteAddress, profileType);
if (ret != (int)BluetoothError.None)
{
Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
BluetoothErrorFactory.ThrowBluetoothException(ret);
}
}
else
{
BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
}
}
///
/// Disconnects the remote device with the given audio profile.
///
///
/// The device must be connected by Connect(). If the disconnection request succeeds, the AudioConnectionStateChanged event will be invoked.
/// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp
/// and AdvancedAudioDistribution is disconnected.
///
/// The type of the audio profile.
/// Thrown when the Bluetooth is not supported.
/// Thrown when the Bluetooth is not enabled
/// or when Disconnection attempt fails.
/// 3
public void Disconnect(BluetoothAudioProfileType type)
{
if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
{
int ret = BluetoothAudioImpl.Instance.Disconnect(RemoteAddress, type);
if (ret != (int)BluetoothError.None)
{
Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
BluetoothErrorFactory.ThrowBluetoothException(ret);
}
}
else
{
BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
}
}
///
/// Opens a AG(Audio Gateway) SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously.
///
/// 6
/// http://tizen.org/feature/network.bluetooth
/// http://tizen.org/feature/network.bluetooth.audio.call
/// http://tizen.org/privilege/bluetooth.admin
/// Thrown when the Bluetooth is not supported.
/// Thrown when the method is failed with message.
[EditorBrowsable(EditorBrowsableState.Never)]
public static void OpenAgSco()
{
BluetoothAudioImpl.Instance.OpenAgSco();
}
///
/// Closes a AG(Audio Gateway) SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously.
///
/// 6
/// http://tizen.org/feature/network.bluetooth
/// http://tizen.org/feature/network.bluetooth.audio.call
/// http://tizen.org/privilege/bluetooth.admin
/// Thrown when the Bluetooth is not supported.
/// Thrown when the method is failed with message.
[EditorBrowsable(EditorBrowsableState.Never)]
public static void CloseAgSco()
{
BluetoothAudioImpl.Instance.CloseAgSco();
}
///
/// A property to check whether an opened AG(Audio Gateway) SCO(Synchronous Connection Oriented link) exists or not.
///
/// 6
/// http://tizen.org/feature/network.bluetooth
/// http://tizen.org/feature/network.bluetooth.audio.call
[EditorBrowsable(EditorBrowsableState.Never)]
public static bool IsAgScoOpened
{
get
{
return BluetoothAudioImpl.Instance.IsAgScoOpened;
}
}
///
/// This event is called when the AG(Audio Gateway) SCO(Synchronous Connection Oriented link) state is changed.
///
/// 6
/// http://tizen.org/feature/network.bluetooth
/// http://tizen.org/feature/network.bluetooth.audio.call
[EditorBrowsable(EditorBrowsableState.Never)]
public static event EventHandler AgScoStateChanged
{
add
{
BluetoothAudioImpl.Instance.AgScoStateChanged += value;
}
remove
{
BluetoothAudioImpl.Instance.AgScoStateChanged -= value;
}
}
///
/// Notifies the state of AG(Audio Gateway) voice recognition to connected remote device.
///
/// The state of voice recognition. It is true if voice recognition state is enabled.
/// 6
/// http://tizen.org/feature/network.bluetooth
/// http://tizen.org/feature/network.bluetooth.audio.call
/// http://tizen.org/privilege/bluetooth.admin
/// Thrown when the Bluetooth is not supported.
/// Thrown when the method is failed with message.
[EditorBrowsable(EditorBrowsableState.Never)]
public static void NotifyAgVoiceRecognitionState(bool enable)
{
BluetoothAudioImpl.Instance.NotifyAgVoiceRecognitionState(enable);
}
}
}