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.ComponentModel;
20 namespace Tizen.Network.Bluetooth
23 /// This class is used to handle the connection with other Bluetooth audio devices
24 /// like headset, hands-free, and headphone.
26 /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
27 /// <since_tizen> 3 </since_tizen>
28 public class BluetoothAudio : BluetoothProfile
30 internal BluetoothAudio()
35 /// The AudioConnectionStateChanged event is called when the audio connection state is changed.
37 /// <since_tizen> 3 </since_tizen>
38 public event EventHandler<AudioConnectionStateChangedEventArgs> AudioConnectionStateChanged
42 BluetoothAudioImpl.Instance.AudioConnectionStateChanged += value;
46 BluetoothAudioImpl.Instance.AudioConnectionStateChanged -= value;
51 /// Connects the remote device with the given audio profile.
54 /// The device must be bonded with the remote device by CreateBond(). If connection request succeeds, the AudioConnectionStateChanged event will be invoked.
55 /// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp <br/>
56 /// and AdvancedAudioDistribution is connected.
58 /// <param name="profileType">The type of the audio profile.</param>
59 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
60 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
61 /// or when the connection attempt fails.</exception>
62 /// <since_tizen> 3 </since_tizen>
63 public void Connect(BluetoothAudioProfileType profileType)
65 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
67 int ret = BluetoothAudioImpl.Instance.Connect(RemoteAddress, profileType);
68 if (ret != (int)BluetoothError.None)
70 Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
71 BluetoothErrorFactory.ThrowBluetoothException(ret);
76 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
81 /// Disconnects the remote device with the given audio profile.
84 /// The device must be connected by Connect(). If the disconnection request succeeds, the AudioConnectionStateChanged event will be invoked.
85 /// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp <br/>
86 /// and AdvancedAudioDistribution is disconnected.
88 /// <param name="type">The type of the audio profile.</param>
89 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
90 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
91 /// or when Disconnection attempt fails.</exception>
92 /// <since_tizen> 3 </since_tizen>
93 public void Disconnect(BluetoothAudioProfileType type)
95 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
97 int ret = BluetoothAudioImpl.Instance.Disconnect(RemoteAddress, type);
98 if (ret != (int)BluetoothError.None)
100 Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
101 BluetoothErrorFactory.ThrowBluetoothException(ret);
106 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
111 /// Opens a AG(Audio Gateway) SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously.
113 /// <since_tizen> 6 </since_tizen>
114 /// <feature>http://tizen.org/feature/network.bluetooth</feature>
115 /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
116 /// <privilege>http://tizen.org/privilege/bluetooth.admin</privilege>
117 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
118 /// <exception cref="InvalidOperationException">Thrown when the method is failed with message.</exception>
119 [EditorBrowsable(EditorBrowsableState.Never)]
120 public static void OpenAgSco()
122 BluetoothAudioImpl.Instance.OpenAgSco();
126 /// Closes a AG(Audio Gateway) SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously.
128 /// <since_tizen> 6 </since_tizen>
129 /// <feature>http://tizen.org/feature/network.bluetooth</feature>
130 /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
131 /// <privilege>http://tizen.org/privilege/bluetooth.admin</privilege>
132 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
133 /// <exception cref="InvalidOperationException">Thrown when the method is failed with message.</exception>
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public static void CloseAgSco()
137 BluetoothAudioImpl.Instance.CloseAgSco();
141 /// A property to check whether an opened AG(Audio Gateway) SCO(Synchronous Connection Oriented link) exists or not.
143 /// <since_tizen> 6 </since_tizen>
144 /// <feature>http://tizen.org/feature/network.bluetooth</feature>
145 /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 public static bool IsAgScoOpened
151 return BluetoothAudioImpl.Instance.IsAgScoOpened;
156 /// This event is called when the AG(Audio Gateway) SCO(Synchronous Connection Oriented link) state is changed.
158 /// <since_tizen> 6 </since_tizen>
159 /// <feature>http://tizen.org/feature/network.bluetooth</feature>
160 /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public static event EventHandler<AgScoStateChangedEventArgs> AgScoStateChanged
166 BluetoothAudioImpl.Instance.AgScoStateChanged += value;
170 BluetoothAudioImpl.Instance.AgScoStateChanged -= value;
175 /// Notifies the state of AG(Audio Gateway) voice recognition to connected remote device.
177 /// <param name="enable">The state of voice recognition. It is true if voice recognition state is enabled.</param>
178 /// <since_tizen> 6 </since_tizen>
179 /// <feature>http://tizen.org/feature/network.bluetooth</feature>
180 /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
181 /// <privilege>http://tizen.org/privilege/bluetooth.admin</privilege>
182 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
183 /// <exception cref="InvalidOperationException">Thrown when the method is failed with message.</exception>
184 [EditorBrowsable(EditorBrowsableState.Never)]
185 public static void NotifyAgVoiceRecognitionState(bool enable)
187 BluetoothAudioImpl.Instance.NotifyAgVoiceRecognitionState(enable);