Merge "[LE Audio] To remove the broadcast source item that created by receive state"

This commit is contained in:
Betty Chang
2022-12-05 03:42:06 +00:00
committed by Android (Google) Code Review
4 changed files with 247 additions and 5 deletions

View File

@@ -170,6 +170,16 @@ class BluetoothBroadcastSourcePreference extends Preference {
return mIsEncrypted;
}
/**
* Whether the broadcast source is connected at the beginging. We will get the
* BluetoothLeBroadcastReceiveState from the broadcast source.
* See {@link BluetoothFindBroadcastsFragment#addConnectedSourcePreference}
* @return If true, the broadcast source is already connected by the broadcast sink.
*/
public boolean isCreatedByReceiveState() {
return mBluetoothLeBroadcastReceiveState != null;
}
/**
* Clear the BluetoothLeBroadcastReceiveState and reset the state when the user clicks the
* "leave broadcast" button.

View File

@@ -37,7 +37,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import com.android.settings.R;
@@ -75,9 +74,11 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
CachedBluetoothDevice mCachedDevice;
@VisibleForTesting
PreferenceCategory mBroadcastSourceListCategory;
@VisibleForTesting
BluetoothBroadcastSourcePreference mSelectedPreference;
BluetoothFindBroadcastsHeaderController mBluetoothFindBroadcastsHeaderController;
private LocalBluetoothLeBroadcastAssistant mLeBroadcastAssistant;
private BluetoothBroadcastSourcePreference mSelectedPreference;
private Executor mExecutor;
private int mSourceId;
@@ -369,19 +370,31 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
return pref;
}
private void addSource(BluetoothBroadcastSourcePreference pref) {
@VisibleForTesting
void addSource(BluetoothBroadcastSourcePreference pref) {
if (mLeBroadcastAssistant == null || mCachedDevice == null) {
Log.w(TAG, "addSource: LeBroadcastAssistant or CachedDevice is null!");
return;
}
if (mSelectedPreference != null) {
// The previous preference status set false after user selects the new Preference.
getActivity().runOnUiThread(
if (mSelectedPreference.isCreatedByReceiveState()) {
Log.d(TAG, "addSource: Remove preference that created by getAllSources()");
getActivity().runOnUiThread(() ->
mBroadcastSourceListCategory.removePreference(mSelectedPreference));
if (mLeBroadcastAssistant != null && !mLeBroadcastAssistant.isSearchInProgress()) {
Log.d(TAG, "addSource: Start Searching For Broadcast Sources");
mLeBroadcastAssistant.startSearchingForSources(getScanFilter());
}
} else {
Log.d(TAG, "addSource: Update preference that created by onSourceFound()");
// The previous preference status set false after user selects the new Preference.
getActivity().runOnUiThread(
() -> {
mSelectedPreference.updateMetadataAndRefreshUi(
mSelectedPreference.getBluetoothLeBroadcastMetadata(), false);
mSelectedPreference.setOrder(1);
});
}
}
mSelectedPreference = pref;
mLeBroadcastAssistant.addSource(mCachedDevice.getDevice(),