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 /** 27 * Bass Utility functions 28 */ 29 class BassUtils { 30 private static final String TAG = "BassUtils"; 31 containUuid(List<ScanFilter> filters, ParcelUuid uuid)32 static boolean containUuid(List<ScanFilter> filters, ParcelUuid uuid) { 33 for (ScanFilter filter: filters) { 34 if (filter.getServiceUuid().equals(uuid)) { 35 return true; 36 } 37 } 38 return false; 39 } 40 parseBroadcastId(byte[] broadcastIdBytes)41 static int parseBroadcastId(byte[] broadcastIdBytes) { 42 int broadcastId; 43 broadcastId = (0x00FF0000 & (broadcastIdBytes[2] << 16)); 44 broadcastId |= (0x0000FF00 & (broadcastIdBytes[1] << 8)); 45 broadcastId |= (0x000000FF & broadcastIdBytes[0]); 46 return broadcastId; 47 } 48 log(String msg)49 static void log(String msg) { 50 if (BassConstants.BASS_DBG) { 51 Log.d(TAG, msg); 52 } 53 } 54 printByteArray(byte[] array)55 static void printByteArray(byte[] array) { 56 log("Entire byte Array as string: " + Arrays.toString(array)); 57 log("printitng byte by bte"); 58 for (int i = 0; i < array.length; i++) { 59 log("array[" + i + "] :" + Byte.toUnsignedInt(array[i])); 60 } 61 } 62 reverse(byte[] address)63 static void reverse(byte[] address) { 64 int len = address.length; 65 for (int i = 0; i < len / 2; ++i) { 66 byte b = address[i]; 67 address[i] = address[len - 1 - i]; 68 address[len - 1 - i] = b; 69 } 70 } 71 } 72