Merge "Revert "Revert "Pass in active device to all BluetoothA2dp APIs ..."" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-05 19:15:30 +00:00
committed by Android (Google) Code Review
11 changed files with 137 additions and 45 deletions

View File

@@ -83,7 +83,11 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
synchronized (mBluetoothA2dpConfigStore) {
if (mBluetoothA2dp != null) {
setCodecConfigPreference(null, codecConfig); // Use current active device
BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
return false;
}
setCodecConfigPreference(activeDevice, codecConfig);
}
}
// Because the setting is not persisted into permanent storage, we cannot call update state
@@ -102,13 +106,14 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
@Override
public void updateState(Preference preference) {
if (getCodecConfig(null) == null || mPreference == null) { // Use current active device
BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null || getCodecConfig(activeDevice) == null || mPreference == null) {
return;
}
BluetoothCodecConfig codecConfig;
synchronized (mBluetoothA2dpConfigStore) {
codecConfig = getCodecConfig(null); // Use current active device
codecConfig = getCodecConfig(activeDevice);
}
final int index = getCurrentA2dpSettingIndex(codecConfig);
@@ -178,13 +183,23 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
@VisibleForTesting
void setCodecConfigPreference(BluetoothDevice device,
BluetoothCodecConfig config) {
mBluetoothA2dp.setCodecConfigPreference(device, config);
BluetoothDevice bluetoothDevice =
(device != null) ? device : mBluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return;
}
mBluetoothA2dp.setCodecConfigPreference(bluetoothDevice, config);
}
@VisibleForTesting
BluetoothCodecConfig getCodecConfig(BluetoothDevice device) {
if (mBluetoothA2dp != null) {
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(device);
BluetoothDevice bluetoothDevice =
(device != null) ? device : mBluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return null;
}
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(bluetoothDevice);
if (codecStatus != null) {
return codecStatus.getCodecConfig();
}

View File

@@ -80,7 +80,10 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
}
writeConfigurationValues(index);
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
bluetoothA2dp.setCodecConfigPreference(null, codecConfig);
BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice != null) {
bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig);
}
mPreference.setSummary(((BaseBluetoothDialogPreference) mPreference).generateSummary(
index));
}
@@ -146,7 +149,13 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
if (bluetoothA2dp == null) {
return null;
}
final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(null);
BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get current codec config. No active device.");
return null;
}
final BluetoothCodecStatus codecStatus =
bluetoothA2dp.getCodecStatus(activeDevice);
if (codecStatus == null) {
Log.d(TAG, "Unable to get current codec config. Codec status is null");
return null;
@@ -164,7 +173,12 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
if (bluetoothA2dp == null) {
return null;
}
final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(device);
BluetoothDevice bluetoothDevice =
(device != null) ? device : bluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return null;
}
final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(bluetoothDevice);
if (codecStatus != null) {
return codecStatus.getCodecsSelectableCapabilities();
}
@@ -177,7 +191,12 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
* @return {@link BluetoothCodecConfig}.
*/
protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) {
final BluetoothCodecConfig[] configs = getSelectableConfigs(null);
BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get selectable config. No active device.");
return null;
}
final BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
if (configs == null) {
Log.d(TAG, "Unable to get selectable config. Selectable configs is empty.");
return null;

View File

@@ -83,9 +83,9 @@ public class BluetoothCodecDialogPreferenceController extends
return index;
}
// Check HD audio is enabled, display the available list.
if (bluetoothA2dp.getOptionalCodecsEnabled(activeDevice)
if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
BluetoothCodecConfig[] configs = getSelectableConfigs(null);
BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
if (configs != null) {
return getIndexFromConfig(configs);
}
@@ -101,7 +101,8 @@ public class BluetoothCodecDialogPreferenceController extends
int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
switch (index) {
case 0:
codecTypeValue = getHighestCodec(getSelectableConfigs(null));
codecTypeValue = getHighestCodec(getSelectableConfigs(
mBluetoothA2dp.getActiveDevice()));
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break;
case 1:

View File

@@ -58,11 +58,11 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe
mPreference.setEnabled(false);
return;
}
final boolean supported = (bluetoothA2dp.supportsOptionalCodecs(activeDevice)
final boolean supported = (bluetoothA2dp.isOptionalCodecsSupported(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
mPreference.setEnabled(supported);
if (supported) {
final boolean isEnabled = bluetoothA2dp.getOptionalCodecsEnabled(activeDevice)
final boolean isEnabled = bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
((SwitchPreference) mPreference).setChecked(isEnabled);
}
@@ -84,11 +84,16 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe
final int prefValue = enabled
? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
: BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
bluetoothA2dp.setOptionalCodecsEnabled(bluetoothA2dp.getActiveDevice(), prefValue);
BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
mPreference.setEnabled(false);
return true;
}
bluetoothA2dp.setOptionalCodecsEnabled(activeDevice, prefValue);
if (enabled) {
bluetoothA2dp.enableOptionalCodecs(null); // Use current active device
bluetoothA2dp.enableOptionalCodecs(activeDevice);
} else {
bluetoothA2dp.disableOptionalCodecs(null); // Use current active device
bluetoothA2dp.disableOptionalCodecs(activeDevice);
}
mCallback.onBluetoothHDAudioEnabled(enabled);
return true;