Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3cfde70 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Implement new API for retrieving supported Bluetooth profiles."

parents 3c64fdac 32921cc2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1142,6 +1142,12 @@ public class AdapterService extends Service {
            return service.isBondingInitiatedLocally(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;
@@ -1998,6 +2004,10 @@ public class AdapterService extends Service {
        return deviceProp.isBondingInitiatedLocally();
    }

    long getSupportedProfiles() {
        return Config.getSupportedProfilesBitMask();
    }

    int getConnectionState(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
+30 −11
Original line number Diff line number Diff line
@@ -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) {
@@ -136,16 +165,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;
    }
}