Merge "[BT Broadcast Sink] Add the function for leave and scan QRcode buttons" into tm-dev

This commit is contained in:
SongFerng Wang
2022-05-06 11:08:21 +00:00
committed by Android (Google) Code Review
2 changed files with 78 additions and 15 deletions

View File

@@ -75,6 +75,7 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
CachedBluetoothDevice mCachedDevice; CachedBluetoothDevice mCachedDevice;
@VisibleForTesting @VisibleForTesting
PreferenceCategory mBroadcastSourceListCategory; PreferenceCategory mBroadcastSourceListCategory;
BluetoothFindBroadcastsHeaderController mBluetoothFindBroadcastsHeaderController;
private LocalBluetoothLeBroadcastAssistant mLeBroadcastAssistant; private LocalBluetoothLeBroadcastAssistant mLeBroadcastAssistant;
private BluetoothBroadcastSourcePreference mSelectedPreference; private BluetoothBroadcastSourcePreference mSelectedPreference;
private Executor mExecutor; private Executor mExecutor;
@@ -93,7 +94,6 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
@Override @Override
public void onSearchStartFailed(int reason) { public void onSearchStartFailed(int reason) {
Log.d(TAG, "onSearchStartFailed: " + reason); Log.d(TAG, "onSearchStartFailed: " + reason);
} }
@Override @Override
@@ -240,6 +240,28 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
return SettingsEnums.PAGE_UNKNOWN; return SettingsEnums.PAGE_UNKNOWN;
} }
/**
* Starts to scan broadcast source by the BluetoothLeBroadcastAssistant.
*/
public void scanBroadcastSource() {
if (mLeBroadcastAssistant == null) {
Log.w(TAG, "scanBroadcastSource: LeBroadcastAssistant is null!");
return;
}
mLeBroadcastAssistant.startSearchingForSources(getScanFilter());
}
/**
* Leaves the broadcast source by the BluetoothLeBroadcastAssistant.
*/
public void leaveBroadcastSession() {
if (mLeBroadcastAssistant == null || mCachedDevice == null) {
Log.w(TAG, "leaveBroadcastSession: LeBroadcastAssistant or CachedDevice is null!");
return;
}
mLeBroadcastAssistant.removeSource(mCachedDevice.getDevice(), getSourceId());
}
@Override @Override
protected String getLogTag() { protected String getLogTag() {
return TAG; return TAG;
@@ -256,13 +278,18 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
if (mCachedDevice != null) { if (mCachedDevice != null) {
Lifecycle lifecycle = getSettingsLifecycle(); Lifecycle lifecycle = getSettingsLifecycle();
controllers.add(new BluetoothFindBroadcastsHeaderController(context, this, mBluetoothFindBroadcastsHeaderController = new BluetoothFindBroadcastsHeaderController(
mCachedDevice, lifecycle, mManager)); context, this, mCachedDevice, lifecycle, mManager);
controllers.add(mBluetoothFindBroadcastsHeaderController);
} }
return controllers; return controllers;
} }
private LocalBluetoothLeBroadcastAssistant getLeBroadcastAssistant() { /**
* Gets the LocalBluetoothLeBroadcastAssistant
* @return the LocalBluetoothLeBroadcastAssistant
*/
public LocalBluetoothLeBroadcastAssistant getLeBroadcastAssistant() {
if (mManager == null) { if (mManager == null) {
Log.w(TAG, "getLeBroadcastAssistant: LocalBluetoothManager is null!"); Log.w(TAG, "getLeBroadcastAssistant: LocalBluetoothManager is null!");
return null; return null;
@@ -292,6 +319,11 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
} }
item.updateMetadataAndRefreshUi(source, isConnected); item.updateMetadataAndRefreshUi(source, isConnected);
item.setOrder(isConnected ? 0 : 1); item.setOrder(isConnected ? 0 : 1);
//refresh the header
if (mBluetoothFindBroadcastsHeaderController != null) {
mBluetoothFindBroadcastsHeaderController.refreshUi();
}
} }
private BluetoothBroadcastSourcePreference createBluetoothBroadcastSourcePreference( private BluetoothBroadcastSourcePreference createBluetoothBroadcastSourcePreference(

View File

@@ -16,22 +16,24 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.content.Intent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.qrcode.QrCodeScanModeActivity;
import com.android.settingslib.widget.LayoutPreference; import com.android.settingslib.widget.LayoutPreference;
/** /**
@@ -52,11 +54,12 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
LinearLayout mBtnBroadcastLayout; LinearLayout mBtnBroadcastLayout;
Button mBtnLeaveBroadcast; Button mBtnLeaveBroadcast;
Button mBtnScanQrCode; Button mBtnScanQrCode;
BluetoothFindBroadcastsFragment mBluetoothFindBroadcastsFragment;
public BluetoothFindBroadcastsHeaderController(Context context, public BluetoothFindBroadcastsHeaderController(Context context,
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle, BluetoothFindBroadcastsFragment fragment, CachedBluetoothDevice device,
LocalBluetoothManager bluetoothManager) { Lifecycle lifecycle, LocalBluetoothManager bluetoothManager) {
super(context, fragment, device, lifecycle); super(context, fragment, device, lifecycle);
mBluetoothFindBroadcastsFragment = fragment;
} }
@Override @Override
@@ -101,20 +104,41 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
mBtnFindBroadcast.setVisibility(View.VISIBLE); mBtnFindBroadcast.setVisibility(View.VISIBLE);
mBtnBroadcastLayout.setVisibility(View.GONE); mBtnBroadcastLayout.setVisibility(View.GONE);
} }
mBtnLeaveBroadcast.setEnabled(false);
if (mBluetoothFindBroadcastsFragment != null && mCachedDevice != null) {
LocalBluetoothLeBroadcastAssistant broadcastAssistant =
mBluetoothFindBroadcastsFragment.getLeBroadcastAssistant();
if (broadcastAssistant != null
&& broadcastAssistant.getConnectionStatus(mCachedDevice.getDevice())
== BluetoothProfile.STATE_CONNECTED) {
mBtnLeaveBroadcast.setEnabled(true);
}
}
} }
private void scanBroadcastSource() { private void scanBroadcastSource() {
// TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant // TODO(b/231543455) : Using the BluetoothDeviceUpdater to refactor it.
// to start searching for source if (mBluetoothFindBroadcastsFragment == null) {
return;
}
mBluetoothFindBroadcastsFragment.scanBroadcastSource();
} }
private void leaveBroadcastSession() { private void leaveBroadcastSession() {
// TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant if (mBluetoothFindBroadcastsFragment == null) {
// to leave the broadcast session return;
}
mBluetoothFindBroadcastsFragment.leaveBroadcastSession();
} }
private void launchQrCodeScanner() { private void launchQrCodeScanner() {
// TODO(b/228259065) : Launch the QR code scanner page by intent final Intent intent = new Intent(mContext, QrCodeScanModeActivity.class);
intent.setAction(BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER)
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_SINK_IS_GROUP, false)
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_DEVICE_SINK,
mCachedDevice.getDevice());
mContext.startActivity(intent);
} }
@Override @Override
@@ -128,4 +152,11 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
public String getPreferenceKey() { public String getPreferenceKey() {
return KEY_BROADCAST_HEADER; return KEY_BROADCAST_HEADER;
} }
/**
* Updates the UI
*/
public void refreshUi() {
updateHeaderLayout();
}
} }