Merge "24Q4: Removal of a2dp_offload_codec_extensibility_settings" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
eb927665a3
@@ -1,13 +1,6 @@
|
|||||||
package: "com.android.settings.development"
|
package: "com.android.settings.development"
|
||||||
container: "system"
|
container: "system"
|
||||||
|
|
||||||
flag {
|
|
||||||
name: "a2dp_offload_codec_extensibility_settings"
|
|
||||||
namespace: "bluetooth"
|
|
||||||
description: "Feature flag for Bluetooth Audio Codec extensibility in Settings"
|
|
||||||
bug: "323319530"
|
|
||||||
}
|
|
||||||
|
|
||||||
flag {
|
flag {
|
||||||
name: "deprecate_list_activity"
|
name: "deprecate_list_activity"
|
||||||
namespace: "android_settings"
|
namespace: "android_settings"
|
||||||
|
@@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2019 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp">
|
|
||||||
|
|
||||||
<RadioGroup
|
|
||||||
android:id="@+id/bluetooth_audio_codec_radio_group"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="@dimen/developer_option_dialog_margin_start">
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_default"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_sbc"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_aac"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_aptx"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_aptx_hd"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_ldac"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_lc3"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_opus"
|
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
|
||||||
|
|
||||||
</RadioGroup>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/bluetooth_audio_codec_help_info"
|
|
||||||
layout="@layout/preference_widget_dialog_summary"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
||||||
|
|
@@ -434,14 +434,6 @@
|
|||||||
android:key="bluetooth_hd_audio_settings"
|
android:key="bluetooth_hd_audio_settings"
|
||||||
android:title="@string/bluetooth_profile_a2dp_high_quality_unknown_codec"/>
|
android:title="@string/bluetooth_profile_a2dp_high_quality_unknown_codec"/>
|
||||||
|
|
||||||
<com.android.settings.development.bluetooth.BluetoothCodecDialogPreference
|
|
||||||
android:key="bluetooth_audio_codec_settings"
|
|
||||||
android:title="@string/bluetooth_select_a2dp_codec_type"
|
|
||||||
android:dialogTitle="@string/bluetooth_select_a2dp_codec_type_dialog_title"
|
|
||||||
android:dialogLayout="@layout/bluetooth_audio_codec_dialog"
|
|
||||||
android:positiveButtonText=""
|
|
||||||
android:negativeButtonText="@string/dlg_ok"/>
|
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="bluetooth_audio_codec_settings_list"
|
android:key="bluetooth_audio_codec_settings_list"
|
||||||
android:title="@string/bluetooth_select_a2dp_codec_type"
|
android:title="@string/bluetooth_select_a2dp_codec_type"
|
||||||
|
@@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
import android.annotation.FlaggedApi;
|
|
||||||
import android.bluetooth.BluetoothCodecConfig;
|
import android.bluetooth.BluetoothCodecConfig;
|
||||||
import android.bluetooth.BluetoothCodecType;
|
import android.bluetooth.BluetoothCodecType;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
/** Utility class for storing current Bluetooth A2DP profile values */
|
/** Utility class for storing current Bluetooth A2DP profile values */
|
||||||
@@ -38,10 +36,6 @@ public class BluetoothA2dpConfigStore {
|
|||||||
private long mCodecSpecific3Value;
|
private long mCodecSpecific3Value;
|
||||||
private long mCodecSpecific4Value;
|
private long mCodecSpecific4Value;
|
||||||
|
|
||||||
public void setCodecType(int codecType) {
|
|
||||||
mCodecTypeNative = codecType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodecType(@Nullable BluetoothCodecType codecType) {
|
public void setCodecType(@Nullable BluetoothCodecType codecType) {
|
||||||
mCodecType = codecType;
|
mCodecType = codecType;
|
||||||
}
|
}
|
||||||
@@ -82,6 +76,7 @@ public class BluetoothA2dpConfigStore {
|
|||||||
public BluetoothCodecConfig createCodecConfig() {
|
public BluetoothCodecConfig createCodecConfig() {
|
||||||
BluetoothCodecConfig.Builder builder = new BluetoothCodecConfig.Builder()
|
BluetoothCodecConfig.Builder builder = new BluetoothCodecConfig.Builder()
|
||||||
.setCodecPriority(mCodecPriority)
|
.setCodecPriority(mCodecPriority)
|
||||||
|
.setExtendedCodecType(mCodecType)
|
||||||
.setSampleRate(mSampleRate)
|
.setSampleRate(mSampleRate)
|
||||||
.setBitsPerSample(mBitsPerSample)
|
.setBitsPerSample(mBitsPerSample)
|
||||||
.setChannelMode(mChannelMode)
|
.setChannelMode(mChannelMode)
|
||||||
@@ -89,27 +84,6 @@ public class BluetoothA2dpConfigStore {
|
|||||||
.setCodecSpecific2(mCodecSpecific2Value)
|
.setCodecSpecific2(mCodecSpecific2Value)
|
||||||
.setCodecSpecific3(mCodecSpecific3Value)
|
.setCodecSpecific3(mCodecSpecific3Value)
|
||||||
.setCodecSpecific4(mCodecSpecific4Value);
|
.setCodecSpecific4(mCodecSpecific4Value);
|
||||||
if (Flags.a2dpOffloadCodecExtensibilitySettings()) {
|
|
||||||
builder.setExtendedCodecType(mCodecType);
|
|
||||||
} else {
|
|
||||||
builder.setCodecType(mCodecTypeNative);
|
|
||||||
}
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create codec config utilizing {@link BluetoothCodecType} */
|
|
||||||
@FlaggedApi(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public @NonNull BluetoothCodecConfig createCodecConfigFromCodecType() {
|
|
||||||
return new BluetoothCodecConfig.Builder()
|
|
||||||
.setExtendedCodecType(mCodecType)
|
|
||||||
.setCodecPriority(mCodecPriority)
|
|
||||||
.setSampleRate(mSampleRate)
|
|
||||||
.setBitsPerSample(mBitsPerSample)
|
|
||||||
.setChannelMode(mChannelMode)
|
|
||||||
.setCodecSpecific1(mCodecSpecific1Value)
|
|
||||||
.setCodecSpecific2(mCodecSpecific2Value)
|
|
||||||
.setCodecSpecific3(mCodecSpecific3Value)
|
|
||||||
.setCodecSpecific4(mCodecSpecific4Value)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -67,7 +67,6 @@ import com.android.settings.development.bluetooth.AbstractBluetoothDialogPrefere
|
|||||||
import com.android.settings.development.bluetooth.AbstractBluetoothPreferenceController;
|
import com.android.settings.development.bluetooth.AbstractBluetoothPreferenceController;
|
||||||
import com.android.settings.development.bluetooth.BluetoothBitPerSampleDialogPreferenceController;
|
import com.android.settings.development.bluetooth.BluetoothBitPerSampleDialogPreferenceController;
|
||||||
import com.android.settings.development.bluetooth.BluetoothChannelModeDialogPreferenceController;
|
import com.android.settings.development.bluetooth.BluetoothChannelModeDialogPreferenceController;
|
||||||
import com.android.settings.development.bluetooth.BluetoothCodecDialogPreferenceController;
|
|
||||||
import com.android.settings.development.bluetooth.BluetoothCodecListPreferenceController;
|
import com.android.settings.development.bluetooth.BluetoothCodecListPreferenceController;
|
||||||
import com.android.settings.development.bluetooth.BluetoothHDAudioPreferenceController;
|
import com.android.settings.development.bluetooth.BluetoothHDAudioPreferenceController;
|
||||||
import com.android.settings.development.bluetooth.BluetoothQualityDialogPreferenceController;
|
import com.android.settings.development.bluetooth.BluetoothQualityDialogPreferenceController;
|
||||||
@@ -813,8 +812,6 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
controllers.add(new AutofillCategoryController(context, lifecycle));
|
controllers.add(new AutofillCategoryController(context, lifecycle));
|
||||||
controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle));
|
controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle));
|
||||||
controllers.add(new AutofillResetOptionsPreferenceController(context));
|
controllers.add(new AutofillResetOptionsPreferenceController(context));
|
||||||
controllers.add(new BluetoothCodecDialogPreferenceController(context, lifecycle,
|
|
||||||
bluetoothA2dpConfigStore, fragment));
|
|
||||||
controllers.add(
|
controllers.add(
|
||||||
new BluetoothCodecListPreferenceController(
|
new BluetoothCodecListPreferenceController(
|
||||||
context, lifecycle, bluetoothA2dpConfigStore, fragment));
|
context, lifecycle, bluetoothA2dpConfigStore, fragment));
|
||||||
@@ -849,8 +846,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
@Override
|
@Override
|
||||||
public void onBluetoothCodecChanged() {
|
public void onBluetoothCodecChanged() {
|
||||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||||
if (controller instanceof AbstractBluetoothDialogPreferenceController
|
if (controller instanceof AbstractBluetoothDialogPreferenceController) {
|
||||||
&& !(controller instanceof BluetoothCodecDialogPreferenceController)) {
|
|
||||||
((AbstractBluetoothDialogPreferenceController) controller)
|
((AbstractBluetoothDialogPreferenceController) controller)
|
||||||
.onBluetoothCodecUpdated();
|
.onBluetoothCodecUpdated();
|
||||||
}
|
}
|
||||||
|
@@ -118,7 +118,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
|
|||||||
if (config == null) {
|
if (config == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mBluetoothA2dpConfigStore.setCodecType(config.getCodecType());
|
mBluetoothA2dpConfigStore.setCodecType(config.getExtendedCodecType());
|
||||||
mBluetoothA2dpConfigStore.setSampleRate(config.getSampleRate());
|
mBluetoothA2dpConfigStore.setSampleRate(config.getSampleRate());
|
||||||
mBluetoothA2dpConfigStore.setBitsPerSample(config.getBitsPerSample());
|
mBluetoothA2dpConfigStore.setBitsPerSample(config.getBitsPerSample());
|
||||||
mBluetoothA2dpConfigStore.setChannelMode(config.getChannelMode());
|
mBluetoothA2dpConfigStore.setChannelMode(config.getChannelMode());
|
||||||
|
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.development.bluetooth;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.widget.RadioGroup;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dialog preference to set the Bluetooth A2DP config of codec
|
|
||||||
*/
|
|
||||||
public class BluetoothCodecDialogPreference extends BaseBluetoothDialogPreference implements
|
|
||||||
RadioGroup.OnCheckedChangeListener {
|
|
||||||
|
|
||||||
public BluetoothCodecDialogPreference(Context context) {
|
|
||||||
super(context);
|
|
||||||
initialize(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BluetoothCodecDialogPreference(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
initialize(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BluetoothCodecDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
initialize(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BluetoothCodecDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
|
||||||
int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
initialize(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getRadioButtonGroupId() {
|
|
||||||
return R.id.bluetooth_audio_codec_radio_group;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialize(Context context) {
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_default);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_sbc);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_aac);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx_hd);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_ldac);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_lc3);
|
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_opus);
|
|
||||||
String[] stringArray = context.getResources().getStringArray(
|
|
||||||
com.android.settingslib.R.array.bluetooth_a2dp_codec_titles);
|
|
||||||
for (int i = 0; i < stringArray.length; i++) {
|
|
||||||
mRadioButtonStrings.add(stringArray[i]);
|
|
||||||
}
|
|
||||||
stringArray = context.getResources()
|
|
||||||
.getStringArray(com.android.settingslib.R.array.bluetooth_a2dp_codec_summaries);
|
|
||||||
for (int i = 0; i < stringArray.length; i++) {
|
|
||||||
mSummaryStrings.add(stringArray[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,207 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.development.bluetooth;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothA2dp;
|
|
||||||
import android.bluetooth.BluetoothCodecConfig;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.development.BluetoothA2dpConfigStore;
|
|
||||||
import com.android.settings.development.Flags;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dialog preference controller to set the Bluetooth A2DP config of codec
|
|
||||||
*/
|
|
||||||
public class BluetoothCodecDialogPreferenceController extends
|
|
||||||
AbstractBluetoothDialogPreferenceController {
|
|
||||||
|
|
||||||
private static final String KEY = "bluetooth_audio_codec_settings";
|
|
||||||
private static final String TAG = "BtCodecCtr";
|
|
||||||
|
|
||||||
@Nullable private final Callback mCallback;
|
|
||||||
|
|
||||||
public BluetoothCodecDialogPreferenceController(Context context, Lifecycle lifecycle,
|
|
||||||
BluetoothA2dpConfigStore store,
|
|
||||||
@Nullable Callback callback) {
|
|
||||||
super(context, lifecycle, store);
|
|
||||||
mCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return !Flags.a2dpOffloadCodecExtensibilitySettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
((BaseBluetoothDialogPreference) mPreference).setCallback(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Integer> getSelectableIndex() {
|
|
||||||
List<Integer> index = new ArrayList<>();
|
|
||||||
final BluetoothA2dp bluetoothA2dp = mBluetoothA2dp;
|
|
||||||
|
|
||||||
index.add(getDefaultIndex());
|
|
||||||
if (bluetoothA2dp == null) {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
final BluetoothDevice activeDevice = getA2dpActiveDevice();
|
|
||||||
if (activeDevice == null) {
|
|
||||||
Log.d(TAG, "Unable to get selectable index. No Active Bluetooth device");
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
// Check HD audio is enabled, display the available list.
|
|
||||||
if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
|
|
||||||
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
|
|
||||||
List<BluetoothCodecConfig> configs = getSelectableConfigs(activeDevice);
|
|
||||||
if (configs != null) {
|
|
||||||
return getIndexFromConfig(configs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If HD audio is disabled, SBC is the only one available codec.
|
|
||||||
index.add(convertCfgToBtnIndex(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC));
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void writeConfigurationValues(final int index) {
|
|
||||||
int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; // default
|
|
||||||
int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
|
|
||||||
switch (index) {
|
|
||||||
case 0:
|
|
||||||
final BluetoothDevice activeDevice = getA2dpActiveDevice();
|
|
||||||
codecTypeValue = getHighestCodec(mBluetoothA2dp, activeDevice,
|
|
||||||
getSelectableConfigs(activeDevice));
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS;
|
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mBluetoothA2dpConfigStore.setCodecType(codecTypeValue);
|
|
||||||
mBluetoothA2dpConfigStore.setCodecPriority(codecPriorityValue);
|
|
||||||
|
|
||||||
// Once user changes codec, to reset configs with highest quality.
|
|
||||||
final BluetoothCodecConfig config = getSelectableByCodecType(codecTypeValue);
|
|
||||||
if (config == null) {
|
|
||||||
Log.d(TAG, "Selectable config is null. Unable to reset");
|
|
||||||
}
|
|
||||||
mBluetoothA2dpConfigStore.setSampleRate(getHighestSampleRate(config));
|
|
||||||
mBluetoothA2dpConfigStore.setBitsPerSample(getHighestBitsPerSample(config));
|
|
||||||
mBluetoothA2dpConfigStore.setChannelMode(getHighestChannelMode(config));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getCurrentIndexByConfig(BluetoothCodecConfig config) {
|
|
||||||
if (config == null) {
|
|
||||||
Log.e(TAG, "Unable to get current config index. Config is null.");
|
|
||||||
}
|
|
||||||
return convertCfgToBtnIndex(config.getCodecType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onIndexUpdated(int index) {
|
|
||||||
super.onIndexUpdated(index);
|
|
||||||
mCallback.onBluetoothCodecChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHDAudioEnabled(boolean enabled) {
|
|
||||||
writeConfigurationValues(/* index= */ 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Integer> getIndexFromConfig(List<BluetoothCodecConfig> configs) {
|
|
||||||
List<Integer> indexArray = new ArrayList<>();
|
|
||||||
for (BluetoothCodecConfig config : configs) {
|
|
||||||
indexArray.add(convertCfgToBtnIndex(config.getCodecType()));
|
|
||||||
}
|
|
||||||
return indexArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
int convertCfgToBtnIndex(int config) {
|
|
||||||
int index = getDefaultIndex();
|
|
||||||
switch (config) {
|
|
||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC:
|
|
||||||
index = 1;
|
|
||||||
break;
|
|
||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC:
|
|
||||||
index = 2;
|
|
||||||
break;
|
|
||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX:
|
|
||||||
index = 3;
|
|
||||||
break;
|
|
||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD:
|
|
||||||
index = 4;
|
|
||||||
break;
|
|
||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
|
|
||||||
index = 5;
|
|
||||||
break;
|
|
||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS:
|
|
||||||
index = 7;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Log.e(TAG, "Unsupported config:" + config);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -32,7 +32,6 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.development.BluetoothA2dpConfigStore;
|
import com.android.settings.development.BluetoothA2dpConfigStore;
|
||||||
import com.android.settings.development.Flags;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -62,9 +61,7 @@ public class BluetoothCodecListPreferenceController extends AbstractBluetoothPre
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
boolean available = Flags.a2dpOffloadCodecExtensibilitySettings();
|
return true;
|
||||||
Log.d(TAG, "isAvailable: " + available);
|
|
||||||
return available;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,10 +77,6 @@ public class BluetoothCodecListPreferenceController extends AbstractBluetoothPre
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(@Nullable Preference preference, @NonNull Object newValue) {
|
public boolean onPreferenceChange(@Nullable Preference preference, @NonNull Object newValue) {
|
||||||
if (!Flags.a2dpOffloadCodecExtensibilitySettings()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mListPreference == null) {
|
if (mListPreference == null) {
|
||||||
Log.e(TAG, "onPreferenceChange: List preference is null");
|
Log.e(TAG, "onPreferenceChange: List preference is null");
|
||||||
return false;
|
return false;
|
||||||
@@ -115,7 +108,7 @@ public class BluetoothCodecListPreferenceController extends AbstractBluetoothPre
|
|||||||
}
|
}
|
||||||
|
|
||||||
BluetoothCodecConfig codecConfig =
|
BluetoothCodecConfig codecConfig =
|
||||||
mBluetoothA2dpConfigStore.createCodecConfigFromCodecType();
|
mBluetoothA2dpConfigStore.createCodecConfig();
|
||||||
Log.d(TAG, "onPreferenceChange: setCodecConfigPreference: " + codecConfig.toString());
|
Log.d(TAG, "onPreferenceChange: setCodecConfigPreference: " + codecConfig.toString());
|
||||||
bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig);
|
bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig);
|
||||||
if (mCallback != null) {
|
if (mCallback != null) {
|
||||||
@@ -128,9 +121,6 @@ public class BluetoothCodecListPreferenceController extends AbstractBluetoothPre
|
|||||||
@Override
|
@Override
|
||||||
public void updateState(@Nullable Preference preference) {
|
public void updateState(@Nullable Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
if (!Flags.a2dpOffloadCodecExtensibilitySettings()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isHDAudioEnabled()) {
|
if (!isHDAudioEnabled()) {
|
||||||
Log.d(TAG, "updateState: HD Audio is disabled");
|
Log.d(TAG, "updateState: HD Audio is disabled");
|
||||||
|
@@ -220,7 +220,7 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
|||||||
mActiveDevice)).thenReturn(mCodecStatus);
|
mActiveDevice)).thenReturn(mCodecStatus);
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecConfigAAC.getCodecType());
|
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecConfigAAC.getExtendedCodecType());
|
||||||
verify(mBluetoothA2dpConfigStore).setSampleRate(mCodecConfigAAC.getSampleRate());
|
verify(mBluetoothA2dpConfigStore).setSampleRate(mCodecConfigAAC.getSampleRate());
|
||||||
verify(mBluetoothA2dpConfigStore).setBitsPerSample(mCodecConfigAAC.getBitsPerSample());
|
verify(mBluetoothA2dpConfigStore).setBitsPerSample(mCodecConfigAAC.getBitsPerSample());
|
||||||
verify(mBluetoothA2dpConfigStore).setChannelMode(mCodecConfigAAC.getChannelMode());
|
verify(mBluetoothA2dpConfigStore).setChannelMode(mCodecConfigAAC.getChannelMode());
|
||||||
|
@@ -1,279 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.development.bluetooth;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
|
||||||
import static org.mockito.Mockito.eq;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothA2dp;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothCodecConfig;
|
|
||||||
import android.bluetooth.BluetoothCodecStatus;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.development.BluetoothA2dpConfigStore;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class BluetoothCodecDialogPreferenceControllerTest {
|
|
||||||
|
|
||||||
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private BluetoothA2dp mBluetoothA2dp;
|
|
||||||
@Mock
|
|
||||||
private BluetoothAdapter mBluetoothAdapter;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
@Mock
|
|
||||||
private AbstractBluetoothPreferenceController.Callback mCallback;
|
|
||||||
|
|
||||||
private BluetoothCodecDialogPreferenceController mController;
|
|
||||||
private BluetoothCodecDialogPreference mPreference;
|
|
||||||
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
|
||||||
private BluetoothCodecStatus mCodecStatus;
|
|
||||||
private BluetoothCodecConfig mCodecConfigAAC;
|
|
||||||
private BluetoothCodecConfig mCodecConfigSBC;
|
|
||||||
private BluetoothCodecConfig mCodecConfigAPTX;
|
|
||||||
private BluetoothCodecConfig mCodecConfigAPTXHD;
|
|
||||||
private BluetoothCodecConfig mCodecConfigLDAC;
|
|
||||||
private BluetoothCodecConfig mCodecConfigOPUS;
|
|
||||||
private BluetoothDevice mActiveDevice;
|
|
||||||
private Context mContext;
|
|
||||||
private LifecycleOwner mLifecycleOwner;
|
|
||||||
private Lifecycle mLifecycle;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
|
||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
|
||||||
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
|
|
||||||
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
|
|
||||||
mController = new BluetoothCodecDialogPreferenceController(mContext, mLifecycle,
|
|
||||||
mBluetoothA2dpConfigStore, mCallback);
|
|
||||||
mController.mBluetoothAdapter = mBluetoothAdapter;
|
|
||||||
mPreference = new BluetoothCodecDialogPreference(mContext);
|
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mCodecConfigSBC = new BluetoothCodecConfig.Builder()
|
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
|
|
||||||
.setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST)
|
|
||||||
.setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000
|
|
||||||
| BluetoothCodecConfig.SAMPLE_RATE_176400)
|
|
||||||
.setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_32)
|
|
||||||
.setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_MONO
|
|
||||||
| BluetoothCodecConfig.CHANNEL_MODE_STEREO)
|
|
||||||
.build();
|
|
||||||
mCodecConfigAAC = new BluetoothCodecConfig.Builder()
|
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
|
|
||||||
.setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST)
|
|
||||||
.setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000
|
|
||||||
| BluetoothCodecConfig.SAMPLE_RATE_88200)
|
|
||||||
.setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16
|
|
||||||
| BluetoothCodecConfig.BITS_PER_SAMPLE_24)
|
|
||||||
.setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_STEREO)
|
|
||||||
.build();
|
|
||||||
mCodecConfigAPTX = new BluetoothCodecConfig.Builder()
|
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX)
|
|
||||||
.build();
|
|
||||||
mCodecConfigAPTXHD = new BluetoothCodecConfig.Builder()
|
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD)
|
|
||||||
.build();
|
|
||||||
mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
|
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
|
|
||||||
.build();
|
|
||||||
mCodecConfigOPUS = new BluetoothCodecConfig.Builder()
|
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS)
|
|
||||||
.build();
|
|
||||||
when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
|
|
||||||
.thenReturn(Arrays.asList(mActiveDevice));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void writeConfigurationValues_selectDefault_setHighest() {
|
|
||||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigOPUS, mCodecConfigAAC,
|
|
||||||
mCodecConfigSBC};
|
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
|
||||||
.setCodecConfig(mCodecConfigSBC)
|
|
||||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
|
||||||
.build();
|
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
|
||||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
|
||||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
|
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(0);
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(
|
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void writeConfigurationValues_checkCodec() {
|
|
||||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigOPUS, mCodecConfigAAC,
|
|
||||||
mCodecConfigSBC, mCodecConfigAPTX, mCodecConfigAPTXHD, mCodecConfigLDAC};
|
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
|
||||||
.setCodecConfig(mCodecConfigSBC)
|
|
||||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
|
||||||
.build();
|
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(1);
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecType(
|
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(2);
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(3);
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(4);
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(
|
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(5);
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);
|
|
||||||
|
|
||||||
mController.writeConfigurationValues(7);
|
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(
|
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void writeConfigurationValues_resetHighestConfig() {
|
|
||||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
|
|
||||||
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigOPUS};
|
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
|
||||||
.setCodecConfig(mCodecConfigAAC)
|
|
||||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
|
||||||
.build();
|
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
mController.writeConfigurationValues(2);
|
|
||||||
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecPriority(
|
|
||||||
BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST);
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setSampleRate(
|
|
||||||
BluetoothCodecConfig.SAMPLE_RATE_88200);
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setBitsPerSample(
|
|
||||||
BluetoothCodecConfig.BITS_PER_SAMPLE_24);
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setChannelMode(
|
|
||||||
BluetoothCodecConfig.CHANNEL_MODE_STEREO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getCurrentIndexByConfig_verifyIndex() {
|
|
||||||
assertThat(mController.getCurrentIndexByConfig(mCodecConfigAAC)).isEqualTo(
|
|
||||||
mController.convertCfgToBtnIndex(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getCurrentIndexByConfig_verifyOpusIndex() {
|
|
||||||
assertThat(mController.getCurrentIndexByConfig(mCodecConfigOPUS)).isEqualTo(
|
|
||||||
mController.convertCfgToBtnIndex(
|
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onIndexUpdated_notifyPreference() {
|
|
||||||
mController.onIndexUpdated(0);
|
|
||||||
|
|
||||||
verify(mCallback).onBluetoothCodecChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsOpus() {
|
|
||||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
|
|
||||||
mCodecConfigAAC, mCodecConfigSBC);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
|
||||||
.setCodecConfig(mCodecConfigOPUS)
|
|
||||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
|
||||||
.build();
|
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
|
||||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
|
||||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
|
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
|
|
||||||
mController.onHDAudioEnabled(/* enabled= */ true);
|
|
||||||
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecType(
|
|
||||||
eq(BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
|
|
||||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
|
|
||||||
mCodecConfigAAC, mCodecConfigSBC);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
|
||||||
.setCodecConfig(mCodecConfigAAC)
|
|
||||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
|
||||||
.build();
|
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
|
||||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
|
||||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
|
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
|
|
||||||
mController.onHDAudioEnabled(/* enabled= */ true);
|
|
||||||
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecType(
|
|
||||||
eq(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC));
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
|
|
||||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
|
|
||||||
mCodecConfigAAC, mCodecConfigSBC);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
|
||||||
.setCodecConfig(mCodecConfigAAC)
|
|
||||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
|
||||||
.build();
|
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
|
||||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
|
||||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
|
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
|
|
||||||
mController.onHDAudioEnabled(/* enabled= */ false);
|
|
||||||
|
|
||||||
verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecType(
|
|
||||||
eq(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.development.bluetooth;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class BluetoothCodecDialogPreferenceTest {
|
|
||||||
|
|
||||||
private BluetoothCodecDialogPreference mPreference;
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mPreference = new BluetoothCodecDialogPreference(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getRadioButtonGroupId() {
|
|
||||||
assertThat(mPreference.getRadioButtonGroupId())
|
|
||||||
.isEqualTo(R.id.bluetooth_audio_codec_radio_group);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -18,7 +18,6 @@ package com.android.settings.development.bluetooth;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
@@ -35,14 +34,12 @@ import android.bluetooth.BluetoothCodecType;
|
|||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.platform.test.annotations.EnableFlags;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.development.BluetoothA2dpConfigStore;
|
import com.android.settings.development.BluetoothA2dpConfigStore;
|
||||||
import com.android.settings.development.Flags;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -73,6 +70,7 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
private BluetoothCodecType mCodecTypeAAC;
|
private BluetoothCodecType mCodecTypeAAC;
|
||||||
private BluetoothCodecType mCodecTypeSBC;
|
private BluetoothCodecType mCodecTypeSBC;
|
||||||
private BluetoothCodecType mCodecTypeAPTX;
|
private BluetoothCodecType mCodecTypeAPTX;
|
||||||
|
private BluetoothCodecType mCodecTypeAPTXHD;
|
||||||
private BluetoothCodecType mCodecTypeLDAC;
|
private BluetoothCodecType mCodecTypeLDAC;
|
||||||
private BluetoothCodecType mCodecTypeOPUS;
|
private BluetoothCodecType mCodecTypeOPUS;
|
||||||
private List<BluetoothCodecType> mCodecTypes;
|
private List<BluetoothCodecType> mCodecTypes;
|
||||||
@@ -114,6 +112,8 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
|
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
|
||||||
mCodecTypeAPTX =
|
mCodecTypeAPTX =
|
||||||
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX);
|
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX);
|
||||||
|
mCodecTypeAPTXHD =
|
||||||
|
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD);
|
||||||
mCodecTypeLDAC =
|
mCodecTypeLDAC =
|
||||||
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);
|
BluetoothCodecType.createFromType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);
|
||||||
mCodecTypeOPUS =
|
mCodecTypeOPUS =
|
||||||
@@ -125,6 +125,7 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
mCodecTypeSBC,
|
mCodecTypeSBC,
|
||||||
mCodecTypeAAC,
|
mCodecTypeAAC,
|
||||||
mCodecTypeAPTX,
|
mCodecTypeAPTX,
|
||||||
|
mCodecTypeAPTXHD,
|
||||||
mCodecTypeLDAC,
|
mCodecTypeLDAC,
|
||||||
mCodecTypeOPUS));
|
mCodecTypeOPUS));
|
||||||
|
|
||||||
@@ -212,6 +213,11 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
mController.writeConfigurationValues(String.valueOf(mCodecTypeAPTX.getCodecId())));
|
mController.writeConfigurationValues(String.valueOf(mCodecTypeAPTX.getCodecId())));
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecTypeAPTX);
|
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecTypeAPTX);
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
mController.writeConfigurationValues(String.valueOf(
|
||||||
|
mCodecTypeAPTXHD.getCodecId())));
|
||||||
|
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecTypeAPTXHD);
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
mController.writeConfigurationValues(String.valueOf(mCodecTypeLDAC.getCodecId())));
|
mController.writeConfigurationValues(String.valueOf(mCodecTypeLDAC.getCodecId())));
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecTypeLDAC);
|
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecTypeLDAC);
|
||||||
@@ -244,7 +250,6 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public void onPreferenceChange_notifyPreference() {
|
public void onPreferenceChange_notifyPreference() {
|
||||||
assertFalse(
|
assertFalse(
|
||||||
mController.onPreferenceChange(
|
mController.onPreferenceChange(
|
||||||
@@ -271,7 +276,6 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public void onPreferenceChange_listPreferenceIsNull() {
|
public void onPreferenceChange_listPreferenceIsNull() {
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(null);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(null);
|
||||||
assertFalse(
|
assertFalse(
|
||||||
@@ -280,13 +284,11 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public void onPreferenceChange_unknownCodecId() {
|
public void onPreferenceChange_unknownCodecId() {
|
||||||
assertFalse(mController.onPreferenceChange(mPreference, String.valueOf(TEST_ENTRY_VALUE)));
|
assertFalse(mController.onPreferenceChange(mPreference, String.valueOf(TEST_ENTRY_VALUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public void onPreferenceChange_codecSelection() {
|
public void onPreferenceChange_codecSelection() {
|
||||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice))
|
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice))
|
||||||
@@ -325,6 +327,14 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
assertTrue(
|
assertTrue(
|
||||||
mController.onPreferenceChange(
|
mController.onPreferenceChange(
|
||||||
mPreference, String.valueOf(mCodecTypeAPTX.getCodecId())));
|
mPreference, String.valueOf(mCodecTypeAPTX.getCodecId())));
|
||||||
|
mCodecStatus =
|
||||||
|
new BluetoothCodecStatus.Builder()
|
||||||
|
.setCodecConfig(mCodecConfigAPTXHD)
|
||||||
|
.setCodecsSelectableCapabilities(mCodecConfigs)
|
||||||
|
.build();
|
||||||
|
assertTrue(
|
||||||
|
mController.onPreferenceChange(
|
||||||
|
mPreference, String.valueOf(mCodecTypeAPTXHD.getCodecId())));
|
||||||
mCodecStatus =
|
mCodecStatus =
|
||||||
new BluetoothCodecStatus.Builder()
|
new BluetoothCodecStatus.Builder()
|
||||||
.setCodecConfig(mCodecConfigOPUS)
|
.setCodecConfig(mCodecConfigOPUS)
|
||||||
@@ -336,7 +346,6 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public void updateState_notifyPreference() {
|
public void updateState_notifyPreference() {
|
||||||
assertFalse(
|
assertFalse(
|
||||||
mController.onPreferenceChange(
|
mController.onPreferenceChange(
|
||||||
@@ -437,7 +446,6 @@ public class BluetoothCodecListPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
|
|
||||||
public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
|
public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
|
||||||
mCodecStatus =
|
mCodecStatus =
|
||||||
new BluetoothCodecStatus.Builder()
|
new BluetoothCodecStatus.Builder()
|
||||||
|
Reference in New Issue
Block a user