1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 package com.android.bluetooth.bass_client;
18 
19 import android.bluetooth.le.ScanFilter;
20 import android.os.ParcelUuid;
21 import android.util.Log;
22 
23 import java.util.Arrays;
24 import java.util.List;
25 
26 /** Bass Utility functions */
27 class BassUtils {
28     private static final String TAG = "BassUtils";
29 
containUuid(List<ScanFilter> filters, ParcelUuid uuid)30     static boolean containUuid(List<ScanFilter> filters, ParcelUuid uuid) {
31         for (ScanFilter filter : filters) {
32             if (filter.getServiceUuid().equals(uuid)) {
33                 return true;
34             }
35         }
36         return false;
37     }
38 
parseBroadcastId(byte[] broadcastIdBytes)39     static int parseBroadcastId(byte[] broadcastIdBytes) {
40         int broadcastId;
41         broadcastId = (0x00FF0000 & (broadcastIdBytes[2] << 16));
42         broadcastId |= (0x0000FF00 & (broadcastIdBytes[1] << 8));
43         broadcastId |= (0x000000FF & broadcastIdBytes[0]);
44         return broadcastId;
45     }
46 
log(String msg)47     static void log(String msg) {
48         Log.d(TAG, msg);
49     }
50 
printByteArray(byte[] array)51     static void printByteArray(byte[] array) {
52         log("Entire byte Array as string: " + Arrays.toString(array));
53     }
54 
reverse(byte[] address)55     static void reverse(byte[] address) {
56         int len = address.length;
57         for (int i = 0; i < len / 2; ++i) {
58             byte b = address[i];
59             address[i] = address[len - 1 - i];
60             address[len - 1 - i] = b;
61         }
62     }
63 }
64