Disable media output switcher in Settings when audio sharing
Bug: 327080094 Test: atest MediaOutputPreferenceControllerTest Change-Id: I1e81d507c5c92c2b6f21494551931b359d5043cb
This commit is contained in:
@@ -19,6 +19,8 @@ package com.android.settings.sound;
|
||||
import static com.android.settingslib.media.flags.Flags.enableOutputSwitcherForSystemRouting;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
@@ -26,6 +28,7 @@ import android.media.session.MediaController;
|
||||
import android.media.session.MediaSessionManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -35,6 +38,8 @@ import com.android.settings.media.MediaOutputUtils;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.media.MediaOutputConstants;
|
||||
|
||||
import java.util.List;
|
||||
@@ -53,10 +58,74 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
@Nullable private MediaController mMediaController;
|
||||
private MediaSessionManager mMediaSessionManager;
|
||||
|
||||
@Nullable private LocalBluetoothLeBroadcast mLocalBluetoothLeBroadcast;
|
||||
|
||||
private final BluetoothLeBroadcast.Callback mBroadcastCallback =
|
||||
new BluetoothLeBroadcast.Callback() {
|
||||
@Override
|
||||
public void onBroadcastStarted(int reason, int broadcastId) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStartFailed(int reason) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStopped(int reason, int broadcastId) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStopFailed(int reason) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStarted(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStopped(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastUpdated(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastUpdateFailed(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastMetadataChanged(
|
||||
int broadcastId, @NonNull BluetoothLeBroadcastMetadata metadata) {}
|
||||
};
|
||||
|
||||
public MediaOutputPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mMediaSessionManager = context.getSystemService(MediaSessionManager.class);
|
||||
mMediaController = MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager);
|
||||
LocalBluetoothManager localBluetoothManager =
|
||||
com.android.settings.bluetooth.Utils.getLocalBtManager(mContext);
|
||||
if (localBluetoothManager != null) {
|
||||
mLocalBluetoothLeBroadcast =
|
||||
localBluetoothManager.getProfileManager().getLeAudioBroadcastProfile();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (mLocalBluetoothLeBroadcast != null) {
|
||||
mLocalBluetoothLeBroadcast.registerServiceCallBack(
|
||||
mContext.getMainExecutor(), mBroadcastCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (mLocalBluetoothLeBroadcast != null) {
|
||||
mLocalBluetoothLeBroadcast.unregisterServiceCallBack(mBroadcastCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +152,7 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mPreference.setEnabled(true);
|
||||
if (Utils.isAudioModeOngoingCall(mContext)) {
|
||||
// Ongoing call status, switch entry for media will be disabled.
|
||||
mPreference.setVisible(false);
|
||||
@@ -112,9 +181,15 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
com.android.settings.Utils.getApplicationLabel(mContext,
|
||||
mMediaController.getPackageName())));
|
||||
}
|
||||
mPreference.setSummary((activeDevice == null) ?
|
||||
mContext.getText(R.string.media_output_default_summary) :
|
||||
activeDevice.getAlias());
|
||||
if (isDeviceBroadcasting()) {
|
||||
mPreference.setSummary(R.string.media_output_audio_sharing);
|
||||
mPreference.setEnabled(false);
|
||||
} else {
|
||||
mPreference.setSummary(
|
||||
(activeDevice == null)
|
||||
? mContext.getText(R.string.media_output_default_summary)
|
||||
: activeDevice.getAlias());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,4 +251,10 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDeviceBroadcasting() {
|
||||
return com.android.settingslib.flags.Flags.enableLeAudioSharing()
|
||||
&& mLocalBluetoothLeBroadcast != null
|
||||
&& mLocalBluetoothLeBroadcast.isEnabled(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user