[Audiosharing] Impl the stop audio sharing dialog.
Show the dialog when an ineligible remote device connected during the sharing session. Flagged with enable_le_audio_sharing Bug: 305620450 Test: Manual Change-Id: I3b3cc2e5e20dab7c07f9979bc01f53d6127ea20b
This commit is contained in:
@@ -16,10 +16,12 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastAssistant;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
@@ -38,9 +40,14 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@@ -53,11 +60,13 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
"connected_device_audio_sharing_settings";
|
||||
|
||||
private final LocalBluetoothManager mLocalBtManager;
|
||||
private final LocalBluetoothLeBroadcast mBroadcast;
|
||||
private final LocalBluetoothLeBroadcastAssistant mAssistant;
|
||||
private final Executor mExecutor;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private Preference mAudioSharingSettingsPreference;
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
private DashboardFragment mFragment;
|
||||
|
||||
private BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
|
||||
new BluetoothLeBroadcastAssistant.Callback() {
|
||||
@@ -149,6 +158,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
public AudioSharingDevicePreferenceController(Context context) {
|
||||
super(context, KEY);
|
||||
mLocalBtManager = Utils.getLocalBtManager(mContext);
|
||||
mBroadcast = mLocalBtManager.getProfileManager().getLeAudioBroadcastProfile();
|
||||
mAssistant = mLocalBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile();
|
||||
mExecutor = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
@@ -156,15 +166,15 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
@Override
|
||||
public void onStart(@NonNull LifecycleOwner owner) {
|
||||
if (mLocalBtManager == null) {
|
||||
Log.e(TAG, "onStart() Bluetooth is not supported on this device");
|
||||
Log.d(TAG, "onStart() Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
if (mAssistant == null) {
|
||||
Log.e(TAG, "onStart() Broadcast assistant is not supported on this device");
|
||||
Log.d(TAG, "onStart() Broadcast assistant is not supported on this device");
|
||||
return;
|
||||
}
|
||||
if (mBluetoothDeviceUpdater == null) {
|
||||
Log.e(TAG, "onStart() Bluetooth device updater is not initialized");
|
||||
Log.d(TAG, "onStart() Bluetooth device updater is not initialized");
|
||||
return;
|
||||
}
|
||||
mLocalBtManager.getEventManager().registerCallback(this);
|
||||
@@ -176,15 +186,15 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
@Override
|
||||
public void onStop(@NonNull LifecycleOwner owner) {
|
||||
if (mLocalBtManager == null) {
|
||||
Log.e(TAG, "onStop() Bluetooth is not supported on this device");
|
||||
Log.d(TAG, "onStop() Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
if (mAssistant == null) {
|
||||
Log.e(TAG, "onStop() Broadcast assistant is not supported on this device");
|
||||
Log.d(TAG, "onStop() Broadcast assistant is not supported on this device");
|
||||
return;
|
||||
}
|
||||
if (mBluetoothDeviceUpdater == null) {
|
||||
Log.e(TAG, "onStop() Bluetooth device updater is not initialized");
|
||||
Log.d(TAG, "onStop() Bluetooth device updater is not initialized");
|
||||
return;
|
||||
}
|
||||
mLocalBtManager.getEventManager().unregisterCallback(this);
|
||||
@@ -244,17 +254,60 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileConnectionStateChanged(
|
||||
@NonNull CachedBluetoothDevice cachedDevice,
|
||||
@ConnectionState int state,
|
||||
int bluetoothProfile) {
|
||||
if (state != BluetoothAdapter.STATE_CONNECTED || !cachedDevice.getDevice().isConnected()) {
|
||||
Log.d(TAG, "Ignore onProfileConnectionStateChanged, not connected state");
|
||||
return;
|
||||
}
|
||||
List<LocalBluetoothProfile> supportedProfiles = cachedDevice.getProfiles();
|
||||
boolean isLeAudioSupported = false;
|
||||
for (LocalBluetoothProfile profile : supportedProfiles) {
|
||||
if (profile instanceof LeAudioProfile && profile.isEnabled(cachedDevice.getDevice())) {
|
||||
isLeAudioSupported = true;
|
||||
}
|
||||
if (profile.getProfileId() != bluetoothProfile
|
||||
&& profile.getConnectionStatus(cachedDevice.getDevice())
|
||||
== BluetoothProfile.STATE_CONNECTED) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Ignore onProfileConnectionStateChanged, not the first connected profile");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Show stop audio sharing dialog when an ineligible (not le audio) remote device connected
|
||||
// during a sharing session.
|
||||
if (isBroadcasting() && !isLeAudioSupported) {
|
||||
if (mFragment != null) {
|
||||
AudioSharingStopDialogFragment.show(
|
||||
mFragment,
|
||||
cachedDevice.getName(),
|
||||
() -> {
|
||||
mBroadcast.stopBroadcast(mBroadcast.getLatestBroadcastId());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the controller.
|
||||
*
|
||||
* @param fragment The fragment to provide the context and metrics category for {@link
|
||||
* AudioSharingBluetoothDeviceUpdater}.
|
||||
* AudioSharingBluetoothDeviceUpdater} and provide the host for dialogs.
|
||||
*/
|
||||
public void init(DashboardFragment fragment) {
|
||||
mFragment = fragment;
|
||||
mBluetoothDeviceUpdater =
|
||||
new AudioSharingBluetoothDeviceUpdater(
|
||||
fragment.getContext(),
|
||||
AudioSharingDevicePreferenceController.this,
|
||||
fragment.getMetricsCategory());
|
||||
}
|
||||
|
||||
private boolean isBroadcasting() {
|
||||
return mBroadcast != null && mBroadcast.isEnabled(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user