Loading android/app/src/com/android/bluetooth/btservice/PhonePolicy.java +54 −2 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.os.Looper; import android.os.Message; import android.os.ParcelUuid; import android.os.Parcelable; import android.os.SystemProperties; import android.util.Log; import com.android.bluetooth.R; Loading Loading @@ -95,6 +96,9 @@ class PhonePolicy { private static final int MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED = 5; private static final int MESSAGE_DEVICE_CONNECTED = 6; private static final String PREFER_LE_AUDIO_ONLY_MODE = "persist.bluetooth.prefer_le_audio_only_mode"; // Timeouts @VisibleForTesting static int sConnectOtherProfilesTimeoutMillis = 6000; // 6s Loading @@ -106,6 +110,8 @@ class PhonePolicy { private final HashSet<BluetoothDevice> mA2dpRetrySet = new HashSet<>(); private final HashSet<BluetoothDevice> mConnectOtherProfilesDeviceSet = new HashSet<>(); private Boolean mPreferLeAudioOnlyMode = false; // Broadcast receiver for all changes to states of various profiles private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override Loading Loading @@ -284,6 +290,7 @@ class PhonePolicy { "DatabaseManager cannot be null when PhonePolicy starts"); mFactory = factory; mHandler = new PhonePolicyHandler(service.getMainLooper()); mPreferLeAudioOnlyMode = SystemProperties.getBoolean(PREFER_LE_AUDIO_ONLY_MODE, true); } // Policy implementation, all functions MUST be private Loading Loading @@ -354,6 +361,24 @@ class PhonePolicy { debugLog("setting le audio profile priority for device " + device); mAdapterService.getDatabase().setProfileConnectionPolicy(device, BluetoothProfile.LE_AUDIO, BluetoothProfile.CONNECTION_POLICY_ALLOWED); if (mPreferLeAudioOnlyMode) { if (mAdapterService.getDatabase() .getProfileConnectionPolicy(device, BluetoothProfile.A2DP) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { debugLog("clear a2dp profile priority for the le audio dual mode device " + device); mAdapterService.getDatabase().setProfileConnectionPolicy(device, BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); } if (mAdapterService.getDatabase() .getProfileConnectionPolicy(device, BluetoothProfile.HEADSET) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { debugLog("clear hfp profile priority for the le audio dual mode device " + device); mAdapterService.getDatabase().setProfileConnectionPolicy(device, BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); } } } if ((hearingAidService != null) && Utils.arrayContains(uuids, Loading Loading @@ -430,15 +455,42 @@ class PhonePolicy { /** * Updates the last connection date in the connection order database for the newly active device * if connected to a2dp profile * if connected to a2dp profile. If the device is LE audio dual mode device, and * mPreferLeAudioOnlyMode be true, A2DP/HFP will be disconnected as LE audio become active one * after pairing. * * @param device is the device we just made the active device */ private void processActiveDeviceChanged(BluetoothDevice device, int profileId) { debugLog("processActiveDeviceChanged, device=" + device + ", profile=" + profileId); debugLog("processActiveDeviceChanged, device=" + device + ", profile=" + profileId + " mPreferLeAudioOnlyMode: " + mPreferLeAudioOnlyMode); if (device != null) { mDatabaseManager.setConnection(device, profileId == BluetoothProfile.A2DP); if (!mPreferLeAudioOnlyMode) return; if (profileId == BluetoothProfile.LE_AUDIO) { HeadsetService hsService = mFactory.getHeadsetService(); if (hsService != null) { if ((hsService.getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_ALLOWED) && (hsService.getConnectionState(device) == BluetoothProfile.STATE_CONNECTED)) { debugLog("Disconnect HFP for the LE audio dual mode device " + device); hsService.disconnect(device); } } A2dpService a2dpService = mFactory.getA2dpService(); if (a2dpService != null) { if ((a2dpService.getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_ALLOWED) && (a2dpService.getConnectionState(device) == BluetoothProfile.STATE_CONNECTED)) { debugLog("Disconnect A2DP for the LE audio dual mode device " + device); a2dpService.disconnect(device); } } } } } Loading Loading
android/app/src/com/android/bluetooth/btservice/PhonePolicy.java +54 −2 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.os.Looper; import android.os.Message; import android.os.ParcelUuid; import android.os.Parcelable; import android.os.SystemProperties; import android.util.Log; import com.android.bluetooth.R; Loading Loading @@ -95,6 +96,9 @@ class PhonePolicy { private static final int MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED = 5; private static final int MESSAGE_DEVICE_CONNECTED = 6; private static final String PREFER_LE_AUDIO_ONLY_MODE = "persist.bluetooth.prefer_le_audio_only_mode"; // Timeouts @VisibleForTesting static int sConnectOtherProfilesTimeoutMillis = 6000; // 6s Loading @@ -106,6 +110,8 @@ class PhonePolicy { private final HashSet<BluetoothDevice> mA2dpRetrySet = new HashSet<>(); private final HashSet<BluetoothDevice> mConnectOtherProfilesDeviceSet = new HashSet<>(); private Boolean mPreferLeAudioOnlyMode = false; // Broadcast receiver for all changes to states of various profiles private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override Loading Loading @@ -284,6 +290,7 @@ class PhonePolicy { "DatabaseManager cannot be null when PhonePolicy starts"); mFactory = factory; mHandler = new PhonePolicyHandler(service.getMainLooper()); mPreferLeAudioOnlyMode = SystemProperties.getBoolean(PREFER_LE_AUDIO_ONLY_MODE, true); } // Policy implementation, all functions MUST be private Loading Loading @@ -354,6 +361,24 @@ class PhonePolicy { debugLog("setting le audio profile priority for device " + device); mAdapterService.getDatabase().setProfileConnectionPolicy(device, BluetoothProfile.LE_AUDIO, BluetoothProfile.CONNECTION_POLICY_ALLOWED); if (mPreferLeAudioOnlyMode) { if (mAdapterService.getDatabase() .getProfileConnectionPolicy(device, BluetoothProfile.A2DP) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { debugLog("clear a2dp profile priority for the le audio dual mode device " + device); mAdapterService.getDatabase().setProfileConnectionPolicy(device, BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); } if (mAdapterService.getDatabase() .getProfileConnectionPolicy(device, BluetoothProfile.HEADSET) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { debugLog("clear hfp profile priority for the le audio dual mode device " + device); mAdapterService.getDatabase().setProfileConnectionPolicy(device, BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); } } } if ((hearingAidService != null) && Utils.arrayContains(uuids, Loading Loading @@ -430,15 +455,42 @@ class PhonePolicy { /** * Updates the last connection date in the connection order database for the newly active device * if connected to a2dp profile * if connected to a2dp profile. If the device is LE audio dual mode device, and * mPreferLeAudioOnlyMode be true, A2DP/HFP will be disconnected as LE audio become active one * after pairing. * * @param device is the device we just made the active device */ private void processActiveDeviceChanged(BluetoothDevice device, int profileId) { debugLog("processActiveDeviceChanged, device=" + device + ", profile=" + profileId); debugLog("processActiveDeviceChanged, device=" + device + ", profile=" + profileId + " mPreferLeAudioOnlyMode: " + mPreferLeAudioOnlyMode); if (device != null) { mDatabaseManager.setConnection(device, profileId == BluetoothProfile.A2DP); if (!mPreferLeAudioOnlyMode) return; if (profileId == BluetoothProfile.LE_AUDIO) { HeadsetService hsService = mFactory.getHeadsetService(); if (hsService != null) { if ((hsService.getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_ALLOWED) && (hsService.getConnectionState(device) == BluetoothProfile.STATE_CONNECTED)) { debugLog("Disconnect HFP for the LE audio dual mode device " + device); hsService.disconnect(device); } } A2dpService a2dpService = mFactory.getA2dpService(); if (a2dpService != null) { if ((a2dpService.getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_ALLOWED) && (a2dpService.getConnectionState(device) == BluetoothProfile.STATE_CONNECTED)) { debugLog("Disconnect A2DP for the LE audio dual mode device " + device); a2dpService.disconnect(device); } } } } } Loading