1 /* 2 * Copyright (C) 2016 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.util; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 /** 23 * Centralized Bluetooth Interoperability workaround utilities and database. 24 * This is the Java version. An analagous native version can be found 25 * in /system/bt/devices/include/interop_database.h. 26 */ 27 public class Interop { 28 29 /** 30 * Simple interop entry consisting of a workarond id (see below) 31 * and a (partial or complete) Bluetooth device address string 32 * to match against. 33 */ 34 private static class Entry { 35 public String address; 36 public int workaround_id; 37 Entry(int workaroundId, String address)38 Entry(int workaroundId, String address) { 39 this.workaround_id = workaroundId; 40 this.address = address; 41 } 42 } 43 44 /** 45 * The actual "database" of interop entries. 46 */ 47 private static List<Entry> sEntries = null; 48 49 /** 50 * Workaround ID for deivces which do not accept non-ASCII 51 * characters in SMS messages. 52 */ 53 public static final int INTEROP_MAP_ASCIIONLY = 1; 54 55 /** 56 * Initializes the interop datbase with the relevant workaround 57 * entries. 58 * When adding entries, please provide a description for each 59 * device as to what problem the workaround addresses. 60 */ lazyInitInteropDatabase()61 private static void lazyInitInteropDatabase() { 62 if (sEntries != null) { 63 return; 64 } 65 sEntries = new ArrayList<Entry>(); 66 67 /** Mercedes Benz NTG 4.5 does not handle non-ASCII characters in SMS */ 68 sEntries.add(new Entry(INTEROP_MAP_ASCIIONLY, "00:26:e8")); 69 } 70 71 /** 72 * Checks wheter a given device identified by |address| is a match 73 * for a given workaround identified by |workaroundId|. 74 * Return true if the address matches, false otherwise. 75 */ matchByAddress(int workaroundId, String address)76 public static boolean matchByAddress(int workaroundId, String address) { 77 if (address == null || address.isEmpty()) { 78 return false; 79 } 80 81 lazyInitInteropDatabase(); 82 for (Entry entry : sEntries) { 83 if (entry.workaround_id == workaroundId && entry.address.startsWith( 84 address.toLowerCase())) { 85 return true; 86 } 87 } 88 89 return false; 90 } 91 } 92