• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.bluetooth.btservice;
17 
18 import java.io.File;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 
22 /** Class to generate a medical device bloomfilter */
23 public class MedicalDeviceBloomfilterGenerator {
24 
25     public static final String BLOOM_FILTER_DEFAULT =
26             "01070000003C01002106584044800850055"
27                     + "002308488410020D9A00001138410510000"
28                     + "000042004200000000000C2000000040064"
29                     + "0120080020110412A500090520210040C40"
30                     + "4002601040005004400148414006198A041"
31                     + "00890000600400000800210041810600800"
32                     + "0142208000721A030000028102448201110"
33                     + "0002007120020101448C211490A2B000084"
34                     + "C010004004C00C080808200026210608110"
35                     + "200011200000015000000212C4400040802"
36                     + "00111114840000001002080040186000404"
37                     + "81C064400052381109017039900000200C9"
38                     + "C0002E6480000101C40000601064001A018"
39                     + "40440280A810001000040455A0404617034"
40                     + "50000140040D020020C6204100804041600"
41                     + "80840002000800804280028000440000122"
42                     + "00808409905022000590000110448080400"
43                     + "561004210020430092602000040C0090C00"
44                     + "C18480020000519C1482100111011120390"
45                     + "02C0000228208104800C050440000004040"
46                     + "00871400882400140080000005308124900"
47                     + "104000040002410508CA349000200000202"
48                     + "90200920181890100800110220A20874820"
49                     + "0428080054A0005101C0820060090080040"
50                     + "6820C480F40081014010201800000018101"
51                     + "208914100321008006520002030010800C4"
52                     + "1022C000048206002010041220000008021"
53                     + "002080314040000100030002008";
54 
55     /** Provide byte[] version of a given string */
hexStringToByteArray(String s)56     public static byte[] hexStringToByteArray(String s) {
57         int len = s.length();
58         byte[] data = new byte[len / 2];
59         for (int i = 0; i < len; i += 2) {
60             data[i / 2] =
61                     (byte)
62                             ((Character.digit(s.charAt(i), 16) << 4)
63                                     + Character.digit(s.charAt(i + 1), 16));
64         }
65         return data;
66     }
67 
68     /** Generate bloom filter file given filePath */
generateDefaultBloomfilter(String filePath)69     public static void generateDefaultBloomfilter(String filePath) throws IOException {
70         File outputFile = new File(filePath);
71         outputFile.createNewFile(); // if file already exists will do nothing
72         FileOutputStream fos = new FileOutputStream(filePath);
73         fos.write(hexStringToByteArray(BLOOM_FILTER_DEFAULT));
74         fos.close();
75     }
76 }
77