[BT Broadcast Sink] Add the function for leave and scan QRcode buttons
Add function for 'leave broadcast' button Add function for 'Scan QR code' button Set 'level broadcast' button gray out when device does not have broadcast source Bug: 228259065 Test: build pass and manually test Change-Id: Iab4a45e73f49c3f755b95ea3fa38872daac7e745
This commit is contained in:
@@ -75,6 +75,7 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
||||
CachedBluetoothDevice mCachedDevice;
|
||||
@VisibleForTesting
|
||||
PreferenceCategory mBroadcastSourceListCategory;
|
||||
BluetoothFindBroadcastsHeaderController mBluetoothFindBroadcastsHeaderController;
|
||||
private LocalBluetoothLeBroadcastAssistant mLeBroadcastAssistant;
|
||||
private BluetoothBroadcastSourcePreference mSelectedPreference;
|
||||
private Executor mExecutor;
|
||||
@@ -93,7 +94,6 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
||||
@Override
|
||||
public void onSearchStartFailed(int reason) {
|
||||
Log.d(TAG, "onSearchStartFailed: " + reason);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,6 +240,28 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
||||
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
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
@@ -256,13 +278,18 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
||||
|
||||
if (mCachedDevice != null) {
|
||||
Lifecycle lifecycle = getSettingsLifecycle();
|
||||
controllers.add(new BluetoothFindBroadcastsHeaderController(context, this,
|
||||
mCachedDevice, lifecycle, mManager));
|
||||
mBluetoothFindBroadcastsHeaderController = new BluetoothFindBroadcastsHeaderController(
|
||||
context, this, mCachedDevice, lifecycle, mManager);
|
||||
controllers.add(mBluetoothFindBroadcastsHeaderController);
|
||||
}
|
||||
return controllers;
|
||||
}
|
||||
|
||||
private LocalBluetoothLeBroadcastAssistant getLeBroadcastAssistant() {
|
||||
/**
|
||||
* Gets the LocalBluetoothLeBroadcastAssistant
|
||||
* @return the LocalBluetoothLeBroadcastAssistant
|
||||
*/
|
||||
public LocalBluetoothLeBroadcastAssistant getLeBroadcastAssistant() {
|
||||
if (mManager == null) {
|
||||
Log.w(TAG, "getLeBroadcastAssistant: LocalBluetoothManager is null!");
|
||||
return null;
|
||||
@@ -292,6 +319,11 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
||||
}
|
||||
item.updateMetadataAndRefreshUi(source, isConnected);
|
||||
item.setOrder(isConnected ? 0 : 1);
|
||||
|
||||
//refresh the header
|
||||
if (mBluetoothFindBroadcastsHeaderController != null) {
|
||||
mBluetoothFindBroadcastsHeaderController.refreshUi();
|
||||
}
|
||||
}
|
||||
|
||||
private BluetoothBroadcastSourcePreference createBluetoothBroadcastSourcePreference(
|
||||
|
@@ -16,22 +16,24 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.qrcode.QrCodeScanModeActivity;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
/**
|
||||
@@ -52,11 +54,12 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
|
||||
LinearLayout mBtnBroadcastLayout;
|
||||
Button mBtnLeaveBroadcast;
|
||||
Button mBtnScanQrCode;
|
||||
|
||||
BluetoothFindBroadcastsFragment mBluetoothFindBroadcastsFragment;
|
||||
public BluetoothFindBroadcastsHeaderController(Context context,
|
||||
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle,
|
||||
LocalBluetoothManager bluetoothManager) {
|
||||
BluetoothFindBroadcastsFragment fragment, CachedBluetoothDevice device,
|
||||
Lifecycle lifecycle, LocalBluetoothManager bluetoothManager) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
mBluetoothFindBroadcastsFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,20 +104,41 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
|
||||
mBtnFindBroadcast.setVisibility(View.VISIBLE);
|
||||
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() {
|
||||
// TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant
|
||||
// to start searching for source
|
||||
// TODO(b/231543455) : Using the BluetoothDeviceUpdater to refactor it.
|
||||
if (mBluetoothFindBroadcastsFragment == null) {
|
||||
return;
|
||||
}
|
||||
mBluetoothFindBroadcastsFragment.scanBroadcastSource();
|
||||
}
|
||||
|
||||
private void leaveBroadcastSession() {
|
||||
// TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant
|
||||
// to leave the broadcast session
|
||||
if (mBluetoothFindBroadcastsFragment == null) {
|
||||
return;
|
||||
}
|
||||
mBluetoothFindBroadcastsFragment.leaveBroadcastSession();
|
||||
}
|
||||
|
||||
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
|
||||
@@ -128,4 +152,11 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BROADCAST_HEADER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI
|
||||
*/
|
||||
public void refreshUi() {
|
||||
updateHeaderLayout();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user