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

Commit 651c91d4 authored by Alice Kuo's avatar Alice Kuo Committed by Automerger Merge Worker
Browse files

Merge "connectAllSupportedProfile as all connection policy are set to UNKNOWN" am: 5eae43a1

parents bae8051e 5eae43a1
Loading
Loading
Loading
Loading
+68 −54
Original line number Diff line number Diff line
@@ -1420,72 +1420,73 @@ public class AdapterService extends Service {
    }

    /**
     * Checks if any profile is enabled for the given device
     * Checks if the connectino policy of all profiles are unknown for the given device
     *
     * @param device is the device for which we are checking if any profiles are enabled
     * @return true if any profile is enabled, false otherwise
     * @param device is the device for which we are checking if the connection policy of
     * all profiles are unknown
     * @return false if one of profile is enabled or disabled, true otherwise
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    boolean isAnyProfileEnabled(BluetoothDevice device) {
    boolean checkifAllProfilesAreUnknown(BluetoothDevice device) {
        if (mA2dpService != null && mA2dpService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mA2dpSinkService != null && mA2dpSinkService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mHeadsetService != null && mHeadsetService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mHeadsetClientService != null && mHeadsetClientService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mMapClientService != null && mMapClientService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mHidHostService != null && mHidHostService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mPanService != null && mPanService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mPbapClientService != null && mPbapClientService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mHearingAidService != null && mHearingAidService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mHapClientService != null && mHapClientService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mVolumeControlService != null && mVolumeControlService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mCsipSetCoordinatorService != null
                && mCsipSetCoordinatorService.getConnectionPolicy(device)
                        > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                        != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mLeAudioService != null && mLeAudioService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
                != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        if (mBassClientService != null && mBassClientService.getConnectionPolicy(device)
                 > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            return true;
        }
                 != BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
            return false;
        }
        return true;
    }

    /**
     * Connects only available profiles
@@ -5637,62 +5638,77 @@ public class AdapterService extends Service {
            return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED;
        }

        // Checks if any profiles are enabled and if so, only connect enabled profiles
        if (isAnyProfileEnabled(device)) {
        // Checks if any profiles are enablde or disabled and if so, only connect enabled profiles
        if (!checkifAllProfilesAreUnknown(device)) {
            return connectEnabledProfiles(device);
        }

        connectAllSupportedProfiles(device);

        return BluetoothStatusCodes.SUCCESS;
    }

    /**
     * Connect all supported bluetooth profiles between the local and remote device
     *
     * @param device is the remote device with which to connect all supported profiles
     */
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
            android.Manifest.permission.MODIFY_PHONE_STATE,
    })
    void connectAllSupportedProfiles(BluetoothDevice device) {
        int numProfilesConnected = 0;

        // All profile toggles disabled, so connects all supported profiles
        if (mA2dpService != null && isProfileSupported(device, BluetoothProfile.A2DP)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting A2dp");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting A2dp");
            // Set connection policy also connects the profile with CONNECTION_POLICY_ALLOWED
            mA2dpService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mA2dpSinkService != null && isProfileSupported(
                device, BluetoothProfile.A2DP_SINK)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting A2dp Sink");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting A2dp Sink");
            mA2dpSinkService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mHeadsetService != null && isProfileSupported(
                device, BluetoothProfile.HEADSET)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Headset Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Headset Profile");
            mHeadsetService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mHeadsetClientService != null && isProfileSupported(
                device, BluetoothProfile.HEADSET_CLIENT)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting HFP");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting HFP");
            mHeadsetClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mMapClientService != null && isProfileSupported(
                device, BluetoothProfile.MAP_CLIENT)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting MAP");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting MAP");
            mMapClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mHidHostService != null && isProfileSupported(
                device, BluetoothProfile.HID_HOST)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Hid Host Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Hid Host Profile");
            mHidHostService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mPanService != null && isProfileSupported(
                device, BluetoothProfile.PAN)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Pan Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Pan Profile");
            mPanService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mPbapClientService != null && isProfileSupported(
                device, BluetoothProfile.PBAP_CLIENT)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Pbap");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Pbap");
            mPbapClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
@@ -5701,10 +5717,10 @@ public class AdapterService extends Service {
                device, BluetoothProfile.HEARING_AID)) {
            if (mHapClientService != null && isProfileSupported(
                    device, BluetoothProfile.HAP_CLIENT)) {
                Log.i(TAG, "connectAllEnabledProfiles: Hearing Access Client Profile is enabled"
                Log.i(TAG, "connectAllSupportedProfiles: Hearing Access Client Profile is enabled"
                        + " at the same time with Hearing Aid Profile, ignore Hearing Aid Profile");
            } else {
                Log.i(TAG, "connectAllEnabledProfiles: Connecting Hearing Aid Profile");
                Log.i(TAG, "connectAllSupportedProfiles: Connecting Hearing Aid Profile");
                mHearingAidService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                numProfilesConnected++;
@@ -5712,14 +5728,14 @@ public class AdapterService extends Service {
        }
        if (mHapClientService != null && isProfileSupported(
                device, BluetoothProfile.HAP_CLIENT)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Hearing Access Client Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Hearing Access Client Profile");
            mHapClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mVolumeControlService != null && isProfileSupported(
                device, BluetoothProfile.VOLUME_CONTROL)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Volume Control Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Volume Control Profile");
            mVolumeControlService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
@@ -5727,37 +5743,35 @@ public class AdapterService extends Service {
        if (mCsipSetCoordinatorService != null
                && isProfileSupported(
                device, BluetoothProfile.CSIP_SET_COORDINATOR)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Coordinated Set Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Coordinated Set Profile");
            mCsipSetCoordinatorService.setConnectionPolicy(
                    device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mLeAudioService != null && isProfileSupported(
                device, BluetoothProfile.LE_AUDIO)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting LeAudio profile (BAP)");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting LeAudio profile (BAP)");
            mLeAudioService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mBassClientService != null && isProfileSupported(
                device, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting LE Broadcast Assistant Profile");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting LE Broadcast Assistant Profile");
            mBassClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }
        if (mBatteryService != null && isProfileSupported(
                device, BluetoothProfile.BATTERY)) {
            Log.i(TAG, "connectAllEnabledProfiles: Connecting Battery Service");
            Log.i(TAG, "connectAllSupportedProfiles: Connecting Battery Service");
            mBatteryService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            numProfilesConnected++;
        }

        Log.i(TAG, "connectAllEnabledProfiles: Number of Profiles Connected: "
        Log.i(TAG, "connectAllSupportedProfiles: Number of Profiles Connected: "
                + numProfilesConnected);

        return BluetoothStatusCodes.SUCCESS;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -1139,7 +1139,7 @@ final class RemoteDevices {
                }
                resetBatteryLevel(device);
            }
            if (!mAdapterService.isAnyProfileEnabled(device)) {
            if (mAdapterService.checkifAllProfilesAreUnknown(device)) {
                DeviceProperties deviceProp = getDeviceProperties(device);
                if (deviceProp != null) {
                    deviceProp.setBondingInitiatedLocally(false);