diff options
author | Bryce Lee <brycelee@google.com> | 2016-10-09 12:58:54 -0700 |
---|---|---|
committer | Bryce Lee <brycelee@google.com> | 2016-10-09 12:58:54 -0700 |
commit | b7e2f972a0633b4d8c8843d025819d61e71053e7 (patch) | |
tree | 04f061c7ee65d0b1dd3626f200c3ac3cf3af0c04 | |
parent | e891e195514684ca3ab370dcc00b8a5084e1e1c8 (diff) | |
download | android_packages_apps_Bluetooth-b7e2f972a0633b4d8c8843d025819d61e71053e7.tar.gz android_packages_apps_Bluetooth-b7e2f972a0633b4d8c8843d025819d61e71053e7.tar.bz2 android_packages_apps_Bluetooth-b7e2f972a0633b4d8c8843d025819d61e71053e7.zip |
Implement new API for retrieving supported Bluetooth profiles.
Bug: 26451648
Change-Id: I552882034e0289b643377d14bac4fb01c9018046
-rw-r--r-- | src/com/android/bluetooth/btservice/AdapterService.java | 10 | ||||
-rw-r--r-- | src/com/android/bluetooth/btservice/Config.java | 41 |
2 files changed, 40 insertions, 11 deletions
diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index c0e70ac59..544b23c4c 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -1126,6 +1126,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; @@ -1905,6 +1911,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()); diff --git a/src/com/android/bluetooth/btservice/Config.java b/src/com/android/bluetooth/btservice/Config.java index 7a9de21da..1c451de77 100644 --- a/src/com/android/bluetooth/btservice/Config.java +++ b/src/com/android/bluetooth/btservice/Config.java @@ -108,7 +108,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) { @@ -137,16 +166,6 @@ public class Config { profileIndex = BluetoothProfile.PBAP_CLIENT; } - 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; } } |