[Audiosharing] Block pairing during audio sharing
When a) there are two sinks in sharing b) there is at least one temp bond device connected Test: atest Flag: com.android.settingslib.flags.enable_temporary_bond_devices_ui Bug: 392004799 Change-Id: Id093b4c0b67bdc1db621e0241e79900abbd26c0f
This commit is contained in:
@@ -48,6 +48,7 @@ import com.android.settings.widget.GearPreference;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -93,6 +94,7 @@ public final class BluetoothDevicePreference extends GearPreference {
|
||||
private final int mType;
|
||||
|
||||
private AlertDialog mDisconnectDialog;
|
||||
@Nullable private AlertDialog mBlockPairingDialog;
|
||||
private String contentDescription = null;
|
||||
private boolean mHideSecondTarget = false;
|
||||
private boolean mIsCallbackRemoved = true;
|
||||
@@ -409,13 +411,24 @@ public final class BluetoothDevicePreference extends GearPreference {
|
||||
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
mCachedDevice.connect();
|
||||
} else if (bondState == BluetoothDevice.BOND_NONE) {
|
||||
metricsFeatureProvider.action(context,
|
||||
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
if (!mCachedDevice.hasHumanReadableName()) {
|
||||
var unused = ThreadUtils.postOnBackgroundThread(() -> {
|
||||
if (Flags.enableTemporaryBondDevicesUi() && Utils.shouldBlockPairingInAudioSharing(
|
||||
mLocalBtManager)) {
|
||||
// TODO: collect metric
|
||||
context.getMainExecutor().execute(() ->
|
||||
mBlockPairingDialog =
|
||||
Utils.showBlockPairingDialog(context, mBlockPairingDialog,
|
||||
mLocalBtManager));
|
||||
return;
|
||||
}
|
||||
metricsFeatureProvider.action(context,
|
||||
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
pair();
|
||||
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
if (!mCachedDevice.hasHumanReadableName()) {
|
||||
metricsFeatureProvider.action(context,
|
||||
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
context.getMainExecutor().execute(() -> pair());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
@@ -44,6 +45,7 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
||||
@@ -324,4 +326,33 @@ public final class Utils {
|
||||
.map(d -> BluetoothUtils.getGroupId(deviceManager.findDevice(d))).collect(
|
||||
Collectors.toSet()).size() >= 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show block pairing dialog during audio sharing
|
||||
* @param context The dialog context
|
||||
* @param dialog The dialog if already exists
|
||||
* @param localBtManager {@link LocalBluetoothManager}
|
||||
* @return The block pairing dialog
|
||||
*/
|
||||
@Nullable
|
||||
static AlertDialog showBlockPairingDialog(@NonNull Context context,
|
||||
@Nullable AlertDialog dialog, @Nullable LocalBluetoothManager localBtManager) {
|
||||
if (!com.android.settingslib.flags.Flags.enableTemporaryBondDevicesUi()) return null;
|
||||
if (dialog != null && dialog.isShowing()) return dialog;
|
||||
if (dialog == null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setTitle(R.string.audio_sharing_block_pairing_dialog_title)
|
||||
.setMessage(R.string.audio_sharing_block_pairing_dialog_content);
|
||||
LocalBluetoothLeBroadcast broadcast = localBtManager == null ? null :
|
||||
localBtManager.getProfileManager().getLeAudioBroadcastProfile();
|
||||
if (broadcast != null) {
|
||||
builder.setPositiveButton(R.string.audio_sharing_turn_off_button_label,
|
||||
(dlg, which) -> broadcast.stopLatestBroadcast());
|
||||
}
|
||||
dialog = builder.create();
|
||||
}
|
||||
dialog.show();
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user