Merge "[Audiosharing] Enable audio sharing UI when preview option on." into main

This commit is contained in:
Yiyi Shen
2024-11-08 06:36:49 +00:00
committed by Android (Google) Code Review
29 changed files with 445 additions and 379 deletions

View File

@@ -77,7 +77,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
// It would show in Available Devices group if the audio sharing flag is disabled or // It would show in Available Devices group if the audio sharing flag is disabled or
// the device is not in the audio sharing session. // the device is not in the audio sharing session.
if (cachedDevice.isConnectedLeAudioDevice()) { if (cachedDevice.isConnectedLeAudioDevice()) {
if (BluetoothUtils.isAudioSharingEnabled() if (BluetoothUtils.isAudioSharingUIAvailable(mContext)
&& BluetoothUtils.hasConnectedBroadcastSource( && BluetoothUtils.hasConnectedBroadcastSource(
cachedDevice, mLocalBtManager)) { cachedDevice, mLocalBtManager)) {
Log.d( Log.d(

View File

@@ -228,10 +228,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
final BluetoothDevice device = cachedDevice.getDevice(); final BluetoothDevice device = cachedDevice.getDevice();
if (device != null if (device != null
&& mSelectedList.contains(device)) { && mSelectedList.contains(device)) {
if (!BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(getContext())) {
finish();
return;
}
if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT
&& state == BluetoothAdapter.STATE_CONNECTED && state == BluetoothAdapter.STATE_CONNECTED
&& device.equals(mJustBonded) && device.equals(mJustBonded)
@@ -242,6 +239,9 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
mHandler.removeMessages(AUTO_DISMISS_MESSAGE_ID); mHandler.removeMessages(AUTO_DISMISS_MESSAGE_ID);
finishFragmentWithResultForAudioSharing(device); finishFragmentWithResultForAudioSharing(device);
} }
} else {
finish();
}
} else { } else {
onDeviceDeleted(cachedDevice); onDeviceDeleted(cachedDevice);
} }
@@ -309,7 +309,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
@VisibleForTesting @VisibleForTesting
boolean shouldTriggerAudioSharingShareThenPairFlow() { boolean shouldTriggerAudioSharingShareThenPairFlow() {
if (!BluetoothUtils.isAudioSharingEnabled()) return false; if (BluetoothUtils.isAudioSharingUIAvailable(getContext())) {
Activity activity = getActivity(); Activity activity = getActivity();
Intent intent = activity == null ? null : activity.getIntent(); Intent intent = activity == null ? null : activity.getIntent();
Bundle args = Bundle args =
@@ -319,6 +319,8 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
return args != null return args != null
&& args.getBoolean(EXTRA_PAIR_AND_JOIN_SHARING, false); && args.getBoolean(EXTRA_PAIR_AND_JOIN_SHARING, false);
} }
return false;
}
private void addOnMetadataChangedListener(@Nullable BluetoothDevice device) { private void addOnMetadataChangedListener(@Nullable BluetoothDevice device) {
var unused = ThreadUtils.postOnBackgroundThread(() -> { var unused = ThreadUtils.postOnBackgroundThread(() -> {

View File

@@ -179,7 +179,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
super(context, KEY); super(context, KEY);
mBtManager = Utils.getLocalBtManager(mContext); mBtManager = Utils.getLocalBtManager(mContext);
mExecutor = Executors.newSingleThreadExecutor(); mExecutor = Executors.newSingleThreadExecutor();
if (BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
mBroadcast = mBroadcast =
mBtManager == null mBtManager == null
? null ? null
@@ -200,7 +200,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
Log.d(TAG, "onStart() Bluetooth is not supported on this device"); Log.d(TAG, "onStart() Bluetooth is not supported on this device");
return; return;
} }
if (BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
registerAudioSharingCallbacks(); registerAudioSharingCallbacks();
} }
mBtManager.getEventManager().registerCallback(this); mBtManager.getEventManager().registerCallback(this);
@@ -216,7 +216,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
Log.d(TAG, "onStop() Bluetooth is not supported on this device"); Log.d(TAG, "onStop() Bluetooth is not supported on this device");
return; return;
} }
if (BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
unregisterAudioSharingCallbacks(); unregisterAudioSharingCallbacks();
} }
if (mBluetoothDeviceUpdater != null) { if (mBluetoothDeviceUpdater != null) {
@@ -278,7 +278,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
public void onDeviceClick(Preference preference) { public void onDeviceClick(Preference preference) {
final CachedBluetoothDevice cachedDevice = final CachedBluetoothDevice cachedDevice =
((BluetoothDevicePreference) preference).getBluetoothDevice(); ((BluetoothDevicePreference) preference).getBluetoothDevice();
if (BluetoothUtils.isAudioSharingEnabled() && mDialogHandler != null) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext) && mDialogHandler != null) {
mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ true); mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ true);
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider() FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
.action(mContext, SettingsEnums.ACTION_MEDIA_DEVICE_CLICK); .action(mContext, SettingsEnums.ACTION_MEDIA_DEVICE_CLICK);
@@ -294,7 +294,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
fragment.getContext(), fragment.getContext(),
AvailableMediaDeviceGroupController.this, AvailableMediaDeviceGroupController.this,
fragment.getMetricsCategory()); fragment.getMetricsCategory());
if (BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
mDialogHandler = new AudioSharingDialogHandler(mContext, fragment); mDialogHandler = new AudioSharingDialogHandler(mContext, fragment);
} }
} }
@@ -341,7 +341,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
if (isAudioModeOngoingCall(mContext)) { if (isAudioModeOngoingCall(mContext)) {
// in phone call // in phone call
titleResId = R.string.connected_device_call_device_title; titleResId = R.string.connected_device_call_device_title;
} else if (BluetoothUtils.isAudioSharingEnabled() } else if (BluetoothUtils.isAudioSharingUIAvailable(mContext)
&& BluetoothUtils.isBroadcasting(mBtManager)) { && BluetoothUtils.isBroadcasting(mBtManager)) {
// without phone call, in audio sharing // without phone call, in audio sharing
titleResId = R.string.audio_sharing_media_device_group_title; titleResId = R.string.audio_sharing_media_device_group_title;

View File

@@ -80,7 +80,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
+ ", action : " + ", action : "
+ action); + action);
} }
if (BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(context)) {
use(AudioSharingDevicePreferenceController.class).init(this); use(AudioSharingDevicePreferenceController.class).init(this);
} }
use(AvailableMediaDeviceGroupController.class).init(this); use(AvailableMediaDeviceGroupController.class).init(this);

View File

@@ -25,7 +25,7 @@ public class AudioSharingActivity extends SettingsActivity {
@Override @Override
protected void onCreate(Bundle savedState) { protected void onCreate(Bundle savedState) {
super.onCreate(savedState); super.onCreate(savedState);
if (!BluetoothUtils.isAudioSharingEnabled()) { if (!BluetoothUtils.isAudioSharingUIAvailable(this)) {
finish(); finish();
} }
} }

View File

@@ -55,7 +55,8 @@ public abstract class AudioSharingBasePreferenceController extends BasePreferenc
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return (BluetoothUtils.isAudioSharingUIAvailable(mContext))
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -55,7 +55,7 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) { if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
// If device is LE audio device and has a broadcast source, // If device is LE audio device and has a broadcast source,
// it would show in audio sharing devices group. // it would show in audio sharing devices group.
if (BluetoothUtils.isAudioSharingEnabled() if (BluetoothUtils.isAudioSharingUIAvailable(mContext)
&& cachedDevice.isConnectedLeAudioDevice() && cachedDevice.isConnectedLeAudioDevice()
&& BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) { && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) {
isFilterMatched = true; isFilterMatched = true;

View File

@@ -65,11 +65,15 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm
* @param listener The callback to handle the user action on this dialog. * @param listener The callback to handle the user action on this dialog.
*/ */
public static void show( public static void show(
@NonNull Fragment host, @Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems, @NonNull List<AudioSharingDeviceItem> deviceItems,
int checkedItemIndex, int checkedItemIndex,
@NonNull DialogEventListener listener) { @NonNull DialogEventListener listener) {
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -88,6 +92,7 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm
dialog.show(manager, TAG); dialog.show(manager, TAG);
} }
} }
}
@Override @Override
@NonNull @NonNull

View File

@@ -155,7 +155,8 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -44,8 +44,12 @@ public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragmen
* *
* @param host The Fragment this dialog will be hosted. * @param host The Fragment this dialog will be hosted.
*/ */
public static void show(Fragment host) { public static void show(@Nullable Fragment host) {
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -62,6 +66,7 @@ public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragmen
AudioSharingConfirmDialogFragment dialogFrag = new AudioSharingConfirmDialogFragment(); AudioSharingConfirmDialogFragment dialogFrag = new AudioSharingConfirmDialogFragment();
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
@Override @Override
@NonNull @NonNull

View File

@@ -45,6 +45,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment
public static final int SHARE_THEN_PAIR_REQUEST_CODE = 1002; public static final int SHARE_THEN_PAIR_REQUEST_CODE = 1002;
SettingsMainSwitchBar mMainSwitchBar; SettingsMainSwitchBar mMainSwitchBar;
private Context mContext;
private AudioSharingDeviceVolumeGroupController mAudioSharingDeviceVolumeGroupController; private AudioSharingDeviceVolumeGroupController mAudioSharingDeviceVolumeGroupController;
private AudioSharingCallAudioPreferenceController mAudioSharingCallAudioPreferenceController; private AudioSharingCallAudioPreferenceController mAudioSharingCallAudioPreferenceController;
private AudioSharingPlaySoundPreferenceController mAudioSharingPlaySoundPreferenceController; private AudioSharingPlaySoundPreferenceController mAudioSharingPlaySoundPreferenceController;
@@ -78,6 +79,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
mContext = context;
mAudioSharingDeviceVolumeGroupController = mAudioSharingDeviceVolumeGroupController =
use(AudioSharingDeviceVolumeGroupController.class); use(AudioSharingDeviceVolumeGroupController.class);
mAudioSharingDeviceVolumeGroupController.init(this); mAudioSharingDeviceVolumeGroupController.init(this);
@@ -107,11 +109,12 @@ public class AudioSharingDashboardFragment extends DashboardFragment
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
// In share then pair flow, after users be routed to pair new device page and successfully // In share then pair flow, after users be routed to pair new device page and
// pair and connect an LEA headset, the pair fragment will be finished with RESULT_OK // successfully pair and connect an LEA headset, the pair fragment will be finished with
// and EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, pass the BT device to switch bar controller, // RESULT_OK and EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, pass the BT device to switch bar
// which is responsible for adding source to the device with loading indicator. // controller, which is responsible for adding source to the device with loading
// indicator.
if (requestCode == SHARE_THEN_PAIR_REQUEST_CODE) { if (requestCode == SHARE_THEN_PAIR_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
BluetoothDevice btDevice = BluetoothDevice btDevice =
@@ -128,6 +131,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment
} }
} }
} }
}
@Override @Override
public void onAudioSharingStateChanged() { public void onAudioSharingStateChanged() {

View File

@@ -308,7 +308,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() && mBluetoothDeviceUpdater != null return (BluetoothUtils.isAudioSharingUIAvailable(mContext)
&& mBluetoothDeviceUpdater != null)
? AVAILABLE_UNSEARCHABLE ? AVAILABLE_UNSEARCHABLE
: UNSUPPORTED_ON_DEVICE; : UNSUPPORTED_ON_DEVICE;
} }

View File

@@ -84,11 +84,15 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
* @param eventData The eventData to log with for dialog onClick events. * @param eventData The eventData to log with for dialog onClick events.
*/ */
public static void show( public static void show(
@NonNull Fragment host, @Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems, @NonNull List<AudioSharingDeviceItem> deviceItems,
@NonNull DialogEventListener listener, @NonNull DialogEventListener listener,
@NonNull Pair<Integer, Object>[] eventData) { @NonNull Pair<Integer, Object>[] eventData) {
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -116,6 +120,7 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
dialogFrag.setArguments(bundle); dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
/** Return the tag of {@link AudioSharingDialogFragment} dialog. */ /** Return the tag of {@link AudioSharingDialogFragment} dialog. */
public static @NonNull String tag() { public static @NonNull String tag() {

View File

@@ -80,12 +80,16 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
* @param eventData The eventData to log with for dialog onClick events. * @param eventData The eventData to log with for dialog onClick events.
*/ */
public static void show( public static void show(
@NonNull Fragment host, @Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems, @NonNull List<AudioSharingDeviceItem> deviceItems,
@NonNull CachedBluetoothDevice newDevice, @NonNull CachedBluetoothDevice newDevice,
@NonNull DialogEventListener listener, @NonNull DialogEventListener listener,
@NonNull Pair<Integer, Object>[] eventData) { @NonNull Pair<Integer, Object>[] eventData) {
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -122,17 +126,7 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
+ "dismiss current dialog.", + "dismiss current dialog.",
newGroupId)); newGroupId));
dialog.dismiss(); dialog.dismiss();
var unused = logDialogAutoDismiss(dialog);
ThreadUtils.postOnBackgroundThread(
() ->
FeatureFactory.getFeatureFactory()
.getMetricsFeatureProvider()
.action(
dialog.getContext(),
SettingsEnums
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
SettingsEnums
.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
} }
} }
sListener = listener; sListener = listener;
@@ -147,6 +141,7 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
dialogFrag.setArguments(bundle); dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
/** Return the tag of {@link AudioSharingDisconnectDialogFragment} dialog. */ /** Return the tag of {@link AudioSharingDisconnectDialogFragment} dialog. */
public static @NonNull String tag() { public static @NonNull String tag() {
@@ -216,4 +211,17 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
AudioSharingDeviceAdapter.ActionType.REMOVE)); AudioSharingDeviceAdapter.ActionType.REMOVE));
return builder.build(); return builder.build();
} }
private static void logDialogAutoDismiss(AlertDialog dialog) {
var unused =
ThreadUtils.postOnBackgroundThread(
() -> FeatureFactory.getFeatureFactory()
.getMetricsFeatureProvider()
.action(
dialog.getContext(),
SettingsEnums
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
SettingsEnums
.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
}
} }

View File

@@ -46,7 +46,11 @@ public class AudioSharingErrorDialogFragment extends InstrumentedDialogFragment
* @param host The Fragment this dialog will be hosted. * @param host The Fragment this dialog will be hosted.
*/ */
public static void show(@Nullable Fragment host) { public static void show(@Nullable Fragment host) {
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -68,6 +72,7 @@ public class AudioSharingErrorDialogFragment extends InstrumentedDialogFragment
AudioSharingErrorDialogFragment dialogFrag = new AudioSharingErrorDialogFragment(); AudioSharingErrorDialogFragment dialogFrag = new AudioSharingErrorDialogFragment();
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
@Override @Override
@NonNull @NonNull

View File

@@ -62,7 +62,11 @@ public class AudioSharingIncompatibleDialogFragment extends InstrumentedDialogFr
*/ */
public static void show(@Nullable Fragment host, @NonNull String deviceName, public static void show(@Nullable Fragment host, @NonNull String deviceName,
@NonNull DialogEventListener listener) { @NonNull DialogEventListener listener) {
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -89,6 +93,7 @@ public class AudioSharingIncompatibleDialogFragment extends InstrumentedDialogFr
dialogFrag.setArguments(bundle); dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
@Override @Override
@NonNull @NonNull

View File

@@ -77,12 +77,16 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
* @param eventData The eventData to log with for dialog onClick events. * @param eventData The eventData to log with for dialog onClick events.
*/ */
public static void show( public static void show(
@NonNull Fragment host, @Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems, @NonNull List<AudioSharingDeviceItem> deviceItems,
@NonNull CachedBluetoothDevice newDevice, @NonNull CachedBluetoothDevice newDevice,
@NonNull DialogEventListener listener, @NonNull DialogEventListener listener,
@NonNull Pair<Integer, Object>[] eventData) { @NonNull Pair<Integer, Object>[] eventData) {
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -107,11 +111,13 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
final Bundle bundle = new Bundle(); final Bundle bundle = new Bundle();
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems); bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName()); bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
final AudioSharingJoinDialogFragment dialogFrag = new AudioSharingJoinDialogFragment(); final AudioSharingJoinDialogFragment dialogFrag =
new AudioSharingJoinDialogFragment();
dialogFrag.setArguments(bundle); dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
} }
}
/** Return the tag of {@link AudioSharingJoinDialogFragment} dialog. */ /** Return the tag of {@link AudioSharingJoinDialogFragment} dialog. */
public static @NonNull String tag() { public static @NonNull String tag() {

View File

@@ -174,7 +174,8 @@ public class AudioSharingNamePreferenceController extends BasePreferenceControll
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -113,7 +113,8 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -57,7 +57,7 @@ public class AudioSharingPlaySoundPreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return (mRingtone != null && BluetoothUtils.isAudioSharingEnabled()) return (mRingtone != null && BluetoothUtils.isAudioSharingUIAvailable(mContext))
? AVAILABLE ? AVAILABLE
: UNSUPPORTED_ON_DEVICE; : UNSUPPORTED_ON_DEVICE;
} }

View File

@@ -135,7 +135,8 @@ public class AudioSharingPreferenceController extends BasePreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -65,7 +65,11 @@ public class AudioSharingProgressDialogFragment extends InstrumentedDialogFragme
* @param message The content to be shown on the dialog. * @param message The content to be shown on the dialog.
*/ */
public static void show(@Nullable Fragment host, @NonNull String message) { public static void show(@Nullable Fragment host, @NonNull String message) {
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -95,14 +99,20 @@ public class AudioSharingProgressDialogFragment extends InstrumentedDialogFragme
Log.d(TAG, "Show up the progress dialog."); Log.d(TAG, "Show up the progress dialog.");
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(BUNDLE_KEY_MESSAGE, message); args.putString(BUNDLE_KEY_MESSAGE, message);
AudioSharingProgressDialogFragment dialogFrag = new AudioSharingProgressDialogFragment(); AudioSharingProgressDialogFragment dialogFrag =
new AudioSharingProgressDialogFragment();
dialogFrag.setArguments(args); dialogFrag.setArguments(args);
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
/** Dismiss the {@link AudioSharingProgressDialogFragment} dialog. */ /** Dismiss the {@link AudioSharingProgressDialogFragment} dialog. */
public static void dismiss(@Nullable Fragment host) { public static void dismiss(@Nullable Fragment host) {
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to dismiss dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -116,6 +126,7 @@ public class AudioSharingProgressDialogFragment extends InstrumentedDialogFragme
dialog.dismiss(); dialog.dismiss();
} }
} }
}
@Override @Override
@NonNull @NonNull

View File

@@ -62,7 +62,7 @@ public class AudioSharingReceiver extends BroadcastReceiver {
intent.getIntExtra( intent.getIntExtra(
LocalBluetoothLeBroadcast.EXTRA_LE_AUDIO_SHARING_STATE, -1); LocalBluetoothLeBroadcast.EXTRA_LE_AUDIO_SHARING_STATE, -1);
if (state == LocalBluetoothLeBroadcast.BROADCAST_STATE_ON) { if (state == LocalBluetoothLeBroadcast.BROADCAST_STATE_ON) {
if (!BluetoothUtils.isAudioSharingEnabled()) { if (!BluetoothUtils.isAudioSharingUIAvailable(context)) {
Log.w(TAG, "Skip showSharingNotification, feature disabled."); Log.w(TAG, "Skip showSharingNotification, feature disabled.");
return; return;
} }
@@ -85,7 +85,7 @@ public class AudioSharingReceiver extends BroadcastReceiver {
} }
break; break;
case ACTION_LE_AUDIO_SHARING_STOP: case ACTION_LE_AUDIO_SHARING_STOP:
if (BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(context)) {
LocalBluetoothManager manager = Utils.getLocalBtManager(context); LocalBluetoothManager manager = Utils.getLocalBtManager(context);
if (BluetoothUtils.isBroadcasting(manager)) { if (BluetoothUtils.isBroadcasting(manager)) {
AudioSharingUtils.stopBroadcasting(manager); AudioSharingUtils.stopBroadcasting(manager);

View File

@@ -77,12 +77,16 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
* @param eventData The eventData to log with for dialog onClick events. * @param eventData The eventData to log with for dialog onClick events.
*/ */
public static void show( public static void show(
@NonNull Fragment host, @Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems, @NonNull List<AudioSharingDeviceItem> deviceItems,
@NonNull CachedBluetoothDevice newDevice, @NonNull CachedBluetoothDevice newDevice,
@NonNull DialogEventListener listener, @NonNull DialogEventListener listener,
@NonNull Pair<Integer, Object>[] eventData) { @NonNull Pair<Integer, Object>[] eventData) {
if (!BluetoothUtils.isAudioSharingEnabled()) return; if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager; final FragmentManager manager;
try { try {
manager = host.getChildFragmentManager(); manager = host.getChildFragmentManager();
@@ -119,16 +123,7 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
+ "dismiss current dialog.", + "dismiss current dialog.",
newGroupId)); newGroupId));
dialog.dismiss(); dialog.dismiss();
var unused = logDialogAutoDismiss(dialog);
ThreadUtils.postOnBackgroundThread(
() ->
FeatureFactory.getFeatureFactory()
.getMetricsFeatureProvider()
.action(
dialog.getContext(),
SettingsEnums
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
} }
} }
sListener = listener; sListener = listener;
@@ -142,6 +137,7 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
dialogFrag.setArguments(bundle); dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG); dialogFrag.show(manager, TAG);
} }
}
/** Return the tag of {@link AudioSharingStopDialogFragment} dialog. */ /** Return the tag of {@link AudioSharingStopDialogFragment} dialog. */
public static @NonNull String tag() { public static @NonNull String tag() {
@@ -221,4 +217,16 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
AudioSharingDialogHelper.updateMessageStyle(dialog); AudioSharingDialogHelper.updateMessageStyle(dialog);
return dialog; return dialog;
} }
private static void logDialogAutoDismiss(AlertDialog dialog) {
var unused =
ThreadUtils.postOnBackgroundThread(
() -> FeatureFactory.getFeatureFactory()
.getMetricsFeatureProvider()
.action(
dialog.getContext(),
SettingsEnums
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
}
} }

View File

@@ -426,9 +426,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
() -> { () -> {
mSwitchBar.setEnabled(true); mSwitchBar.setEnabled(true);
mSwitchBar.setChecked(false); mSwitchBar.setChecked(false);
if (mFragment != null) {
AudioSharingConfirmDialogFragment.show(mFragment); AudioSharingConfirmDialogFragment.show(mFragment);
}
}); });
return; return;
} }
@@ -447,7 +445,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override
@@ -733,13 +732,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
}; };
AudioSharingUtils.postOnMainThread( AudioSharingUtils.postOnMainThread(
mContext, mContext,
() -> { () -> AudioSharingDialogFragment.show(
// Check nullability to pass NullAway check mFragment, mDeviceItemsForSharing, listener, eventData));
if (mFragment != null) {
AudioSharingDialogFragment.show(
mFragment, mDeviceItemsForSharing, listener, eventData);
}
});
} }
private void showErrorDialog() { private void showErrorDialog() {

View File

@@ -91,7 +91,8 @@ public class StreamSettingsCategoryController extends BasePreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -214,15 +214,16 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
} }
private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) { private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) {
if (!BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_FEATURE_UNSUPPORTED;
}
if (!hasConnectedDevice) { if (!hasConnectedDevice) {
return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_NO_LE_DEVICE; return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_NO_LE_DEVICE;
} }
return hasMetadata return hasMetadata
? SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_LISTEN ? SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_LISTEN
: SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_DATA_ERROR; : SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_DATA_ERROR;
} else {
return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_FEATURE_UNSUPPORTED;
}
} }
@Nullable @Nullable

View File

@@ -50,7 +50,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
@Override @Override
protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) { protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) {
if (BluetoothUtils.isAudioSharingEnabled() if (BluetoothUtils.isAudioSharingUIAvailable(this)
&& !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent"); Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent");
mSavedState = savedState; mSavedState = savedState;
@@ -67,7 +67,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
@Override @Override
public void onStart() { public void onStart() {
if (BluetoothUtils.isAudioSharingEnabled() if (BluetoothUtils.isAudioSharingUIAvailable(this)
&& !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
Log.d(TAG, "onStart() : supported but not ready, listen to service ready"); Log.d(TAG, "onStart() : supported but not ready, listen to service ready");
if (mProfileManager != null) { if (mProfileManager != null) {
@@ -87,7 +87,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
@Override @Override
public void onServiceConnected() { public void onServiceConnected() {
if (BluetoothUtils.isAudioSharingEnabled() if (BluetoothUtils.isAudioSharingUIAvailable(this)
&& AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { && AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
if (mProfileManager != null) { if (mProfileManager != null) {
mProfileManager.removeServiceListener(this); mProfileManager.removeServiceListener(this);

View File

@@ -122,7 +122,7 @@ public class AudioStreamMediaService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
if (!BluetoothUtils.isAudioSharingEnabled()) { if (!BluetoothUtils.isAudioSharingUIAvailable(this)) {
return; return;
} }
Log.d(TAG, "onCreate()"); Log.d(TAG, "onCreate()");
@@ -181,9 +181,7 @@ public class AudioStreamMediaService extends Service {
public void onDestroy() { public void onDestroy() {
Log.d(TAG, "onDestroy()"); Log.d(TAG, "onDestroy()");
super.onDestroy(); super.onDestroy();
if (!BluetoothUtils.isAudioSharingEnabled()) { if (BluetoothUtils.isAudioSharingUIAvailable(this)) {
return;
}
if (mDevices != null) { if (mDevices != null) {
mDevices.clear(); mDevices.clear();
mDevices = null; mDevices = null;
@@ -197,7 +195,8 @@ public class AudioStreamMediaService extends Service {
mExecutor.execute( mExecutor.execute(
() -> { () -> {
if (mLocalBtManager != null) { if (mLocalBtManager != null) {
mLocalBtManager.getEventManager().unregisterCallback(mBluetoothCallback); mLocalBtManager.getEventManager().unregisterCallback(
mBluetoothCallback);
} }
if (mLeBroadcastAssistant != null && mBroadcastAssistantCallback != null) { if (mLeBroadcastAssistant != null && mBroadcastAssistantCallback != null) {
mLeBroadcastAssistant.unregisterServiceCallBack( mLeBroadcastAssistant.unregisterServiceCallBack(
@@ -208,6 +207,7 @@ public class AudioStreamMediaService extends Service {
} }
}); });
} }
}
@Override @Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId) { public int onStartCommand(@Nullable Intent intent, int flags, int startId) {