Merge changes If4a471e2,I5ed1713d into main
* changes: [Temp bonding] Clean up old guest device logic as requirements changed [Temp bonding] Move audio sharing settings up
This commit is contained in:
@@ -26,7 +26,6 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
/** Controller to maintain available media Bluetooth devices */
|
||||
@@ -61,14 +60,6 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
// If the device is temporary bond, it shouldn't be shown here.
|
||||
if (Flags.enableTemporaryBondDevicesUi()
|
||||
&& BluetoothUtils.isTemporaryBondDevice(cachedDevice.getDevice())) {
|
||||
Log.d(TAG,
|
||||
"isFilterMatched() Filter out temporary bond device " + cachedDevice.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
final int currentAudioProfile;
|
||||
|
||||
if (mAudioMode == AudioManager.MODE_RINGTONE
|
||||
|
||||
@@ -57,14 +57,6 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
// If the device is temporary bond, it shouldn't be shown here.
|
||||
if (Flags.enableTemporaryBondDevicesUi()
|
||||
&& BluetoothUtils.isTemporaryBondDevice(cachedDevice.getDevice())) {
|
||||
Log.d(TAG,
|
||||
"isFilterMatched() Filter out temporary bond device " + cachedDevice.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
final int currentAudioProfile;
|
||||
|
||||
if (mAudioMode == AudioManager.MODE_RINGTONE
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingDevicePreferenceController;
|
||||
import com.android.settings.connecteddevice.audiosharing.TemporaryBondDeviceGroupController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.overlay.SurveyFeatureProvider;
|
||||
@@ -35,7 +34,6 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.slices.SlicePreferenceController;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.HearingAidStatsLogUtils;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
@@ -84,9 +82,6 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
use(AudioSharingDevicePreferenceController.class).init(this);
|
||||
if (Flags.enableTemporaryBondDevicesUi()) {
|
||||
use(TemporaryBondDeviceGroupController.class).init(this);
|
||||
}
|
||||
}
|
||||
use(AvailableMediaDeviceGroupController.class).init(this);
|
||||
use(ConnectedDeviceGroupController.class).init(this);
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
@@ -52,14 +51,6 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||
// If the device is temporary bond, it shouldn't be shown here.
|
||||
if (Flags.enableTemporaryBondDevicesUi()
|
||||
&& BluetoothUtils.isTemporaryBondDevice(cachedDevice.getDevice())) {
|
||||
Log.d(TAG,
|
||||
"isFilterMatched() Filter out temporary bond device " + cachedDevice.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isFilterMatched = false;
|
||||
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
|
||||
// If device is LE audio device and has a broadcast source,
|
||||
|
||||
@@ -67,7 +67,6 @@ import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** PreferenceController to control the dialog to choose the active device for calls and alarms */
|
||||
public class AudioSharingCallAudioPreferenceController extends AudioSharingBasePreferenceController
|
||||
@@ -404,21 +403,11 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
|
||||
|
||||
private void updateDeviceItemsInSharingSession() {
|
||||
mGroupedConnectedDevices = AudioSharingUtils.fetchConnectedDevicesByGroupId(mBtManager);
|
||||
if (Flags.enableTemporaryBondDevicesUi()) {
|
||||
mGroupedConnectedDevices =
|
||||
mGroupedConnectedDevices.entrySet().stream()
|
||||
.filter(entry -> !anyTemporaryBondDevice(entry.getValue()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
mDeviceItemsInSharingSession =
|
||||
AudioSharingUtils.buildOrderedConnectedLeadAudioSharingDeviceItem(
|
||||
mBtManager, mGroupedConnectedDevices, /* filterByInSharing= */ true);
|
||||
}
|
||||
|
||||
private boolean anyTemporaryBondDevice(List<BluetoothDevice> connectedDevices) {
|
||||
return connectedDevices.stream().anyMatch(BluetoothUtils::isTemporaryBondDevice);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Pair<Integer, AudioSharingDeviceItem> getActiveItemWithIndex() {
|
||||
List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(mDeviceItemsInSharingSession);
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.connecteddevice.audiosharing;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
/**
|
||||
* Controller to maintain the {@link androidx.preference.PreferenceGroup} for all connected
|
||||
* temporary bond devices. It uses {@link DevicePreferenceCallback} to add/remove
|
||||
* {@link Preference}
|
||||
*/
|
||||
public class TemporaryBondDeviceGroupController extends BasePreferenceController implements
|
||||
DefaultLifecycleObserver, DevicePreferenceCallback, BluetoothCallback {
|
||||
private static final String TAG = "TemporaryBondDeviceGroupController";
|
||||
private static final String KEY = "temp_bond_device_list";
|
||||
|
||||
@Nullable
|
||||
private final BluetoothEventManager mEventManager;
|
||||
@Nullable
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
@Nullable
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
|
||||
|
||||
public TemporaryBondDeviceGroupController(@NonNull Context context) {
|
||||
super(context, KEY);
|
||||
LocalBluetoothManager btManager = Utils.getLocalBtManager(mContext);
|
||||
mEventManager = btManager == null ? null : btManager.getEventManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(@NonNull LifecycleOwner owner) {
|
||||
if (!isAvailable()) {
|
||||
Log.d(TAG, "Skip onStart(), feature is not supported.");
|
||||
return;
|
||||
}
|
||||
if (mEventManager == null) {
|
||||
Log.d(TAG, "onStart() Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
var unused = ThreadUtils.postOnBackgroundThread(() -> {
|
||||
mEventManager.registerCallback(this);
|
||||
if (mBluetoothDeviceUpdater != null) {
|
||||
mBluetoothDeviceUpdater.registerCallback();
|
||||
mBluetoothDeviceUpdater.refreshPreference();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(@NonNull LifecycleOwner owner) {
|
||||
var unused = ThreadUtils.postOnBackgroundThread(() -> {
|
||||
if (mBluetoothDeviceUpdater != null) {
|
||||
mBluetoothDeviceUpdater.unregisterCallback();
|
||||
}
|
||||
if (mEventManager != null) {
|
||||
mEventManager.unregisterCallback(this);
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "onStop() Bluetooth is not supported on this device");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreferenceGroup = screen.findPreference(KEY);
|
||||
if (mPreferenceGroup != null) {
|
||||
mPreferenceGroup.setVisible(false);
|
||||
}
|
||||
|
||||
if (isAvailable() && mBluetoothDeviceUpdater != null) {
|
||||
mBluetoothDeviceUpdater.setPrefContext(screen.getContext());
|
||||
mBluetoothDeviceUpdater.forceUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceAdded(@NonNull Preference preference) {
|
||||
if (mPreferenceGroup != null) {
|
||||
mPreferenceGroup.addPreference(preference);
|
||||
Log.d(TAG, "Temporary bond device added");
|
||||
if (mPreferenceGroup.getPreferenceCount() == 1) {
|
||||
mPreferenceGroup.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceRemoved(@NonNull Preference preference) {
|
||||
if (mPreferenceGroup != null) {
|
||||
mPreferenceGroup.removePreference(preference);
|
||||
Log.d(TAG, "Temporary bond device removed");
|
||||
if (mPreferenceGroup.getPreferenceCount() == 0) {
|
||||
mPreferenceGroup.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return (BluetoothUtils.isAudioSharingUIAvailable(mContext)
|
||||
&& mBluetoothDeviceUpdater != null && Flags.enableTemporaryBondDevicesUi())
|
||||
? AVAILABLE_UNSEARCHABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the controller.
|
||||
*
|
||||
* @param fragment The fragment to provide the context and metrics category for {@link
|
||||
* TemporaryBondDeviceGroupUpdater} and provide the host for dialogs.
|
||||
*/
|
||||
public void init(@NonNull DashboardFragment fragment) {
|
||||
mBluetoothDeviceUpdater = new TemporaryBondDeviceGroupUpdater(fragment.getContext(),
|
||||
TemporaryBondDeviceGroupController.this,
|
||||
fragment.getMetricsCategory());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setBluetoothDeviceUpdater(@Nullable BluetoothDeviceUpdater bluetoothDeviceUpdater) {
|
||||
mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setPreferenceGroup(@Nullable PreferenceGroup preferenceGroup) {
|
||||
mPreferenceGroup = preferenceGroup;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.connecteddevice.audiosharing;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
|
||||
/** Maintain and update connected temporary bond bluetooth devices */
|
||||
public class TemporaryBondDeviceGroupUpdater extends BluetoothDeviceUpdater {
|
||||
private static final String TAG = "TemporaryBondDeviceGroupUpdater";
|
||||
private static final String PREF_KEY_PREFIX = "temp_bond_bt_";
|
||||
|
||||
public TemporaryBondDeviceGroupUpdater(
|
||||
@NonNull Context context,
|
||||
@NonNull DevicePreferenceCallback devicePreferenceCallback,
|
||||
int metricsCategory) {
|
||||
super(context, devicePreferenceCallback, metricsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(@NonNull CachedBluetoothDevice cachedDevice) {
|
||||
// Only connected temporary bond device should be shown in this section when Audio
|
||||
// sharing UI is available.
|
||||
boolean isFilterMatched = Flags.enableTemporaryBondDevicesUi()
|
||||
&& BluetoothUtils.isTemporaryBondDevice(cachedDevice.getDevice())
|
||||
&& isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)
|
||||
&& BluetoothUtils.isAudioSharingUIAvailable(mContext);
|
||||
Log.d(
|
||||
TAG,
|
||||
"isFilterMatched() device : "
|
||||
+ cachedDevice.getName()
|
||||
+ ", isFilterMatched : "
|
||||
+ isFilterMatched);
|
||||
return isFilterMatched;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPreferenceKeyPrefix() {
|
||||
return PREF_KEY_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
super.update(cachedBluetoothDevice);
|
||||
Log.d(TAG, "Map : " + mPreferenceMap);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user