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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
|
/*
* 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.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* This class represents an LE Audio Broadcast Source and the associated information that is needed
* by Broadcast Audio Scan Service (BASS) residing on a Scan Delegator.
*
* <p>For example, the Scan Delegator on an LE Audio Broadcast Sink can use the information
* contained within an instance of this class to synchronize with an LE Audio Broadcast Source in
* order to listen to a Broadcast Audio Stream.
*
* <p>BroadcastAssistant has a BASS client which facilitates scanning and discovery of Broadcast
* Sources on behalf of say a Broadcast Sink. Upon successful discovery of one or more Broadcast
* sources, this information needs to be communicated to the BASS Server residing within the Scan
* Delegator on a Broadcast Sink. This is achieved using the Periodic Advertising Synchronization
* Transfer (PAST) procedure. This procedure uses information contained within an instance of this
* class.
*
* @hide
*/
public final class BluetoothLeBroadcastSourceInfo implements Parcelable {
private static final String TAG = "BluetoothLeBroadcastSourceInfo";
private static final boolean DBG = true;
/**
* Constants representing Broadcast Source address types
*
* @hide
*/
@IntDef(
prefix = "LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_",
value = {
LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_PUBLIC,
LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_RANDOM,
LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_INVALID
})
@Retention(RetentionPolicy.SOURCE)
public @interface LeAudioBroadcastSourceAddressType {}
/**
* Represents a public address used by an LE Audio Broadcast Source
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_PUBLIC = 0;
/**
* Represents a random address used by an LE Audio Broadcast Source
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_RANDOM = 1;
/**
* Represents an invalid address used by an LE Audio Broadcast Seurce
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_INVALID = 0xFFFF;
/**
* Periodic Advertising Synchronization state
*
* <p>Periodic Advertising (PA) enables the LE Audio Broadcast Assistant to discover broadcast
* audio streams as well as the audio stream configuration on behalf of an LE Audio Broadcast
* Sink. This information can then be transferred to the LE Audio Broadcast Sink using the
* Periodic Advertising Synchronizaton Transfer (PAST) procedure.
*
* @hide
*/
@IntDef(
prefix = "LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_",
value = {
LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_IDLE,
LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_SYNCINFO_REQ,
LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_IN_SYNC,
LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_SYNC_FAIL,
LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_NO_PAST
})
@Retention(RetentionPolicy.SOURCE)
public @interface LeAudioBroadcastSinkPaSyncState {}
/**
* Indicates that the Broadcast Sink is not synchronized with the Periodic Advertisements (PA)
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_IDLE = 0;
/**
* Indicates that the Broadcast Sink requested the Broadcast Assistant to synchronize with the
* Periodic Advertisements (PA).
*
* <p>This is also known as scan delegation or scan offloading.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_SYNCINFO_REQ = 1;
/**
* Indicates that the Broadcast Sink is synchronized with the Periodic Advertisements (PA).
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_IN_SYNC = 2;
/**
* Indicates that the Broadcast Sink was unable to synchronize with the Periodic Advertisements
* (PA).
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_SYNC_FAIL = 3;
/**
* Indicates that the Broadcast Sink should be synchronized with the Periodic Advertisements
* (PA) using the Periodic Advertisements Synchronization Transfert (PAST) procedure.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_NO_PAST = 4;
/**
* Indicates that the Broadcast Sink synchornization state is invalid.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_INVALID = 0xFFFF;
/** @hide */
@IntDef(
prefix = "LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_",
value = {
LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_NOT_SYNCHRONIZED,
LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_SYNCHRONIZED
})
@Retention(RetentionPolicy.SOURCE)
public @interface LeAudioBroadcastSinkAudioSyncState {}
/**
* Indicates that the Broadcast Sink is not synchronized with a Broadcast Audio Stream.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_NOT_SYNCHRONIZED = 0;
/**
* Indicates that the Broadcast Sink is synchronized with a Broadcast Audio Stream.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_SYNCHRONIZED = 1;
/**
* Indicates that the Broadcast Sink audio synchronization state is invalid.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_INVALID = 0xFFFF;
/** @hide */
@IntDef(
prefix = "LE_AUDIO_BROADCAST_SINK_ENC_STATE_",
value = {
LE_AUDIO_BROADCAST_SINK_ENC_STATE_NOT_ENCRYPTED,
LE_AUDIO_BROADCAST_SINK_ENC_STATE_CODE_REQUIRED,
LE_AUDIO_BROADCAST_SINK_ENC_STATE_DECRYPTING,
LE_AUDIO_BROADCAST_SINK_ENC_STATE_BAD_CODE
})
@Retention(RetentionPolicy.SOURCE)
public @interface LeAudioBroadcastSinkEncryptionState {}
/**
* Indicates that the Broadcast Sink is synchronized with an unencrypted audio stream.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_ENC_STATE_NOT_ENCRYPTED = 0;
/**
* Indicates that the Broadcast Sink needs a Broadcast Code to synchronize with the audio
* stream.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_ENC_STATE_CODE_REQUIRED = 1;
/**
* Indicates that the Broadcast Sink is synchronized with an encrypted audio stream.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_ENC_STATE_DECRYPTING = 2;
/**
* Indicates that the Broadcast Sink is unable to decrypt an audio stream due to an incorrect
* Broadcast Code
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_ENC_STATE_BAD_CODE = 3;
/**
* Indicates that the Broadcast Sink encryption state is invalid.
*
* @hide
*/
public static final int LE_AUDIO_BROADCAST_SINK_ENC_STATE_INVALID = 0xFF;
/**
* Represents an invalid LE Audio Broadcast Source ID
*
* @hide
*/
public static final byte LE_AUDIO_BROADCAST_SINK_INVALID_SOURCE_ID = (byte) 0x00;
/**
* Represents an invalid Broadcast ID of a Broadcast Source
*
* @hide
*/
public static final int INVALID_BROADCAST_ID = 0xFFFFFF;
private byte mSourceId;
private @LeAudioBroadcastSourceAddressType int mSourceAddressType;
private BluetoothDevice mSourceDevice;
private byte mSourceAdvSid;
private int mBroadcastId;
private @LeAudioBroadcastSinkPaSyncState int mPaSyncState;
private @LeAudioBroadcastSinkEncryptionState int mEncryptionStatus;
private @LeAudioBroadcastSinkAudioSyncState int mAudioSyncState;
private byte[] mBadBroadcastCode;
private byte mNumSubGroups;
private Map<Integer, Integer> mSubgroupBisSyncState = new HashMap<Integer, Integer>();
private Map<Integer, byte[]> mSubgroupMetadata = new HashMap<Integer, byte[]>();
private String mBroadcastCode;
private static final int BIS_NO_PREF = 0xFFFFFFFF;
private static final int BROADCAST_CODE_SIZE = 16;
/**
* Constructor to create an Empty object of {@link BluetoothLeBroadcastSourceInfo } with the
* given Source Id.
*
* <p>This is mainly used to represent the Empty Broadcast Source entries
*
* @param sourceId Source Id for this Broadcast Source info object
* @hide
*/
public BluetoothLeBroadcastSourceInfo(byte sourceId) {
mSourceId = sourceId;
mSourceAddressType = LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_INVALID;
mSourceDevice = null;
mSourceAdvSid = (byte) 0x00;
mBroadcastId = INVALID_BROADCAST_ID;
mPaSyncState = LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_INVALID;
mAudioSyncState = LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_INVALID;
mEncryptionStatus = LE_AUDIO_BROADCAST_SINK_ENC_STATE_INVALID;
mBadBroadcastCode = null;
mNumSubGroups = 0;
mBroadcastCode = null;
}
/*package*/ BluetoothLeBroadcastSourceInfo(
byte sourceId,
@LeAudioBroadcastSourceAddressType int addressType,
@NonNull BluetoothDevice device,
byte advSid,
int broadcastId,
@LeAudioBroadcastSinkPaSyncState int paSyncstate,
@LeAudioBroadcastSinkEncryptionState int encryptionStatus,
@LeAudioBroadcastSinkAudioSyncState int audioSyncstate,
@Nullable byte[] badCode,
byte numSubGroups,
@NonNull Map<Integer, Integer> bisSyncState,
@Nullable Map<Integer, byte[]> subgroupMetadata,
@NonNull String broadcastCode) {
mSourceId = sourceId;
mSourceAddressType = addressType;
mSourceDevice = device;
mSourceAdvSid = advSid;
mBroadcastId = broadcastId;
mPaSyncState = paSyncstate;
mEncryptionStatus = encryptionStatus;
mAudioSyncState = audioSyncstate;
if (badCode != null && badCode.length != 0) {
mBadBroadcastCode = new byte[badCode.length];
System.arraycopy(badCode, 0, mBadBroadcastCode, 0, badCode.length);
}
mNumSubGroups = numSubGroups;
mSubgroupBisSyncState = new HashMap<Integer, Integer>(bisSyncState);
mSubgroupMetadata = new HashMap<Integer, byte[]>(subgroupMetadata);
mBroadcastCode = broadcastCode;
}
@Override
public boolean equals(Object o) {
if (o instanceof BluetoothLeBroadcastSourceInfo) {
BluetoothLeBroadcastSourceInfo other = (BluetoothLeBroadcastSourceInfo) o;
return (other.mSourceId == mSourceId
&& other.mSourceAddressType == mSourceAddressType
&& other.mSourceDevice == mSourceDevice
&& other.mSourceAdvSid == mSourceAdvSid
&& other.mBroadcastId == mBroadcastId
&& other.mPaSyncState == mPaSyncState
&& other.mEncryptionStatus == mEncryptionStatus
&& other.mAudioSyncState == mAudioSyncState
&& Arrays.equals(other.mBadBroadcastCode, mBadBroadcastCode)
&& other.mNumSubGroups == mNumSubGroups
&& mSubgroupBisSyncState.equals(other.mSubgroupBisSyncState)
&& mSubgroupMetadata.equals(other.mSubgroupMetadata)
&& other.mBroadcastCode == mBroadcastCode);
}
return false;
}
/**
* Checks if an instance of {@link BluetoothLeBroadcastSourceInfo} is empty.
*
* @hide
*/
public boolean isEmpty() {
boolean ret = false;
if (mSourceAddressType == LE_AUDIO_BROADCAST_SOURCE_ADDRESS_TYPE_INVALID
&& mSourceDevice == null
&& mSourceAdvSid == (byte) 0
&& mPaSyncState == LE_AUDIO_BROADCAST_SINK_PA_SYNC_STATE_INVALID
&& mEncryptionStatus == LE_AUDIO_BROADCAST_SINK_ENC_STATE_INVALID
&& mAudioSyncState == LE_AUDIO_BROADCAST_SINK_AUDIO_SYNC_STATE_INVALID
&& mBadBroadcastCode == null
&& mNumSubGroups == 0
&& mSubgroupBisSyncState.size() == 0
&& mSubgroupMetadata.size() == 0
&& mBroadcastCode == null) {
ret = true;
}
return ret;
}
/**
* Compares an instance of {@link BluetoothLeBroadcastSourceInfo} with the provided instance.
*
* @hide
*/
public boolean matches(BluetoothLeBroadcastSourceInfo srcInfo) {
boolean ret = false;
if (srcInfo == null) {
ret = false;
} else {
if (mSourceDevice == null) {
if (mSourceAdvSid == srcInfo.getAdvertisingSid()
&& mSourceAddressType == srcInfo.getAdvAddressType()) {
ret = true;
}
} else {
if (mSourceDevice.equals(srcInfo.getSourceDevice())
&& mSourceAdvSid == srcInfo.getAdvertisingSid()
&& mSourceAddressType == srcInfo.getAdvAddressType()
&& mBroadcastId == srcInfo.getBroadcastId()) {
ret = true;
}
}
}
return ret;
}
@Override
public int hashCode() {
return Objects.hash(
mSourceId,
mSourceAddressType,
mSourceDevice,
mSourceAdvSid,
mBroadcastId,
mPaSyncState,
mEncryptionStatus,
mAudioSyncState,
mBadBroadcastCode,
mNumSubGroups,
mSubgroupBisSyncState,
mSubgroupMetadata,
mBroadcastCode);
}
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
return "{BluetoothLeBroadcastSourceInfo : mSourceId"
+ mSourceId
+ " addressType: "
+ mSourceAddressType
+ " sourceDevice: "
+ mSourceDevice
+ " mSourceAdvSid:"
+ mSourceAdvSid
+ " mBroadcastId:"
+ mBroadcastId
+ " mPaSyncState:"
+ mPaSyncState
+ " mEncryptionStatus:"
+ mEncryptionStatus
+ " mAudioSyncState:"
+ mAudioSyncState
+ " mBadBroadcastCode:"
+ mBadBroadcastCode
+ " mNumSubGroups:"
+ mNumSubGroups
+ " mSubgroupBisSyncState:"
+ mSubgroupBisSyncState
+ " mSubgroupMetadata:"
+ mSubgroupMetadata
+ " mBroadcastCode:"
+ mBroadcastCode
+ "}";
}
/**
* Get the Source Id
*
* @return byte representing the Source Id, {@link
* #LE_AUDIO_BROADCAST_ASSISTANT_INVALID_SOURCE_ID} if invalid
* @hide
*/
public byte getSourceId() {
return mSourceId;
}
/**
* Set the Source Id
*
* @param sourceId source Id
* @hide
*/
public void setSourceId(byte sourceId) {
mSourceId = sourceId;
}
/**
* Set the Broadcast Source device
*
* @param sourceDevice the Broadcast Source BluetoothDevice
* @hide
*/
public void setSourceDevice(@NonNull BluetoothDevice sourceDevice) {
mSourceDevice = sourceDevice;
}
/**
* Get the Broadcast Source BluetoothDevice
*
* @return Broadcast Source BluetoothDevice
* @hide
*/
public @NonNull BluetoothDevice getSourceDevice() {
return mSourceDevice;
}
/**
* Set the address type of the Broadcast Source advertisements
*
* @hide
*/
public void setAdvAddressType(@LeAudioBroadcastSourceAddressType int addressType) {
mSourceAddressType = addressType;
}
/**
* Get the address type used by advertisements from the Broadcast Source.
* BluetoothLeBroadcastSourceInfo Object
*
* @hide
*/
@LeAudioBroadcastSourceAddressType
public int getAdvAddressType() {
return mSourceAddressType;
}
/**
* Set the advertising SID of the Broadcast Source advertisement.
*
* @param advSid advertising SID of the Broadcast Source
* @hide
*/
public void setAdvertisingSid(byte advSid) {
mSourceAdvSid = advSid;
}
/**
* Get the advertising SID of the Broadcast Source advertisement.
*
* @return advertising SID of the Broadcast Source
* @hide
*/
public byte getAdvertisingSid() {
return mSourceAdvSid;
}
/**
* Get the Broadcast ID of the Broadcast Source.
*
* @return broadcast ID
* @hide
*/
public int getBroadcastId() {
return mBroadcastId;
}
/**
* Set the Periodic Advertising (PA) Sync State.
*
* @hide
*/
/*package*/ void setPaSyncState(@LeAudioBroadcastSinkPaSyncState int paSyncState) {
mPaSyncState = paSyncState;
}
/**
* Get the Periodic Advertising (PA) Sync State
*
* @hide
*/
public @LeAudioBroadcastSinkPaSyncState int getMetadataSyncState() {
return mPaSyncState;
}
/**
* Set the audio sync state
*
* @hide
*/
/*package*/ void setAudioSyncState(@LeAudioBroadcastSinkAudioSyncState int audioSyncState) {
mAudioSyncState = audioSyncState;
}
/**
* Get the audio sync state
*
* @hide
*/
public @LeAudioBroadcastSinkAudioSyncState int getAudioSyncState() {
return mAudioSyncState;
}
/**
* Set the encryption status
*
* @hide
*/
/*package*/ void setEncryptionStatus(
@LeAudioBroadcastSinkEncryptionState int encryptionStatus) {
mEncryptionStatus = encryptionStatus;
}
/**
* Get the encryption status
*
* @hide
*/
public @LeAudioBroadcastSinkEncryptionState int getEncryptionStatus() {
return mEncryptionStatus;
}
/**
* Get the incorrect broadcast code that the Scan delegator used to decrypt the Broadcast Audio
* Stream and failed.
*
* <p>This code is valid only if {@link #getEncryptionStatus} returns {@link
* #LE_AUDIO_BROADCAST_SINK_ENC_STATE_BAD_CODE}
*
* @return byte array containing bad broadcast value, null if the current encryption status is
* not {@link #LE_AUDIO_BROADCAST_SINK_ENC_STATE_BAD_CODE}
* @hide
*/
public @Nullable byte[] getBadBroadcastCode() {
return mBadBroadcastCode;
}
/**
* Get the number of subgroups.
*
* @return number of subgroups
* @hide
*/
public byte getNumberOfSubGroups() {
return mNumSubGroups;
}
public @NonNull Map<Integer, Integer> getSubgroupBisSyncState() {
return mSubgroupBisSyncState;
}
public void setSubgroupBisSyncState(@NonNull Map<Integer, Integer> bisSyncState) {
mSubgroupBisSyncState = new HashMap<Integer, Integer>(bisSyncState);
}
/*package*/ void setBroadcastCode(@NonNull String broadcastCode) {
mBroadcastCode = broadcastCode;
}
/**
* Get the broadcast code
*
* @return
* @hide
*/
public @NonNull String getBroadcastCode() {
return mBroadcastCode;
}
/**
* Set the broadcast ID
*
* @param broadcastId broadcast ID of the Broadcast Source
* @hide
*/
public void setBroadcastId(int broadcastId) {
mBroadcastId = broadcastId;
}
private void writeSubgroupBisSyncStateToParcel(
@NonNull Parcel dest, @NonNull Map<Integer, Integer> subgroupBisSyncState) {
dest.writeInt(subgroupBisSyncState.size());
for (Map.Entry<Integer, Integer> entry : subgroupBisSyncState.entrySet()) {
dest.writeInt(entry.getKey());
dest.writeInt(entry.getValue());
}
}
private static void readSubgroupBisSyncStateFromParcel(
@NonNull Parcel in, @NonNull Map<Integer, Integer> subgroupBisSyncState) {
int size = in.readInt();
for (int i = 0; i < size; i++) {
Integer key = in.readInt();
Integer value = in.readInt();
subgroupBisSyncState.put(key, value);
}
}
private void writeSubgroupMetadataToParcel(
@NonNull Parcel dest, @Nullable Map<Integer, byte[]> subgroupMetadata) {
if (subgroupMetadata == null) {
dest.writeInt(0);
return;
}
dest.writeInt(subgroupMetadata.size());
for (Map.Entry<Integer, byte[]> entry : subgroupMetadata.entrySet()) {
dest.writeInt(entry.getKey());
byte[] metadata = entry.getValue();
if (metadata != null) {
dest.writeInt(metadata.length);
dest.writeByteArray(metadata);
}
}
}
private static void readSubgroupMetadataFromParcel(
@NonNull Parcel in, @NonNull Map<Integer, byte[]> subgroupMetadata) {
int size = in.readInt();
for (int i = 0; i < size; i++) {
Integer key = in.readInt();
Integer metaDataLen = in.readInt();
byte[] metadata = null;
if (metaDataLen != 0) {
metadata = new byte[metaDataLen];
in.readByteArray(metadata);
}
subgroupMetadata.put(key, metadata);
}
}
public static final @NonNull Parcelable.Creator<BluetoothLeBroadcastSourceInfo> CREATOR =
new Parcelable.Creator<BluetoothLeBroadcastSourceInfo>() {
public @NonNull BluetoothLeBroadcastSourceInfo createFromParcel(
@NonNull Parcel in) {
final byte sourceId = in.readByte();
final int sourceAddressType = in.readInt();
final BluetoothDevice sourceDevice =
in.readTypedObject(BluetoothDevice.CREATOR);
final byte sourceAdvSid = in.readByte();
final int broadcastId = in.readInt();
final int paSyncState = in.readInt();
final int audioSyncState = in.readInt();
final int encryptionStatus = in.readInt();
final int badBroadcastLen = in.readInt();
byte[] badBroadcastCode = null;
if (badBroadcastLen > 0) {
badBroadcastCode = new byte[badBroadcastLen];
in.readByteArray(badBroadcastCode);
}
final byte numSubGroups = in.readByte();
final String broadcastCode = in.readString();
Map<Integer, Integer> subgroupBisSyncState = new HashMap<Integer, Integer>();
readSubgroupBisSyncStateFromParcel(in, subgroupBisSyncState);
Map<Integer, byte[]> subgroupMetadata = new HashMap<Integer, byte[]>();
readSubgroupMetadataFromParcel(in, subgroupMetadata);
BluetoothLeBroadcastSourceInfo srcInfo =
new BluetoothLeBroadcastSourceInfo(
sourceId,
sourceAddressType,
sourceDevice,
sourceAdvSid,
broadcastId,
paSyncState,
encryptionStatus,
audioSyncState,
badBroadcastCode,
numSubGroups,
subgroupBisSyncState,
subgroupMetadata,
broadcastCode);
return srcInfo;
}
public @NonNull BluetoothLeBroadcastSourceInfo[] newArray(int size) {
return new BluetoothLeBroadcastSourceInfo[size];
}
};
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeByte(mSourceId);
out.writeInt(mSourceAddressType);
out.writeTypedObject(mSourceDevice, 0);
out.writeByte(mSourceAdvSid);
out.writeInt(mBroadcastId);
out.writeInt(mPaSyncState);
out.writeInt(mAudioSyncState);
out.writeInt(mEncryptionStatus);
if (mBadBroadcastCode != null) {
out.writeInt(mBadBroadcastCode.length);
out.writeByteArray(mBadBroadcastCode);
} else {
// zero indicates that there is no "bad broadcast code"
out.writeInt(0);
}
out.writeByte(mNumSubGroups);
out.writeString(mBroadcastCode);
writeSubgroupBisSyncStateToParcel(out, mSubgroupBisSyncState);
writeSubgroupMetadataToParcel(out, mSubgroupMetadata);
}
private static void log(@NonNull String msg) {
if (DBG) {
Log.d(TAG, msg);
}
}
}
;
|