1 /*
2  * Copyright (C) 2023 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 android.bluetooth;
18 
19 import static com.google.common.io.BaseEncoding.base16;
20 
21 import com.google.protobuf.ByteString;
22 
23 import java.util.Locale;
24 
25 public final class Utils {
26     // From bumble_config.json
27     public static final String BUMBLE_RANDOM_ADDRESS = "51:F7:A8:75:AC:5E";
28     public static final byte[] BUMBLE_IRK = base16().decode("1F66F4B5F0C742F807DD0DDBF64E9213");
29 
addressStringFromByteString(ByteString bs)30     public static String addressStringFromByteString(ByteString bs) {
31         StringBuilder refAddrBuilder = new StringBuilder();
32         for (int i = 0; i < bs.size(); i++) {
33             if (i != 0) {
34                 refAddrBuilder.append(':');
35             }
36             refAddrBuilder.append(String.format("%02X", bs.byteAt(i)));
37         }
38         return refAddrBuilder.toString();
39     }
40 
41     /**
42      * @param address String representing Bluetooth address (case insensitive).
43      * @return Decoded address.
44      */
addressBytesFromString(String address)45     public static byte[] addressBytesFromString(String address) {
46         return base16().upperCase().withSeparator(":", 2).decode(address.toUpperCase(Locale.US));
47     }
48 }
49