OSDN Git Service

DO NOT MERGE ANYWHERE Implement new API for retrieving supported Bluetooth profiles.
authorBryce Lee <brycelee@google.com>
Mon, 29 Feb 2016 22:58:49 +0000 (14:58 -0800)
committerBryce Lee <brycelee@google.com>
Mon, 29 Feb 2016 22:58:49 +0000 (14:58 -0800)
Bug: 26451648
Change-Id: Ice55556d64208656824d5a6f9b90230d17f0c3bc

src/com/android/bluetooth/btservice/AdapterService.java
src/com/android/bluetooth/btservice/Config.java

index ac72282..6380286 100644 (file)
@@ -1038,6 +1038,12 @@ public class AdapterService extends Service {
             return service.getBondState(device);
         }
 
+        public long getSupportedProfiles() {
+            AdapterService service = getService();
+            if (service == null) return 0;
+            return service.getSupportedProfiles();
+        }
+
         public int getConnectionState(BluetoothDevice device) {
             AdapterService service = getService();
             if (service == null) return 0;
@@ -1681,6 +1687,10 @@ public class AdapterService extends Service {
         return deviceProp.getBondState();
     }
 
+    long getSupportedProfiles() {
+        return Config.getSupportedProfilesBitMask();
+    }
+
     int getConnectionState(BluetoothDevice device) {
         enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
         byte[] addr = Utils.getBytesFromAddress(device.getAddress());
index 0fc4718..6bfb098 100644 (file)
@@ -107,7 +107,36 @@ public class Config {
         return SUPPORTED_PROFILES;
     }
 
+    static long getSupportedProfilesBitMask() {
+        long mask = 0;
+        for (final Class profileClass : getSupportedProfiles()) {
+            final int profileIndex = getProfileIndex(profileClass);
+
+            if (profileIndex != -1) {
+                mask |= 1 << getProfileIndex(profileClass);
+            }
+        }
+
+        return mask;
+    }
+
     private static boolean isProfileDisabled(Context context, Class profile) {
+        final int profileIndex = getProfileIndex(profile);
+
+        if (profileIndex == -1) {
+            Log.w(TAG, "Could not find profile bit mask");
+            return false;
+        }
+
+        final ContentResolver resolver = context.getContentResolver();
+        final long disabledProfilesBitMask = Settings.Global.getLong(resolver,
+                Settings.Global.BLUETOOTH_DISABLED_PROFILES, 0);
+        final long profileBit = 1 << profileIndex;
+
+        return (disabledProfilesBitMask & profileBit) != 0;
+    }
+
+    private static int getProfileIndex(Class profile) {
         int profileIndex = -1;
 
         if (profile == HeadsetService.class) {
@@ -134,16 +163,6 @@ public class Config {
             profileIndex = BluetoothProfile.SAP;
         }
 
-        if (profileIndex == -1) {
-            Log.d(TAG, "Could not find profile bit mask");
-            return false;
-        }
-
-        final ContentResolver resolver = context.getContentResolver();
-        final long disabledProfilesBitMask = Settings.Global.getLong(resolver,
-                Settings.Global.BLUETOOTH_DISABLED_PROFILES, 0);
-        long profileBit = 1 << profileIndex;
-
-        return (disabledProfilesBitMask & profileBit) != 0;
+        return profileIndex;
     }
 }