Merge "[LE Audio] To remove the broadcast source item that created by receive state" am: 18eb985e41 am: 1de44c2447

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2495740

Change-Id: I704c81ac2d045142be5c7cc1835efa6d46cd2930
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Betty Chang
2023-03-20 07:35:52 +00:00
committed by Automerger Merge Worker
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(),