Loading src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java +25 −9 Original line number Diff line number Diff line Loading @@ -17,9 +17,12 @@ package com.android.settings.development; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import androidx.annotation.VisibleForTesting; Loading @@ -34,6 +37,8 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnDestroy; import com.android.settingslib.development.DeveloperOptionsPreferenceController; import java.util.List; public abstract class AbstractBluetoothA2dpPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin, BluetoothServiceConnectionListener, LifecycleObserver, Loading @@ -48,11 +53,15 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends private final String[] mListValues; private final String[] mListSummaries; @VisibleForTesting BluetoothAdapter mBluetoothAdapter; public AbstractBluetoothA2dpPreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store) { super(context); mBluetoothA2dpConfigStore = store; mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); mListValues = getListValues(); mListSummaries = getListSummaries(); Loading Loading @@ -82,14 +91,12 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); synchronized (mBluetoothA2dpConfigStore) { if (mBluetoothA2dp != null) { BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { return false; } setCodecConfigPreference(activeDevice, codecConfig); } } // Because the setting is not persisted into permanent storage, we cannot call update state // here to update the preference. // Instead, we just assume it was set and update the preference here. Loading @@ -106,7 +113,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends @Override public void updateState(Preference preference) { BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null || getCodecConfig(activeDevice) == null || mPreference == null) { return; } Loading Loading @@ -184,7 +191,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends void setCodecConfigPreference(BluetoothDevice device, BluetoothCodecConfig config) { BluetoothDevice bluetoothDevice = (device != null) ? device : mBluetoothA2dp.getActiveDevice(); (device != null) ? device : getA2dpActiveDevice(); if (bluetoothDevice == null) { return; } Loading @@ -195,7 +202,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends BluetoothCodecConfig getCodecConfig(BluetoothDevice device) { if (mBluetoothA2dp != null) { BluetoothDevice bluetoothDevice = (device != null) ? device : mBluetoothA2dp.getActiveDevice(); (device != null) ? device : getA2dpActiveDevice(); if (bluetoothDevice == null) { return null; } Loading @@ -206,4 +213,13 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends } return null; } private BluetoothDevice getA2dpActiveDevice() { if (mBluetoothAdapter == null) { return null; } List<BluetoothDevice> activeDevices = mBluetoothAdapter.getActiveDevices(BluetoothProfile.A2DP); return (activeDevices.size() > 0) ? activeDevices.get(0) : null; } } src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java +4 −4 Original line number Diff line number Diff line Loading @@ -84,7 +84,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends } writeConfigurationValues(index); final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice != null) { bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig); } Loading Loading @@ -153,7 +153,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends if (bluetoothA2dp == null) { return null; } BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.d(TAG, "Unable to get current codec config. No active device."); return null; Loading @@ -178,7 +178,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends return null; } BluetoothDevice bluetoothDevice = (device != null) ? device : bluetoothA2dp.getActiveDevice(); (device != null) ? device : getA2dpActiveDevice(); if (bluetoothDevice == null) { return null; } Loading @@ -195,7 +195,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends * @return {@link BluetoothCodecConfig}. */ protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) { BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.d(TAG, "Unable to get selectable config. No active device."); return null; Loading src/com/android/settings/development/bluetooth/AbstractBluetoothPreferenceController.java +21 −0 Original line number Diff line number Diff line Loading @@ -17,8 +17,14 @@ package com.android.settings.development.bluetooth; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import androidx.annotation.VisibleForTesting; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.development.BluetoothA2dpConfigStore; import com.android.settings.development.BluetoothServiceConnectionListener; Loading @@ -27,6 +33,8 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnDestroy; import com.android.settingslib.development.DeveloperOptionsPreferenceController; import java.util.List; /** * Abstract class for Bluetooth A2DP config controller in developer option. */ Loading @@ -36,12 +44,16 @@ public abstract class AbstractBluetoothPreferenceController extends protected volatile BluetoothA2dp mBluetoothA2dp; @VisibleForTesting BluetoothAdapter mBluetoothAdapter; public AbstractBluetoothPreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store) { super(context); if (lifecycle != null) { lifecycle.addObserver(this); } mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); } @Override Loading Loading @@ -82,4 +94,13 @@ public abstract class AbstractBluetoothPreferenceController extends */ void onBluetoothHDAudioEnabled(boolean enabled); } protected BluetoothDevice getA2dpActiveDevice() { if (mBluetoothAdapter == null) { return null; } List<BluetoothDevice> activeDevices = mBluetoothAdapter.getActiveDevices(BluetoothProfile.A2DP); return (activeDevices.size() > 0) ? activeDevices.get(0) : null; } } src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -69,7 +69,7 @@ public class BluetoothCodecDialogPreferenceController extends if (bluetoothA2dp == null) { return index; } final BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); final BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.d(TAG, "Unable to get selectable index. No Active Bluetooth device"); return index; Loading @@ -93,7 +93,7 @@ public class BluetoothCodecDialogPreferenceController extends int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; switch (index) { case 0: final BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); final BluetoothDevice activeDevice = getA2dpActiveDevice(); codecTypeValue = getHighestCodec(mBluetoothA2dp, activeDevice, getSelectableConfigs(activeDevice)); codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; Loading src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe mPreference.setEnabled(false); return; } final BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); final BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.e(TAG, "Active device is null. To disable HD audio button"); mPreference.setEnabled(false); Loading Loading @@ -84,7 +84,7 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe final int prefValue = enabled ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { mPreference.setEnabled(false); return true; Loading Loading
src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java +25 −9 Original line number Diff line number Diff line Loading @@ -17,9 +17,12 @@ package com.android.settings.development; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import androidx.annotation.VisibleForTesting; Loading @@ -34,6 +37,8 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnDestroy; import com.android.settingslib.development.DeveloperOptionsPreferenceController; import java.util.List; public abstract class AbstractBluetoothA2dpPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin, BluetoothServiceConnectionListener, LifecycleObserver, Loading @@ -48,11 +53,15 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends private final String[] mListValues; private final String[] mListSummaries; @VisibleForTesting BluetoothAdapter mBluetoothAdapter; public AbstractBluetoothA2dpPreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store) { super(context); mBluetoothA2dpConfigStore = store; mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); mListValues = getListValues(); mListSummaries = getListSummaries(); Loading Loading @@ -82,14 +91,12 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); synchronized (mBluetoothA2dpConfigStore) { if (mBluetoothA2dp != null) { BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { return false; } setCodecConfigPreference(activeDevice, codecConfig); } } // Because the setting is not persisted into permanent storage, we cannot call update state // here to update the preference. // Instead, we just assume it was set and update the preference here. Loading @@ -106,7 +113,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends @Override public void updateState(Preference preference) { BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null || getCodecConfig(activeDevice) == null || mPreference == null) { return; } Loading Loading @@ -184,7 +191,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends void setCodecConfigPreference(BluetoothDevice device, BluetoothCodecConfig config) { BluetoothDevice bluetoothDevice = (device != null) ? device : mBluetoothA2dp.getActiveDevice(); (device != null) ? device : getA2dpActiveDevice(); if (bluetoothDevice == null) { return; } Loading @@ -195,7 +202,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends BluetoothCodecConfig getCodecConfig(BluetoothDevice device) { if (mBluetoothA2dp != null) { BluetoothDevice bluetoothDevice = (device != null) ? device : mBluetoothA2dp.getActiveDevice(); (device != null) ? device : getA2dpActiveDevice(); if (bluetoothDevice == null) { return null; } Loading @@ -206,4 +213,13 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends } return null; } private BluetoothDevice getA2dpActiveDevice() { if (mBluetoothAdapter == null) { return null; } List<BluetoothDevice> activeDevices = mBluetoothAdapter.getActiveDevices(BluetoothProfile.A2DP); return (activeDevices.size() > 0) ? activeDevices.get(0) : null; } }
src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java +4 −4 Original line number Diff line number Diff line Loading @@ -84,7 +84,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends } writeConfigurationValues(index); final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice != null) { bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig); } Loading Loading @@ -153,7 +153,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends if (bluetoothA2dp == null) { return null; } BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.d(TAG, "Unable to get current codec config. No active device."); return null; Loading @@ -178,7 +178,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends return null; } BluetoothDevice bluetoothDevice = (device != null) ? device : bluetoothA2dp.getActiveDevice(); (device != null) ? device : getA2dpActiveDevice(); if (bluetoothDevice == null) { return null; } Loading @@ -195,7 +195,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends * @return {@link BluetoothCodecConfig}. */ protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) { BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.d(TAG, "Unable to get selectable config. No active device."); return null; Loading
src/com/android/settings/development/bluetooth/AbstractBluetoothPreferenceController.java +21 −0 Original line number Diff line number Diff line Loading @@ -17,8 +17,14 @@ package com.android.settings.development.bluetooth; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import androidx.annotation.VisibleForTesting; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.development.BluetoothA2dpConfigStore; import com.android.settings.development.BluetoothServiceConnectionListener; Loading @@ -27,6 +33,8 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnDestroy; import com.android.settingslib.development.DeveloperOptionsPreferenceController; import java.util.List; /** * Abstract class for Bluetooth A2DP config controller in developer option. */ Loading @@ -36,12 +44,16 @@ public abstract class AbstractBluetoothPreferenceController extends protected volatile BluetoothA2dp mBluetoothA2dp; @VisibleForTesting BluetoothAdapter mBluetoothAdapter; public AbstractBluetoothPreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store) { super(context); if (lifecycle != null) { lifecycle.addObserver(this); } mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); } @Override Loading Loading @@ -82,4 +94,13 @@ public abstract class AbstractBluetoothPreferenceController extends */ void onBluetoothHDAudioEnabled(boolean enabled); } protected BluetoothDevice getA2dpActiveDevice() { if (mBluetoothAdapter == null) { return null; } List<BluetoothDevice> activeDevices = mBluetoothAdapter.getActiveDevices(BluetoothProfile.A2DP); return (activeDevices.size() > 0) ? activeDevices.get(0) : null; } }
src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -69,7 +69,7 @@ public class BluetoothCodecDialogPreferenceController extends if (bluetoothA2dp == null) { return index; } final BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); final BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.d(TAG, "Unable to get selectable index. No Active Bluetooth device"); return index; Loading @@ -93,7 +93,7 @@ public class BluetoothCodecDialogPreferenceController extends int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; switch (index) { case 0: final BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); final BluetoothDevice activeDevice = getA2dpActiveDevice(); codecTypeValue = getHighestCodec(mBluetoothA2dp, activeDevice, getSelectableConfigs(activeDevice)); codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; Loading
src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe mPreference.setEnabled(false); return; } final BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); final BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { Log.e(TAG, "Active device is null. To disable HD audio button"); mPreference.setEnabled(false); Loading Loading @@ -84,7 +84,7 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe final int prefValue = enabled ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice(); BluetoothDevice activeDevice = getA2dpActiveDevice(); if (activeDevice == null) { mPreference.setEnabled(false); return true; Loading