[hearing devices page][Audio routing] Add feature flag to control visibility of the hearing device controls and audio output
* Setup basic xml for hearing device controls and audio output in bluetooth detail device page. * Use same PreferenceCategory with spatial audio and rename to `feature_controls_group` Bug: 237625815 Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsHearingDeviceControlsControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsAudioRoutingControllerTest Change-Id: Ibe71757b53b9d65c6ab6efa1053d035e78882b68
This commit is contained in:
@@ -71,7 +71,7 @@
|
|||||||
android:key="device_companion_apps"/>
|
android:key="device_companion_apps"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="spatial_audio_group"/>
|
android:key="feature_controls_group"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="bluetooth_profiles"/>
|
android:key="bluetooth_profiles"/>
|
||||||
|
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.bluetooth;
|
||||||
|
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDeviceDetailsFragment.FEATURE_AUDIO_ROUTING_ORDER;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller of the audio routing in the bluetooth detail settings.
|
||||||
|
*/
|
||||||
|
public class BluetoothDetailsAudioRoutingController extends BluetoothDetailsController {
|
||||||
|
|
||||||
|
private static final String KEY_FEATURE_CONTROLS_GROUP = "feature_controls_group";
|
||||||
|
private static final String KEY_AUDIO_ROUTING = "audio_routing";
|
||||||
|
|
||||||
|
public BluetoothDetailsAudioRoutingController(Context context,
|
||||||
|
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||||
|
super(context, fragment, device, lifecycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mCachedDevice.isHearingAidDevice() && FeatureFlagUtils.isEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(PreferenceScreen screen) {
|
||||||
|
if (!mCachedDevice.isHearingAidDevice()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final PreferenceCategory prefCategory = screen.findPreference(getPreferenceKey());
|
||||||
|
final Preference pref = createAudioRoutingPreference(prefCategory.getContext());
|
||||||
|
pref.setOrder(FEATURE_AUDIO_ROUTING_ORDER);
|
||||||
|
prefCategory.addPreference(pref);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void refresh() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_FEATURE_CONTROLS_GROUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Preference createAudioRoutingPreference(Context context) {
|
||||||
|
final Preference preference = new Preference(context);
|
||||||
|
preference.setKey(KEY_AUDIO_ROUTING);
|
||||||
|
preference.setTitle(context.getString(R.string.bluetooth_audio_routing_title));
|
||||||
|
preference.setSummary(context.getString(R.string.bluetooth_audio_routing_summary));
|
||||||
|
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.bluetooth;
|
||||||
|
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDeviceDetailsFragment.FEATURE_HEARING_DEVICE_CONTROLS_ORDER;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller of the hearing device controls in the bluetooth detail settings.
|
||||||
|
*/
|
||||||
|
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController {
|
||||||
|
|
||||||
|
private static final String KEY_FEATURE_CONTROLS_GROUP = "feature_controls_group";
|
||||||
|
private static final String KEY_HEARING_DEVICE_CONTROLS = "hearing_device_controls";
|
||||||
|
|
||||||
|
public BluetoothDetailsHearingDeviceControlsController(Context context,
|
||||||
|
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||||
|
super(context, fragment, device, lifecycle);
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mCachedDevice.isHearingAidDevice() && FeatureFlagUtils.isEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(PreferenceScreen screen) {
|
||||||
|
if (!mCachedDevice.isHearingAidDevice()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final PreferenceCategory prefCategory = screen.findPreference(getPreferenceKey());
|
||||||
|
final Preference pref = createHearingDeviceControlsPreference(prefCategory.getContext());
|
||||||
|
pref.setOrder(FEATURE_HEARING_DEVICE_CONTROLS_ORDER);
|
||||||
|
prefCategory.addPreference(pref);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void refresh() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_FEATURE_CONTROLS_GROUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Preference createHearingDeviceControlsPreference(Context context) {
|
||||||
|
final Preference preference = new Preference(context);
|
||||||
|
preference.setKey(KEY_HEARING_DEVICE_CONTROLS);
|
||||||
|
preference.setTitle(context.getString(R.string.bluetooth_device_controls_title));
|
||||||
|
preference.setSummary(context.getString(R.string.bluetooth_device_controls_summary));
|
||||||
|
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDeviceDetailsFragment.FEATURE_HEAD_TRACKING_ORDER;
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDeviceDetailsFragment.FEATURE_SPATIAL_AUDIO_ORDER;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioDeviceAttributes;
|
import android.media.AudioDeviceAttributes;
|
||||||
import android.media.AudioDeviceInfo;
|
import android.media.AudioDeviceInfo;
|
||||||
@@ -42,7 +45,7 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
|||||||
implements Preference.OnPreferenceClickListener {
|
implements Preference.OnPreferenceClickListener {
|
||||||
|
|
||||||
private static final String TAG = "BluetoothSpatialAudioController";
|
private static final String TAG = "BluetoothSpatialAudioController";
|
||||||
private static final String KEY_SPATIAL_AUDIO_GROUP = "spatial_audio_group";
|
private static final String KEY_FEATURE_CONTROLS_GROUP = "feature_controls_group";
|
||||||
private static final String KEY_SPATIAL_AUDIO = "spatial_audio";
|
private static final String KEY_SPATIAL_AUDIO = "spatial_audio";
|
||||||
private static final String KEY_HEAD_TRACKING = "head_tracking";
|
private static final String KEY_HEAD_TRACKING = "head_tracking";
|
||||||
|
|
||||||
@@ -95,13 +98,12 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_SPATIAL_AUDIO_GROUP;
|
return KEY_FEATURE_CONTROLS_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init(PreferenceScreen screen) {
|
protected void init(PreferenceScreen screen) {
|
||||||
mProfilesContainer = screen.findPreference(getPreferenceKey());
|
mProfilesContainer = screen.findPreference(getPreferenceKey());
|
||||||
mProfilesContainer.setLayoutResource(R.layout.preference_bluetooth_profile_category);
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +112,7 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
|||||||
SwitchPreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO);
|
SwitchPreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO);
|
||||||
if (spatialAudioPref == null) {
|
if (spatialAudioPref == null) {
|
||||||
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
|
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
|
||||||
|
spatialAudioPref.setOrder(FEATURE_SPATIAL_AUDIO_ORDER);
|
||||||
mProfilesContainer.addPreference(spatialAudioPref);
|
mProfilesContainer.addPreference(spatialAudioPref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +123,7 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
|||||||
SwitchPreference headTrackingPref = mProfilesContainer.findPreference(KEY_HEAD_TRACKING);
|
SwitchPreference headTrackingPref = mProfilesContainer.findPreference(KEY_HEAD_TRACKING);
|
||||||
if (headTrackingPref == null) {
|
if (headTrackingPref == null) {
|
||||||
headTrackingPref = createHeadTrackingPreference(mProfilesContainer.getContext());
|
headTrackingPref = createHeadTrackingPreference(mProfilesContainer.getContext());
|
||||||
|
headTrackingPref.setOrder(FEATURE_HEAD_TRACKING_ORDER);
|
||||||
mProfilesContainer.addPreference(headTrackingPref);
|
mProfilesContainer.addPreference(headTrackingPref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,6 +63,11 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
|||||||
public static final String KEY_DEVICE_ADDRESS = "device_address";
|
public static final String KEY_DEVICE_ADDRESS = "device_address";
|
||||||
private static final String TAG = "BTDeviceDetailsFrg";
|
private static final String TAG = "BTDeviceDetailsFrg";
|
||||||
|
|
||||||
|
static final int FEATURE_HEARING_DEVICE_CONTROLS_ORDER = 1;
|
||||||
|
static final int FEATURE_AUDIO_ROUTING_ORDER = 2;
|
||||||
|
static final int FEATURE_SPATIAL_AUDIO_ORDER = 3;
|
||||||
|
static final int FEATURE_HEAD_TRACKING_ORDER = 4;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static int EDIT_DEVICE_NAME_ITEM_ID = Menu.FIRST;
|
static int EDIT_DEVICE_NAME_ITEM_ID = Menu.FIRST;
|
||||||
|
|
||||||
@@ -312,6 +317,10 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
|||||||
lifecycle));
|
lifecycle));
|
||||||
controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
|
controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
|
||||||
lifecycle));
|
lifecycle));
|
||||||
|
controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
|
||||||
|
mCachedDevice, lifecycle));
|
||||||
|
controllers.add(new BluetoothDetailsAudioRoutingController(context, this, mCachedDevice,
|
||||||
|
lifecycle));
|
||||||
}
|
}
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.bluetooth;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
/** Tests for {@link BluetoothDetailsAudioRoutingController}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class BluetoothDetailsAudioRoutingControllerTest extends
|
||||||
|
BluetoothDetailsControllerTestBase {
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
private BluetoothDetailsAudioRoutingController mController;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() {
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
mController = new BluetoothDetailsAudioRoutingController(mContext, mFragment, mCachedDevice,
|
||||||
|
mLifecycle);
|
||||||
|
mController.init(mScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_isHearingAidDevice_available() {
|
||||||
|
FeatureFlagUtils.setEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true);
|
||||||
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_isNotHearingAidDevice_notAvailable() {
|
||||||
|
FeatureFlagUtils.setEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true);
|
||||||
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.bluetooth;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
/** Tests for {@link BluetoothDetailsHearingDeviceControlsController}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class BluetoothDetailsHearingDeviceControlsControllerTest extends
|
||||||
|
BluetoothDetailsControllerTestBase {
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
private BluetoothDetailsHearingDeviceControlsController mController;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() {
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
mController = new BluetoothDetailsHearingDeviceControlsController(mContext, mFragment,
|
||||||
|
mCachedDevice, mLifecycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_isHearingAidDevice_available() {
|
||||||
|
FeatureFlagUtils.setEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE, true);
|
||||||
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_isNotHearingAidDevice_notAvailable() {
|
||||||
|
FeatureFlagUtils.setEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE, true);
|
||||||
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user