1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/*
* Copyright 2021 The Android Open Source Project
*
* 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.
*/
package android.bluetooth;
import android.annotation.IntDef;
import android.content.Context;
import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
/**
* This class provides the public APIs to control the Bluetooth LE Broadcast Source profile.
*
* <p>BluetoothLeBroadcast is a proxy object for controlling the Bluetooth LE Broadcast
* Source Service via IPC. Use {@link BluetoothAdapter#getProfileProxy}
* to get the BluetoothLeBroadcast proxy object.
*
* @hide
*/
public final class BluetoothLeBroadcast implements BluetoothProfile {
private static final String TAG = "BluetoothLeBroadcast";
private static final boolean DBG = true;
private static final boolean VDBG = false;
/**
* Constants used by the LE Audio Broadcast profile for the Broadcast state
*
* @hide
*/
@IntDef(prefix = {"LE_AUDIO_BROADCAST_STATE_"}, value = {
LE_AUDIO_BROADCAST_STATE_DISABLED,
LE_AUDIO_BROADCAST_STATE_ENABLING,
LE_AUDIO_BROADCAST_STATE_ENABLED,
LE_AUDIO_BROADCAST_STATE_DISABLING,
LE_AUDIO_BROADCAST_STATE_PLAYING,
LE_AUDIO_BROADCAST_STATE_NOT_PLAYING
})
@Retention(RetentionPolicy.SOURCE)
public @interface LeAudioBroadcastState {}
/**
* Indicates that LE Audio Broadcast mode is currently disabled
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_STATE_DISABLED = 10;
/**
* Indicates that LE Audio Broadcast mode is being enabled
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_STATE_ENABLING = 11;
/**
* Indicates that LE Audio Broadcast mode is currently enabled
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_STATE_ENABLED = 12;
/**
* Indicates that LE Audio Broadcast mode is being disabled
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_STATE_DISABLING = 13;
/**
* Indicates that an LE Audio Broadcast mode is currently playing
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_STATE_PLAYING = 14;
/**
* Indicates that LE Audio Broadcast is currently not playing
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_STATE_NOT_PLAYING = 15;
/**
* Constants used by the LE Audio Broadcast profile for encryption key length
*
* @hide
*/
@IntDef(prefix = {"LE_AUDIO_BROADCAST_ENCRYPTION_KEY_"}, value = {
LE_AUDIO_BROADCAST_ENCRYPTION_KEY_32BIT,
LE_AUDIO_BROADCAST_ENCRYPTION_KEY_128BIT
})
@Retention(RetentionPolicy.SOURCE)
public @interface LeAudioEncryptionKeyLength {}
/**
* Indicates that the LE Audio Broadcast encryption key size is 32 bits.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_ENCRYPTION_KEY_32BIT = 16;
/**
* Indicates that the LE Audio Broadcast encryption key size is 128 bits.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_ENCRYPTION_KEY_128BIT = 17;
/**
* Interface for receiving events related to broadcasts
*/
public interface Callback {
/**
* Called when broadcast state has changed
*
* @param prevState broadcast state before the change
* @param newState broadcast state after the change
*/
@LeAudioBroadcastState
void onBroadcastStateChange(int prevState, int newState);
/**
* Called when encryption key has been updated
*
* @param success true if the key was updated successfully, false otherwise
*/
void onEncryptionKeySet(boolean success);
}
/**
* Create a BluetoothLeBroadcast proxy object for interacting with the local
* LE Audio Broadcast Source service.
*
* @hide
*/
/*package*/ BluetoothLeBroadcast(Context context,
BluetoothProfile.ServiceListener listener) {
}
/**
* Not supported since LE Audio Broadcasts do not establish a connection
*
* @throws UnsupportedOperationException
*
* @hide
*/
@Override
public int getConnectionState(BluetoothDevice device) {
throw new UnsupportedOperationException(
"LE Audio Broadcasts are not connection-oriented.");
}
/**
* Not supported since LE Audio Broadcasts do not establish a connection
*
* @throws UnsupportedOperationException
*
* @hide
*/
@Override
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
throw new UnsupportedOperationException(
"LE Audio Broadcasts are not connection-oriented.");
}
/**
* Not supported since LE Audio Broadcasts do not establish a connection
*
* @throws UnsupportedOperationException
*
* @hide
*/
@Override
public List<BluetoothDevice> getConnectedDevices() {
throw new UnsupportedOperationException(
"LE Audio Broadcasts are not connection-oriented.");
}
/**
* Enable LE Audio Broadcast mode.
*
* Generates a new broadcast ID and enables sending of encrypted or unencrypted
* isochronous PDUs
*
* @hide
*/
public int enableBroadcastMode() {
if (DBG) log("enableBroadcastMode");
return BluetoothStatusCodes.ERROR_LE_AUDIO_BROADCAST_SOURCE_SET_BROADCAST_MODE_FAILED;
}
/**
* Disable LE Audio Broadcast mode.
*
* @hide
*/
public int disableBroadcastMode() {
if (DBG) log("disableBroadcastMode");
return BluetoothStatusCodes.ERROR_LE_AUDIO_BROADCAST_SOURCE_SET_BROADCAST_MODE_FAILED;
}
/**
* Get the current LE Audio broadcast state
*
* @hide
*/
@LeAudioBroadcastState
public int getBroadcastState() {
if (DBG) log("getBroadcastState");
return LE_AUDIO_BROADCAST_STATE_DISABLED;
}
/**
* Enable LE Audio broadcast encryption
*
* @param keyLength if useExisting is true, this specifies the length of the key that should
* be generated
* @param useExisting true, if an existing key should be used
* false, if a new key should be generated
*
* @hide
*/
@LeAudioEncryptionKeyLength
public int enableEncryption(boolean useExisting, int keyLength) {
if (DBG) log("enableEncryption useExisting=" + useExisting + " keyLength=" + keyLength);
return BluetoothStatusCodes.ERROR_LE_AUDIO_BROADCAST_SOURCE_ENABLE_ENCRYPTION_FAILED;
}
/**
* Disable LE Audio broadcast encryption
*
* @param removeExisting true, if the existing key should be removed
* false, otherwise
*
* @hide
*/
public int disableEncryption(boolean removeExisting) {
if (DBG) log("disableEncryption removeExisting=" + removeExisting);
return BluetoothStatusCodes.ERROR_LE_AUDIO_BROADCAST_SOURCE_DISABLE_ENCRYPTION_FAILED;
}
/**
* Enable or disable LE Audio broadcast encryption
*
* @param key use the provided key if non-null, generate a new key if null
* @param keyLength 0 if encryption is disabled, 4 bytes (low security),
* 16 bytes (high security)
*
* @hide
*/
@LeAudioEncryptionKeyLength
public int setEncryptionKey(byte[] key, int keyLength) {
if (DBG) log("setEncryptionKey key=" + key + " keyLength=" + keyLength);
return BluetoothStatusCodes.ERROR_LE_AUDIO_BROADCAST_SOURCE_SET_ENCRYPTION_KEY_FAILED;
}
/**
* Get the encryption key that was set before
*
* @return encryption key as a byte array or null if no encryption key was set
*
* @hide
*/
public byte[] getEncryptionKey() {
if (DBG) log("getEncryptionKey");
return null;
}
private static void log(String msg) {
Log.d(TAG, msg);
}
}
|