Merge "Move 'Audio Output' to Accessibility hearing device page" into udc-dev

This commit is contained in:
Jason Hsu
2023-05-12 14:20:23 +00:00
committed by Android (Google) Code Review
25 changed files with 542 additions and 619 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2023 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.accessibility;
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
import android.app.settings.SettingsEnums;
import com.android.settings.R;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
/** Settings fragment containing bluetooth audio routing. */
public class AccessibilityAudioRoutingFragment extends RestrictedDashboardFragment {
private static final String TAG = "AccessibilityAudioRoutingFragment";
public AccessibilityAudioRoutingFragment() {
super(DISALLOW_CONFIG_BLUETOOTH);
}
@Override
public int getMetricsCategory() {
return SettingsEnums.HEARING_AID_AUDIO_ROUTING;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_audio_routing_fragment;
}
@Override
protected String getLogTag() {
return TAG;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.accessibility_audio_routing_fragment);
}

View File

@@ -17,7 +17,6 @@
package com.android.settings.accessibility;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
@@ -41,20 +40,14 @@ import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Controller that shows and updates the bluetooth device name
@@ -73,10 +66,8 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
};
private final LocalBluetoothManager mLocalBluetoothManager;
private final BluetoothAdapter mBluetoothAdapter;
private final LocalBluetoothProfileManager mProfileManager;
private final CachedBluetoothDeviceManager mCachedDeviceManager;
private final HearingAidHelper mHelper;
private FragmentManager mFragmentManager;
public AccessibilityHearingAidPreferenceController(Context context, String preferenceKey) {
@@ -84,8 +75,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
mLocalBluetoothManager = com.android.settings.bluetooth.Utils.getLocalBluetoothManager(
context);
mProfileManager = mLocalBluetoothManager.getProfileManager();
mCachedDeviceManager = mLocalBluetoothManager.getCachedDeviceManager();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mHelper = new HearingAidHelper(context);
}
@Override
@@ -96,7 +86,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public int getAvailabilityStatus() {
return isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return mHelper.isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -111,7 +101,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
// Can't get connected hearing aids when hearing aids related profiles are not ready. The
// profiles will be ready after the services are connected. Needs to add listener and
// updates the information when all hearing aids related services are connected.
if (isAnyHearingAidRelatedProfilesNotReady()) {
if (!mHelper.isAllHearingAidRelatedProfilesReady()) {
mProfileManager.addServiceListener(this);
}
}
@@ -126,7 +116,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
final CachedBluetoothDevice device = getConnectedHearingAidDevice();
final CachedBluetoothDevice device = mHelper.getConnectedHearingAidDevice();
if (FeatureFlagUtils.isEnabled(mContext,
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE)) {
launchHearingAidPage();
@@ -144,10 +134,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public CharSequence getSummary() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
}
final CachedBluetoothDevice device = getConnectedHearingAidDevice();
final CachedBluetoothDevice device = mHelper.getConnectedHearingAidDevice();
if (device == null) {
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
}
@@ -203,7 +190,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public void onServiceConnected() {
if (!isAnyHearingAidRelatedProfilesNotReady()) {
if (mHelper.isAllHearingAidRelatedProfilesReady()) {
updateState(mHearingAidPreference);
mProfileManager.removeServiceListener(this);
}
@@ -218,53 +205,8 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
mFragmentManager = fragmentManager;
}
@VisibleForTesting
CachedBluetoothDevice getConnectedHearingAidDevice() {
final List<BluetoothDevice> deviceList = getConnectedHearingAidDeviceList();
return deviceList.isEmpty() ? null : mCachedDeviceManager.findDevice(deviceList.get(0));
}
private int getConnectedHearingAidDeviceNum() {
return getConnectedHearingAidDeviceList().size();
}
private List<BluetoothDevice> getConnectedHearingAidDeviceList() {
if (!isHearingAidSupported()) {
return new ArrayList<>();
}
final List<BluetoothDevice> deviceList = new ArrayList<>();
final HapClientProfile hapClientProfile = mProfileManager.getHapClientProfile();
if (hapClientProfile != null) {
deviceList.addAll(hapClientProfile.getConnectedDevices());
}
final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
if (hearingAidProfile != null) {
deviceList.addAll(hearingAidProfile.getConnectedDevices());
}
return deviceList.stream()
.distinct()
.filter(d -> !mCachedDeviceManager.isSubDevice(d)).collect(Collectors.toList());
}
private boolean isHearingAidSupported() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return false;
}
final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
return supportedList.contains(BluetoothProfile.HEARING_AID)
|| supportedList.contains(BluetoothProfile.HAP_CLIENT);
}
private boolean isAnyHearingAidRelatedProfilesNotReady() {
HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
if (hearingAidProfile != null && !hearingAidProfile.isProfileReady()) {
return true;
}
HapClientProfile hapClientProfile = mProfileManager.getHapClientProfile();
if (hapClientProfile != null && !hapClientProfile.isProfileReady()) {
return true;
}
return false;
return mHelper.getConnectedHearingAidDeviceList().size();
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)

View File

@@ -39,7 +39,7 @@ public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPrefe
private static final String TAG = "AccessibilityHearingAidsFragment";
private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category";
private static final int FIRST_PREFERENCE_IN_CATEGORY_INDEX = -1;
private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20;
private String mFeatureName;
public AccessibilityHearingAidsFragment() {
@@ -65,7 +65,7 @@ public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPrefe
final View view = super.onCreateView(inflater, container, savedInstanceState);
final PreferenceCategory controlCategory = findPreference(KEY_HEARING_OPTIONS_CATEGORY);
// To move the shortcut preference under controlCategory need to remove the original added.
mShortcutPreference.setOrder(FIRST_PREFERENCE_IN_CATEGORY_INDEX);
mShortcutPreference.setOrder(SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX);
getPreferenceScreen().removePreference(mShortcutPreference);
controlCategory.addPreference(mShortcutPreference);
return view;

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 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.accessibility;
import android.content.Context;
import android.util.FeatureFlagUtils;
import com.android.settings.core.BasePreferenceController;
/**
* The controller of the audio routing.
*/
public class HearingAidAudioRoutingPreferenceController extends BasePreferenceController {
public HearingAidAudioRoutingPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_AUDIO_ROUTING)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2023 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.accessibility;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* A helper class to get and check hearing aids and its status.
*/
public class HearingAidHelper {
private final BluetoothAdapter mBluetoothAdapter;
private final LocalBluetoothProfileManager mProfileManager;
private final CachedBluetoothDeviceManager mCachedDeviceManager;
public HearingAidHelper(Context context) {
final LocalBluetoothManager localBluetoothManager =
com.android.settings.bluetooth.Utils.getLocalBluetoothManager(context);
mProfileManager = localBluetoothManager.getProfileManager();
mCachedDeviceManager = localBluetoothManager.getCachedDeviceManager();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
/**
* Gets the connected hearing aids device whose profiles are
* {@link BluetoothProfile#HEARING_AID} or {@link BluetoothProfile#HAP_CLIENT}.
*
* @return a list of hearing aids {@link BluetoothDevice} objects
*/
public List<BluetoothDevice> getConnectedHearingAidDeviceList() {
if (!isHearingAidSupported()) {
return new ArrayList<>();
}
final List<BluetoothDevice> deviceList = new ArrayList<>();
final HapClientProfile hapClientProfile = mProfileManager.getHapClientProfile();
if (hapClientProfile != null) {
deviceList.addAll(hapClientProfile.getConnectedDevices());
}
final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
if (hearingAidProfile != null) {
deviceList.addAll(hearingAidProfile.getConnectedDevices());
}
return deviceList.stream()
.distinct()
.filter(d -> !mCachedDeviceManager.isSubDevice(d)).collect(Collectors.toList());
}
/**
* Gets the first connected hearing aids device.
*
* @return a {@link CachedBluetoothDevice} that is hearing aids device
*/
public CachedBluetoothDevice getConnectedHearingAidDevice() {
final List<BluetoothDevice> deviceList = getConnectedHearingAidDeviceList();
return deviceList.isEmpty() ? null : mCachedDeviceManager.findDevice(deviceList.get(0));
}
/**
* Checks if {@link BluetoothProfile#HEARING_AID} or {@link BluetoothProfile#HAP_CLIENT}
* supported.
*/
public boolean isHearingAidSupported() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return false;
}
final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
return supportedList.contains(BluetoothProfile.HEARING_AID)
|| supportedList.contains(BluetoothProfile.HAP_CLIENT);
}
/**
* Checks if {@link BluetoothProfile#HEARING_AID} or {@link BluetoothProfile#HAP_CLIENT}
* profiles all ready.
*/
public boolean isAllHearingAidRelatedProfilesReady() {
HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
if (hearingAidProfile != null && !hearingAidProfile.isProfileReady()) {
return false;
}
HapClientProfile hapClientProfile = mProfileManager.getHapClientProfile();
if (hapClientProfile != null && !hapClientProfile.isProfileReady()) {
return false;
}
return true;
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
import android.content.ContentResolver;
import android.content.Context;
@@ -47,19 +47,24 @@ public abstract class HearingDeviceAudioRoutingBasePreferenceController extends
private static final String TAG = "HARoutingBasePreferenceController";
private static final boolean DEBUG = false;
private final HearingAidAudioRoutingHelper mHelper;
private final HearingAidAudioRoutingHelper mAudioRoutingHelper;
private final HearingAidHelper mHearingAidHelper;
public HearingDeviceAudioRoutingBasePreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
mHelper = new HearingAidAudioRoutingHelper(context);
this(context, preferenceKey,
new HearingAidAudioRoutingHelper(context),
new HearingAidHelper(context));
}
@VisibleForTesting
public HearingDeviceAudioRoutingBasePreferenceController(Context context,
String preferenceKey, HearingAidAudioRoutingHelper helper) {
String preferenceKey, HearingAidAudioRoutingHelper audioRoutingHelper,
HearingAidHelper hearingAidHelper) {
super(context, preferenceKey);
mHelper = helper;
mAudioRoutingHelper = audioRoutingHelper;
mHearingAidHelper = hearingAidHelper;
}
@Override
@@ -81,7 +86,11 @@ public abstract class HearingDeviceAudioRoutingBasePreferenceController extends
final Integer routingValue = Ints.tryParse((String) newValue);
saveRoutingValue(mContext, routingValue);
trySetAudioRoutingConfig(getSupportedAttributeList(), getHearingDevice(), routingValue);
final CachedBluetoothDevice device = mHearingAidHelper.getConnectedHearingAidDevice();
if (device != null) {
trySetAudioRoutingConfig(getSupportedAttributeList(),
mHearingAidHelper.getConnectedHearingAidDevice(), routingValue);
}
return true;
}
@@ -89,10 +98,10 @@ public abstract class HearingDeviceAudioRoutingBasePreferenceController extends
private void trySetAudioRoutingConfig(int[] audioAttributes,
CachedBluetoothDevice hearingDevice,
@HearingAidAudioRoutingConstants.RoutingValue int routingValue) {
final List<AudioProductStrategy> supportedStrategies = mHelper.getSupportedStrategies(
audioAttributes);
final List<AudioProductStrategy> supportedStrategies =
mAudioRoutingHelper.getSupportedStrategies(audioAttributes);
final AudioDeviceAttributes hearingDeviceAttributes =
mHelper.getMatchedHearingDeviceAttributes(hearingDevice);
mAudioRoutingHelper.getMatchedHearingDeviceAttributes(hearingDevice);
if (hearingDeviceAttributes == null) {
if (DEBUG) {
Log.d(TAG,
@@ -103,8 +112,8 @@ public abstract class HearingDeviceAudioRoutingBasePreferenceController extends
return;
}
final boolean status = mHelper.setPreferredDeviceRoutingStrategies(supportedStrategies,
hearingDeviceAttributes, routingValue);
final boolean status = mAudioRoutingHelper.setPreferredDeviceRoutingStrategies(
supportedStrategies, hearingDeviceAttributes, routingValue);
if (!status) {
final List<String> strategiesName = supportedStrategies.stream()
@@ -121,12 +130,6 @@ public abstract class HearingDeviceAudioRoutingBasePreferenceController extends
*/
protected abstract int[] getSupportedAttributeList();
/**
* Gets the {@link CachedBluetoothDevice} hearing device that is used to configure audio
* routing.
*/
protected abstract CachedBluetoothDevice getHearingDevice();
/**
* Saves the routing value.
*

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
import android.content.Context;
import android.provider.Settings;
@@ -35,15 +35,6 @@ public class HearingDeviceCallRoutingPreferenceController extends
super(context, preferenceKey);
}
/**
* Initializes objects in this controller. Need to call this before using the controller.
*
* @param cachedBluetoothDevice the hearing device to configure audio routing
*/
public void init(CachedBluetoothDevice cachedBluetoothDevice) {
mHearingDevice = cachedBluetoothDevice;
}
@Override
public int getAvailabilityStatus() {
return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
@@ -54,11 +45,6 @@ public class HearingDeviceCallRoutingPreferenceController extends
return HearingAidAudioRoutingConstants.CALL_ROUTING_ATTRIBUTES;
}
@Override
protected CachedBluetoothDevice getHearingDevice() {
return mHearingDevice;
}
@Override
protected void saveRoutingValue(Context context, int routingValue) {
Settings.Secure.putInt(context.getContentResolver(),

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
import android.content.Context;
import android.provider.Settings;
@@ -34,26 +34,12 @@ public class HearingDeviceMediaRoutingPreferenceController extends
super(context, preferenceKey);
}
/**
* Initializes objects in this controller. Need to call this before using the controller.
*
* @param cachedBluetoothDevice the hearing device to configure audio routing
*/
public void init(CachedBluetoothDevice cachedBluetoothDevice) {
mHearingDevice = cachedBluetoothDevice;
}
@Override
protected int[] getSupportedAttributeList() {
return HearingAidAudioRoutingConstants.MEDIA_ROUTING_ATTRIBUTES;
}
@Override
protected CachedBluetoothDevice getHearingDevice() {
return mHearingDevice;
}
@Override
protected void saveRoutingValue(Context context, int routingValue) {
Settings.Secure.putInt(context.getContentResolver(),

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
import android.content.Context;
import android.provider.Settings;
@@ -34,26 +34,12 @@ public class HearingDeviceRingtoneRoutingPreferenceController extends
super(context, preferenceKey);
}
/**
* Initializes objects in this controller. Need to call this before using the controller.
*
* @param cachedBluetoothDevice the hearing device to configure audio routing
*/
public void init(CachedBluetoothDevice cachedBluetoothDevice) {
mHearingDevice = cachedBluetoothDevice;
}
@Override
protected int[] getSupportedAttributeList() {
return HearingAidAudioRoutingConstants.RINGTONE_ROUTING_ATTRIBUTE;
}
@Override
protected CachedBluetoothDevice getHearingDevice() {
return mHearingDevice;
}
@Override
protected void saveRoutingValue(Context context, int routingValue) {
Settings.Secure.putInt(context.getContentResolver(),

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
import android.content.Context;
import android.provider.Settings;
@@ -35,26 +35,12 @@ public class HearingDeviceSystemSoundsRoutingPreferenceController extends
super(context, preferenceKey);
}
/**
* Initializes objects in this controller. Need to call this before using the controller.
*
* @param cachedBluetoothDevice the hearing device to configure audio routing
*/
public void init(CachedBluetoothDevice cachedBluetoothDevice) {
mHearingDevice = cachedBluetoothDevice;
}
@Override
protected int[] getSupportedAttributeList() {
return HearingAidAudioRoutingConstants.SYSTEM_SOUNDS_ROUTING_ATTRIBUTES;
}
@Override
protected CachedBluetoothDevice getHearingDevice() {
return mHearingDevice;
}
@Override
protected void saveRoutingValue(Context context, int routingValue) {
Settings.Secure.putInt(context.getContentResolver(),

View File

@@ -1,86 +0,0 @@
/*
* 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.KEY_DEVICE_ADDRESS;
import android.content.Context;
import android.os.Bundle;
import android.util.FeatureFlagUtils;
import androidx.annotation.VisibleForTesting;
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_DEVICE_CONTROLS_SPECIFIC_GROUP = "device_controls_specific";
@VisibleForTesting
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());
prefCategory.addPreference(pref);
}
@Override
protected void refresh() {}
@Override
public String getPreferenceKey() {
return KEY_DEVICE_CONTROLS_SPECIFIC_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));
final Bundle extras = preference.getExtras();
extras.putString(KEY_DEVICE_ADDRESS, mCachedDevice.getAddress());
preference.setFragment(BluetoothDetailsAudioRoutingFragment.class.getName());
return preference;
}
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (C) 2023 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 android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
import static com.android.settings.bluetooth.BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
/** Settings fragment containing bluetooth audio routing. */
public class BluetoothDetailsAudioRoutingFragment extends RestrictedDashboardFragment {
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.bluetooth_audio_routing_fragment);
private static final String TAG = "BluetoothDetailsAudioRoutingFragment";
@VisibleForTesting
CachedBluetoothDevice mCachedDevice;
public BluetoothDetailsAudioRoutingFragment() {
super(DISALLOW_CONFIG_BLUETOOTH);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
final LocalBluetoothManager localBtMgr = Utils.getLocalBtManager(context);
final CachedBluetoothDeviceManager cachedDeviceMgr = localBtMgr.getCachedDeviceManager();
final BluetoothDevice bluetoothDevice = localBtMgr.getBluetoothAdapter().getRemoteDevice(
getArguments().getString(KEY_DEVICE_ADDRESS));
mCachedDevice = cachedDeviceMgr.findDevice(bluetoothDevice);
if (mCachedDevice == null) {
// Close this page if device is null with invalid device mac address
Log.w(TAG, "onAttach() CachedDevice is null! Can not find address: "
+ bluetoothDevice.getAnonymizedAddress());
finish();
return;
}
use(HearingDeviceRingtoneRoutingPreferenceController.class).init(mCachedDevice);
use(HearingDeviceCallRoutingPreferenceController.class).init(mCachedDevice);
use(HearingDeviceMediaRoutingPreferenceController.class).init(mCachedDevice);
use(HearingDeviceSystemSoundsRoutingPreferenceController.class).init(mCachedDevice);
}
@Override
public int getMetricsCategory() {
return SettingsEnums.BLUETOOTH_AUDIO_ROUTING;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.bluetooth_audio_routing_fragment;
}
@Override
protected String getLogTag() {
return TAG;
}
}

View File

@@ -34,7 +34,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.google.common.annotations.VisibleForTesting;
/**
* The controller of the hearing device controls in the bluetooth detail settings.
* The controller of the hearing device settings to launch Hearing device page.
*/
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController
implements Preference.OnPreferenceClickListener {
@@ -87,6 +87,7 @@ public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDe
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));
preference.setOnPreferenceClickListener(this);
return preference;

View File

@@ -314,8 +314,6 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
lifecycle));
controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
mCachedDevice, lifecycle));
controllers.add(new BluetoothDetailsAudioRoutingController(context, this, mCachedDevice,
lifecycle));
}
return controllers;
}