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

Commit da198344 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I4af15060,I43862413,I7afdc8ed,I366796e4,Ia8efdcb0 into main

* changes:
  AutoConnect hfp: Improve test behavior
  if mostRecentlyActiveA2DPDevice is null, auto connect to mostRecentlyActiveHfpDevice device
  MetadataDatabase: fix format
  Prepare database for mostRecentlyActiveHfpDevice
  Metadata: Add builder
parents 39541aaf 589d4c16
Loading
Loading
Loading
Loading
+150 −92
Original line number Original line Diff line number Diff line
@@ -23,9 +23,6 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.BluetoothUuid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
@@ -80,6 +77,12 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
    private static boolean sLeAudioEnabledByDefault = DeviceConfig.getBoolean(
    private static boolean sLeAudioEnabledByDefault = DeviceConfig.getBoolean(
            DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);
            DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);


    private static final String HFP_AUTO_CONNECT = "HFP_AUTO_CONNECT";

    @VisibleForTesting
    static boolean sIsHfpAutoConnectEnabled =
            DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, HFP_AUTO_CONNECT, false);

    // Timeouts
    // Timeouts
    @VisibleForTesting static int sConnectOtherProfilesTimeoutMillis = 6000; // 6s
    @VisibleForTesting static int sConnectOtherProfilesTimeoutMillis = 6000; // 6s


@@ -206,9 +209,10 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {


        // Set profile priorities only for the profiles discovered on the remote device.
        // Set profile priorities only for the profiles discovered on the remote device.
        // This avoids needless auto-connect attempts to profiles non-existent on the remote device
        // This avoids needless auto-connect attempts to profiles non-existent on the remote device
        if ((hidService != null) && (Utils.arrayContains(uuids, BluetoothUuid.HID)
        if ((hidService != null)
                || Utils.arrayContains(uuids, BluetoothUuid.HOGP)) && (
                && (Utils.arrayContains(uuids, BluetoothUuid.HID)
                hidService.getConnectionPolicy(device)
                        || Utils.arrayContains(uuids, BluetoothUuid.HOGP))
                && (hidService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            if (mAutoConnectProfilesSupported) {
            if (mAutoConnectProfilesSupported) {
                hidService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                hidService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
@@ -230,8 +234,8 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                        BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                        BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            } else {
            } else {
                if (mAutoConnectProfilesSupported) {
                if (mAutoConnectProfilesSupported) {
                    headsetService.setConnectionPolicy(device,
                    headsetService.setConnectionPolicy(
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                } else {
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                            BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
@@ -245,8 +249,7 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                && (a2dpService.getConnectionPolicy(device)
                && (a2dpService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            if (!isDualModeAudioEnabled() && isLeAudioProfileAllowed) {
            if (!isDualModeAudioEnabled() && isLeAudioProfileAllowed) {
                debugLog("clear a2dp profile priority for the le audio dual mode device "
                debugLog("clear a2dp profile priority for the le audio dual mode device " + device);
                        + device);
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                        BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                        BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            } else {
            } else {
@@ -254,8 +257,12 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                    a2dpService.setConnectionPolicy(device,
                    a2dpService.setConnectionPolicy(device,
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                } else {
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    mAdapterService
                            BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            .getDatabase()
                            .setProfileConnectionPolicy(
                                    device,
                                    BluetoothProfile.A2DP,
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
                }
            }
            }
        }
        }
@@ -267,10 +274,13 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            // Always allow CSIP during pairing process regardless of LE audio preference
            // Always allow CSIP during pairing process regardless of LE audio preference
            if (mAutoConnectProfilesSupported) {
            if (mAutoConnectProfilesSupported) {
                csipSetCoordinatorService.setConnectionPolicy(device,
                csipSetCoordinatorService.setConnectionPolicy(
                        BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                        device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            } else {
            } else {
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.CSIP_SET_COORDINATOR,
                                BluetoothProfile.CSIP_SET_COORDINATOR,
                                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            }
            }
@@ -281,13 +291,18 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                && (Utils.arrayContains(uuids, BluetoothUuid.PANU)
                && (Utils.arrayContains(uuids, BluetoothUuid.PANU)
                        && (panService.getConnectionPolicy(device)
                        && (panService.getConnectionPolicy(device)
                                == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)
                                == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)
                && mAdapterService.getResources()
                        && mAdapterService
                                .getResources()
                                .getBoolean(R.bool.config_bluetooth_pan_enable_autoconnect))) {
                                .getBoolean(R.bool.config_bluetooth_pan_enable_autoconnect))) {
            if (mAutoConnectProfilesSupported) {
            if (mAutoConnectProfilesSupported) {
                panService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                panService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            } else {
            } else {
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        BluetoothProfile.PAN, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.PAN,
                                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            }
            }
        }
        }


@@ -298,16 +313,24 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
            if (isLeAudioProfileAllowed) {
            if (isLeAudioProfileAllowed) {
                debugLog("setting le audio profile priority for device " + device);
                debugLog("setting le audio profile priority for device " + device);
                if (mAutoConnectProfilesSupported) {
                if (mAutoConnectProfilesSupported) {
                    leAudioService.setConnectionPolicy(device,
                    leAudioService.setConnectionPolicy(
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                } else {
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    mAdapterService
                            BluetoothProfile.LE_AUDIO, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            .getDatabase()
                            .setProfileConnectionPolicy(
                                    device,
                                    BluetoothProfile.LE_AUDIO,
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
                }
            } else {
            } else {
                debugLog("clear LEA profile priority because LE audio is not allowed");
                debugLog("clear LEA profile priority because LE audio is not allowed");
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        BluetoothProfile.LE_AUDIO, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.LE_AUDIO,
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            }
            }
        }
        }


@@ -317,15 +340,22 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            if (isLeAudioProfileAllowed) {
            if (isLeAudioProfileAllowed) {
                debugLog("LE Audio preferred over ASHA for device " + device);
                debugLog("LE Audio preferred over ASHA for device " + device);
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        BluetoothProfile.HEARING_AID, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.HEARING_AID,
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            } else {
            } else {
                debugLog("setting hearing aid profile priority for device " + device);
                debugLog("setting hearing aid profile priority for device " + device);
                if (mAutoConnectProfilesSupported) {
                if (mAutoConnectProfilesSupported) {
                    hearingAidService.setConnectionPolicy(device,
                    hearingAidService.setConnectionPolicy(
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                } else {
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    mAdapterService
                            .getDatabase()
                            .setProfileConnectionPolicy(
                                    device,
                                    BluetoothProfile.HEARING_AID,
                                    BluetoothProfile.HEARING_AID,
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
                }
@@ -339,16 +369,22 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
            if (isLeAudioProfileAllowed) {
            if (isLeAudioProfileAllowed) {
                debugLog("setting volume control profile priority for device " + device);
                debugLog("setting volume control profile priority for device " + device);
                if (mAutoConnectProfilesSupported) {
                if (mAutoConnectProfilesSupported) {
                    volumeControlService.setConnectionPolicy(device,
                    volumeControlService.setConnectionPolicy(
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                } else {
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    mAdapterService
                            .getDatabase()
                            .setProfileConnectionPolicy(
                                    device,
                                    BluetoothProfile.VOLUME_CONTROL,
                                    BluetoothProfile.VOLUME_CONTROL,
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
                }
            } else {
            } else {
                debugLog("clear VCP priority because dual mode is disabled by default");
                debugLog("clear VCP priority because dual mode is disabled by default");
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.VOLUME_CONTROL,
                                BluetoothProfile.VOLUME_CONTROL,
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            }
            }
@@ -361,15 +397,18 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
            debugLog("setting hearing access profile priority for device " + device);
            debugLog("setting hearing access profile priority for device " + device);
            if (isLeAudioProfileAllowed) {
            if (isLeAudioProfileAllowed) {
                if (mAutoConnectProfilesSupported) {
                if (mAutoConnectProfilesSupported) {
                    hapClientService.setConnectionPolicy(device,
                    hapClientService.setConnectionPolicy(
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                } else {
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                            BluetoothProfile.HAP_CLIENT,
                            BluetoothProfile.HAP_CLIENT,
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                            BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
                }
            } else {
            } else {
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.HAP_CLIENT,
                                BluetoothProfile.HAP_CLIENT,
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            }
            }
@@ -383,7 +422,10 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
            if (mAutoConnectProfilesSupported) {
            if (mAutoConnectProfilesSupported) {
                bcService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                bcService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            } else {
            } else {
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT,
                                BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT,
                                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            }
            }
@@ -398,8 +440,12 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                batteryService.setConnectionPolicy(device,
                batteryService.setConnectionPolicy(device,
                        BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                        BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            } else {
            } else {
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mAdapterService
                        BluetoothProfile.BATTERY, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.BATTERY,
                                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            }
            }
        }
        }
    }
    }
@@ -410,7 +456,8 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
        debugLog("processProfileStateChanged, device=" + device + ", profile="
        debugLog("processProfileStateChanged, device=" + device + ", profile="
                + BluetoothProfile.getProfileName(profileId) + ", " + prevState + " -> "
                + BluetoothProfile.getProfileName(profileId) + ", " + prevState + " -> "
                + nextState);
                + nextState);
        if (((profileId == BluetoothProfile.A2DP) || (profileId == BluetoothProfile.HEADSET)
        if (((profileId == BluetoothProfile.A2DP)
                || (profileId == BluetoothProfile.HEADSET)
                || (profileId == BluetoothProfile.LE_AUDIO)
                || (profileId == BluetoothProfile.LE_AUDIO)
                || (profileId == BluetoothProfile.CSIP_SET_COORDINATOR)
                || (profileId == BluetoothProfile.CSIP_SET_COORDINATOR)
                || (profileId == BluetoothProfile.VOLUME_CONTROL)
                || (profileId == BluetoothProfile.VOLUME_CONTROL)
@@ -427,10 +474,9 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                connectOtherProfile(device);
                connectOtherProfile(device);
            }
            }
            if (nextState == BluetoothProfile.STATE_DISCONNECTED) {
            if (nextState == BluetoothProfile.STATE_DISCONNECTED) {
                if (profileId == BluetoothProfile.A2DP
                if (prevState == BluetoothProfile.STATE_CONNECTING
                        && (prevState == BluetoothProfile.STATE_CONNECTING
                        || prevState == BluetoothProfile.STATE_DISCONNECTING) {
                        || prevState == BluetoothProfile.STATE_DISCONNECTING)) {
                    mDatabaseManager.setDisconnection(device, profileId);
                    mDatabaseManager.setDisconnection(device);
                }
                }
                handleAllProfilesDisconnected(device);
                handleAllProfilesDisconnected(device);
            }
            }
@@ -440,8 +486,8 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
    /**
    /**
     * Updates the last connection date in the connection order database for the newly active device
     * Updates the last connection date in the connection order database for the newly active device
     * if connected to the A2DP profile. If this is a dual mode audio device (supports classic and
     * if connected to the A2DP profile. If this is a dual mode audio device (supports classic and
     * LE Audio), LE Audio is made active, and {@link Utils#isDualModeAudioEnabled()} is false,
     * LE Audio), LE Audio is made active, and {@link Utils#isDualModeAudioEnabled()} is false, A2DP
     * A2DP and HFP will be disconnected.
     * and HFP will be disconnected.
     *
     *
     * @param device is the device we just made the active device
     * @param device is the device we just made the active device
     */
     */
@@ -451,7 +497,7 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
                + isDualModeAudioEnabled());
                + isDualModeAudioEnabled());


        if (device != null) {
        if (device != null) {
            mDatabaseManager.setConnection(device, profileId == BluetoothProfile.A2DP);
            mDatabaseManager.setConnection(device, profileId);


            if (isDualModeAudioEnabled()) return;
            if (isDualModeAudioEnabled()) return;
            if (profileId == BluetoothProfile.LE_AUDIO) {
            if (profileId == BluetoothProfile.LE_AUDIO) {
@@ -486,7 +532,7 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {


    private void processDeviceConnected(BluetoothDevice device) {
    private void processDeviceConnected(BluetoothDevice device) {
        debugLog("processDeviceConnected, device=" + device);
        debugLog("processDeviceConnected, device=" + device);
        mDatabaseManager.setConnection(device, false);
        mDatabaseManager.setConnection(device);
    }
    }


    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@@ -547,29 +593,45 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
        mA2dpRetrySet.clear();
        mA2dpRetrySet.clear();
    }
    }


    @VisibleForTesting
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    private void autoConnect() {
    void autoConnect() {
        if (mAdapterService.getState() != BluetoothAdapter.STATE_ON) {
        if (mAdapterService.getState() != BluetoothAdapter.STATE_ON) {
            errorLog("autoConnect: BT is not ON. Exiting autoConnect");
            Log.e(TAG, "autoConnect: BT is not ON. Exiting autoConnect");
            return;
        }
        if (mAdapterService.isQuietModeEnabled()) {
            Log.i(TAG, "autoConnect() - BT is in quiet mode. Not initiating autoConnect");
            return;
            return;
        }
        }


        if (!mAdapterService.isQuietModeEnabled()) {
            debugLog("autoConnect: Initiate auto connection on BT on...");
        final BluetoothDevice mostRecentlyActiveA2dpDevice =
        final BluetoothDevice mostRecentlyActiveA2dpDevice =
                mDatabaseManager.getMostRecentlyConnectedA2dpDevice();
                mDatabaseManager.getMostRecentlyConnectedA2dpDevice();
            if (mostRecentlyActiveA2dpDevice == null) {
        if (mostRecentlyActiveA2dpDevice != null) {
                errorLog("autoConnect: most recently active a2dp device is null");
            debugLog(
                return;
                    "autoConnect: Device "
            }
                            + mostRecentlyActiveA2dpDevice
            debugLog("autoConnect: Device " + mostRecentlyActiveA2dpDevice
                            + " attempting auto connection");
                            + " attempting auto connection");
            autoConnectHeadset(mostRecentlyActiveA2dpDevice);
            autoConnectHeadset(mostRecentlyActiveA2dpDevice);
            autoConnectA2dp(mostRecentlyActiveA2dpDevice);
            autoConnectA2dp(mostRecentlyActiveA2dpDevice);
            autoConnectHidHost(mostRecentlyActiveA2dpDevice);
            autoConnectHidHost(mostRecentlyActiveA2dpDevice);
        } else {
            return;
            debugLog("autoConnect() - BT is in quiet mode. Not initiating auto connections");
        }
        }

        if (!sIsHfpAutoConnectEnabled) {
            debugLog("HFP auto connect is not enabled");
            return;
        }

        // Try to autoConnect with Hfp only if there was no a2dp valid device
        final BluetoothDevice mostRecentlyConnectedHfpDevice =
                mDatabaseManager.getMostRecentlyActiveHfpDevice();
        if (mostRecentlyConnectedHfpDevice != null) {
            debugLog("autoConnect: Headset device: " + mostRecentlyConnectedHfpDevice);
            autoConnectHeadset(mostRecentlyConnectedHfpDevice);
            return;
        }
        Log.i(TAG, "autoConnect: No device to reconnect to");
    }
    }


    private void autoConnectA2dp(BluetoothDevice device) {
    private void autoConnectA2dp(BluetoothDevice device) {
@@ -800,8 +862,4 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
    private static void warnLog(String msg) {
    private static void warnLog(String msg) {
        Log.w(TAG, msg);
        Log.w(TAG, msg);
    }
    }

    private static void errorLog(String msg) {
        Log.e(TAG, msg);
    }
}
}
+178 −69

File changed.

Preview size limit exceeded, changes collapsed.

+46 −13
Original line number Original line Diff line number Diff line
@@ -58,6 +58,8 @@ public class Metadata {
    public long last_active_time;
    public long last_active_time;
    public boolean is_active_a2dp_device;
    public boolean is_active_a2dp_device;


    public boolean isActiveHfpDevice;

    @Embedded
    @Embedded
    public AudioPolicyEntity audioPolicyMetadata;
    public AudioPolicyEntity audioPolicyMetadata;


@@ -78,6 +80,10 @@ public class Metadata {
    public int preferred_duplex_profile;
    public int preferred_duplex_profile;


    Metadata(String address) {
    Metadata(String address) {
        this(address, false, false);
    }

    private Metadata(String address, boolean isActiveA2dp, boolean isActiveHfp) {
        this.address = address;
        this.address = address;
        migrated = false;
        migrated = false;
        profileConnectionPolicies = new ProfilePrioritiesEntity();
        profileConnectionPolicies = new ProfilePrioritiesEntity();
@@ -85,12 +91,37 @@ public class Metadata {
        a2dpSupportsOptionalCodecs = BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN;
        a2dpSupportsOptionalCodecs = BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN;
        a2dpOptionalCodecsEnabled = BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN;
        a2dpOptionalCodecsEnabled = BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN;
        last_active_time = MetadataDatabase.sCurrentConnectionNumber++;
        last_active_time = MetadataDatabase.sCurrentConnectionNumber++;
        is_active_a2dp_device = true;
        is_active_a2dp_device = isActiveA2dp;
        isActiveHfpDevice = isActiveHfp;
        audioPolicyMetadata = new AudioPolicyEntity();
        audioPolicyMetadata = new AudioPolicyEntity();
        preferred_output_only_profile = 0;
        preferred_output_only_profile = 0;
        preferred_duplex_profile = 0;
        preferred_duplex_profile = 0;
    }
    }


    static final class Builder {
        final String mAddress;
        boolean mIsActiveA2dpDevice = false;
        boolean mIsActiveHfpDevice = false;

        Builder(String address) {
            mAddress = address;
        }

        Builder setActiveA2dp() {
            mIsActiveA2dpDevice = true;
            return this;
        }

        Builder setActiveHfp() {
            mIsActiveHfpDevice = true;
            return this;
        }

        Metadata build() {
            return new Metadata(mAddress, mIsActiveA2dpDevice, mIsActiveHfpDevice);
        }
    }

    /**
    /**
     * @hide
     * @hide
     */
     */
@@ -439,6 +470,8 @@ public class Metadata {
                .append(a2dpSupportsOptionalCodecs)
                .append(a2dpSupportsOptionalCodecs)
                .append("|enabled=")
                .append("|enabled=")
                .append(a2dpOptionalCodecsEnabled)
                .append(a2dpOptionalCodecsEnabled)
                .append("), isActiveHfpDevice (")
                .append(isActiveHfpDevice)
                .append("), custom metadata(")
                .append("), custom metadata(")
                .append(publicMetadata)
                .append(publicMetadata)
                .append("), hfp client audio policy(")
                .append("), hfp client audio policy(")
+474 −410

File changed.

Preview size limit exceeded, changes collapsed.

+91 −34

File changed.

Preview size limit exceeded, changes collapsed.

Loading