Merge "[Audiosharing] Enable audio sharing UI when preview option on." into main
This commit is contained in:
@@ -77,9 +77,9 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
// It would show in Available Devices group if the audio sharing flag is disabled or
|
||||
// the device is not in the audio sharing session.
|
||||
if (cachedDevice.isConnectedLeAudioDevice()) {
|
||||
if (BluetoothUtils.isAudioSharingEnabled()
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)
|
||||
&& BluetoothUtils.hasConnectedBroadcastSource(
|
||||
cachedDevice, mLocalBtManager)) {
|
||||
cachedDevice, mLocalBtManager)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Filter out device : "
|
||||
|
@@ -228,19 +228,19 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
final BluetoothDevice device = cachedDevice.getDevice();
|
||||
if (device != null
|
||||
&& mSelectedList.contains(device)) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(getContext())) {
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT
|
||||
&& state == BluetoothAdapter.STATE_CONNECTED
|
||||
&& device.equals(mJustBonded)
|
||||
&& mShouldTriggerAudioSharingShareThenPairFlow) {
|
||||
Log.d(getLogTag(),
|
||||
"onProfileConnectionStateChanged, assistant profile connected");
|
||||
dismissConnectingDialog();
|
||||
mHandler.removeMessages(AUTO_DISMISS_MESSAGE_ID);
|
||||
finishFragmentWithResultForAudioSharing(device);
|
||||
}
|
||||
} else {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT
|
||||
&& state == BluetoothAdapter.STATE_CONNECTED
|
||||
&& device.equals(mJustBonded)
|
||||
&& mShouldTriggerAudioSharingShareThenPairFlow) {
|
||||
Log.d(getLogTag(),
|
||||
"onProfileConnectionStateChanged, assistant profile connected");
|
||||
dismissConnectingDialog();
|
||||
mHandler.removeMessages(AUTO_DISMISS_MESSAGE_ID);
|
||||
finishFragmentWithResultForAudioSharing(device);
|
||||
}
|
||||
} else {
|
||||
onDeviceDeleted(cachedDevice);
|
||||
@@ -309,15 +309,17 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
|
||||
@VisibleForTesting
|
||||
boolean shouldTriggerAudioSharingShareThenPairFlow() {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return false;
|
||||
Activity activity = getActivity();
|
||||
Intent intent = activity == null ? null : activity.getIntent();
|
||||
Bundle args =
|
||||
intent == null ? null :
|
||||
intent.getBundleExtra(
|
||||
SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
return args != null
|
||||
&& args.getBoolean(EXTRA_PAIR_AND_JOIN_SHARING, false);
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(getContext())) {
|
||||
Activity activity = getActivity();
|
||||
Intent intent = activity == null ? null : activity.getIntent();
|
||||
Bundle args =
|
||||
intent == null ? null :
|
||||
intent.getBundleExtra(
|
||||
SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
return args != null
|
||||
&& args.getBoolean(EXTRA_PAIR_AND_JOIN_SHARING, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addOnMetadataChangedListener(@Nullable BluetoothDevice device) {
|
||||
|
@@ -179,7 +179,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
super(context, KEY);
|
||||
mBtManager = Utils.getLocalBtManager(mContext);
|
||||
mExecutor = Executors.newSingleThreadExecutor();
|
||||
if (BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||
mBroadcast =
|
||||
mBtManager == null
|
||||
? null
|
||||
@@ -200,7 +200,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
Log.d(TAG, "onStart() Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||
registerAudioSharingCallbacks();
|
||||
}
|
||||
mBtManager.getEventManager().registerCallback(this);
|
||||
@@ -216,7 +216,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
Log.d(TAG, "onStop() Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||
unregisterAudioSharingCallbacks();
|
||||
}
|
||||
if (mBluetoothDeviceUpdater != null) {
|
||||
@@ -278,7 +278,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
public void onDeviceClick(Preference preference) {
|
||||
final CachedBluetoothDevice cachedDevice =
|
||||
((BluetoothDevicePreference) preference).getBluetoothDevice();
|
||||
if (BluetoothUtils.isAudioSharingEnabled() && mDialogHandler != null) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext) && mDialogHandler != null) {
|
||||
mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ true);
|
||||
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
|
||||
.action(mContext, SettingsEnums.ACTION_MEDIA_DEVICE_CLICK);
|
||||
@@ -294,7 +294,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
fragment.getContext(),
|
||||
AvailableMediaDeviceGroupController.this,
|
||||
fragment.getMetricsCategory());
|
||||
if (BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||
mDialogHandler = new AudioSharingDialogHandler(mContext, fragment);
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
if (isAudioModeOngoingCall(mContext)) {
|
||||
// in phone call
|
||||
titleResId = R.string.connected_device_call_device_title;
|
||||
} else if (BluetoothUtils.isAudioSharingEnabled()
|
||||
} else if (BluetoothUtils.isAudioSharingUIAvailable(mContext)
|
||||
&& BluetoothUtils.isBroadcasting(mBtManager)) {
|
||||
// without phone call, in audio sharing
|
||||
titleResId = R.string.audio_sharing_media_device_group_title;
|
||||
|
@@ -80,7 +80,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
||||
+ ", action : "
|
||||
+ action);
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
use(AudioSharingDevicePreferenceController.class).init(this);
|
||||
}
|
||||
use(AvailableMediaDeviceGroupController.class).init(this);
|
||||
|
@@ -25,7 +25,7 @@ public class AudioSharingActivity extends SettingsActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(this)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@@ -55,7 +55,8 @@ public abstract class AudioSharingBasePreferenceController extends BasePreferenc
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return (BluetoothUtils.isAudioSharingUIAvailable(mContext))
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -55,7 +55,7 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
|
||||
// If device is LE audio device and has a broadcast source,
|
||||
// it would show in audio sharing devices group.
|
||||
if (BluetoothUtils.isAudioSharingEnabled()
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)
|
||||
&& cachedDevice.isConnectedLeAudioDevice()
|
||||
&& BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) {
|
||||
isFilterMatched = true;
|
||||
|
@@ -65,27 +65,32 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm
|
||||
* @param listener The callback to handle the user action on this dialog.
|
||||
*/
|
||||
public static void show(
|
||||
@NonNull Fragment host,
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
int checkedItemIndex,
|
||||
@NonNull DialogEventListener listener) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
sListener = listener;
|
||||
if (manager.findFragmentByTag(TAG) == null) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
bundle.putInt(BUNDLE_KEY_CHECKED_ITEM_INDEX, checkedItemIndex);
|
||||
final AudioSharingCallAudioDialogFragment dialog =
|
||||
new AudioSharingCallAudioDialogFragment();
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(manager, TAG);
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
sListener = listener;
|
||||
if (manager.findFragmentByTag(TAG) == null) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
bundle.putInt(BUNDLE_KEY_CHECKED_ITEM_INDEX, checkedItemIndex);
|
||||
final AudioSharingCallAudioDialogFragment dialog =
|
||||
new AudioSharingCallAudioDialogFragment();
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(manager, TAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -155,7 +155,8 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -44,23 +44,28 @@ public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragmen
|
||||
*
|
||||
* @param host The Fragment this dialog will be hosted.
|
||||
*/
|
||||
public static void show(Fragment host) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
public static void show(@Nullable Fragment host) {
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the confirm dialog.");
|
||||
AudioSharingConfirmDialogFragment dialogFrag = new AudioSharingConfirmDialogFragment();
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
Log.d(TAG, "Show up the confirm dialog.");
|
||||
AudioSharingConfirmDialogFragment dialogFrag = new AudioSharingConfirmDialogFragment();
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -45,6 +45,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment
|
||||
public static final int SHARE_THEN_PAIR_REQUEST_CODE = 1002;
|
||||
|
||||
SettingsMainSwitchBar mMainSwitchBar;
|
||||
private Context mContext;
|
||||
private AudioSharingDeviceVolumeGroupController mAudioSharingDeviceVolumeGroupController;
|
||||
private AudioSharingCallAudioPreferenceController mAudioSharingCallAudioPreferenceController;
|
||||
private AudioSharingPlaySoundPreferenceController mAudioSharingPlaySoundPreferenceController;
|
||||
@@ -78,6 +79,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mContext = context;
|
||||
mAudioSharingDeviceVolumeGroupController =
|
||||
use(AudioSharingDeviceVolumeGroupController.class);
|
||||
mAudioSharingDeviceVolumeGroupController.init(this);
|
||||
@@ -107,23 +109,25 @@ public class AudioSharingDashboardFragment extends DashboardFragment
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
// In share then pair flow, after users be routed to pair new device page and successfully
|
||||
// pair and connect an LEA headset, the pair fragment will be finished with RESULT_OK
|
||||
// and EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, pass the BT device to switch bar controller,
|
||||
// which is responsible for adding source to the device with loading indicator.
|
||||
if (requestCode == SHARE_THEN_PAIR_REQUEST_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
BluetoothDevice btDevice =
|
||||
data != null
|
||||
? data.getParcelableExtra(EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE,
|
||||
BluetoothDevice.class)
|
||||
: null;
|
||||
Log.d(TAG, "onActivityResult: RESULT_OK with device = " + btDevice);
|
||||
if (btDevice != null) {
|
||||
var unused = ThreadUtils.postOnBackgroundThread(
|
||||
() -> mAudioSharingSwitchBarController.handleAutoAddSourceAfterPair(
|
||||
btDevice));
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||
// In share then pair flow, after users be routed to pair new device page and
|
||||
// successfully pair and connect an LEA headset, the pair fragment will be finished with
|
||||
// RESULT_OK and EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, pass the BT device to switch bar
|
||||
// controller, which is responsible for adding source to the device with loading
|
||||
// indicator.
|
||||
if (requestCode == SHARE_THEN_PAIR_REQUEST_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
BluetoothDevice btDevice =
|
||||
data != null
|
||||
? data.getParcelableExtra(EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE,
|
||||
BluetoothDevice.class)
|
||||
: null;
|
||||
Log.d(TAG, "onActivityResult: RESULT_OK with device = " + btDevice);
|
||||
if (btDevice != null) {
|
||||
var unused = ThreadUtils.postOnBackgroundThread(
|
||||
() -> mAudioSharingSwitchBarController.handleAutoAddSourceAfterPair(
|
||||
btDevice));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -308,7 +308,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() && mBluetoothDeviceUpdater != null
|
||||
return (BluetoothUtils.isAudioSharingUIAvailable(mContext)
|
||||
&& mBluetoothDeviceUpdater != null)
|
||||
? AVAILABLE_UNSEARCHABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
@@ -84,37 +84,42 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*/
|
||||
public static void show(
|
||||
@NonNull Fragment host,
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull DialogEventListener listener,
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
sHost = host;
|
||||
sListener = listener;
|
||||
sEventData = eventData;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
AudioSharingDialogFragment dialogFrag = new AudioSharingDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
sHost = host;
|
||||
sListener = listener;
|
||||
sEventData = eventData;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
AudioSharingDialogFragment dialogFrag = new AudioSharingDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
/** Return the tag of {@link AudioSharingDialogFragment} dialog. */
|
||||
|
@@ -80,72 +80,67 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*/
|
||||
public static void show(
|
||||
@NonNull Fragment host,
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull CachedBluetoothDevice newDevice,
|
||||
@NonNull DialogEventListener listener,
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
int newGroupId = BluetoothUtils.getGroupId(newDevice);
|
||||
if (sNewDevice != null && newGroupId == BluetoothUtils.getGroupId(sNewDevice)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for the same device group %d, "
|
||||
+ "update the content.",
|
||||
newGroupId));
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for new device group %d, "
|
||||
+ "dismiss current dialog.",
|
||||
newGroupId));
|
||||
dialog.dismiss();
|
||||
var unused =
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() ->
|
||||
FeatureFactory.getFeatureFactory()
|
||||
.getMetricsFeatureProvider()
|
||||
.action(
|
||||
dialog.getContext(),
|
||||
SettingsEnums
|
||||
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
|
||||
SettingsEnums
|
||||
.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
int newGroupId = BluetoothUtils.getGroupId(newDevice);
|
||||
if (sNewDevice != null && newGroupId == BluetoothUtils.getGroupId(sNewDevice)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for the same device group %d, "
|
||||
+ "update the content.",
|
||||
newGroupId));
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
return;
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for new device group %d, "
|
||||
+ "dismiss current dialog.",
|
||||
newGroupId));
|
||||
dialog.dismiss();
|
||||
logDialogAutoDismiss(dialog);
|
||||
}
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingDisconnectDialogFragment dialogFrag =
|
||||
new AudioSharingDisconnectDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingDisconnectDialogFragment dialogFrag =
|
||||
new AudioSharingDisconnectDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
/** Return the tag of {@link AudioSharingDisconnectDialogFragment} dialog. */
|
||||
@@ -216,4 +211,17 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
|
||||
AudioSharingDeviceAdapter.ActionType.REMOVE));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@@ -46,27 +46,32 @@ public class AudioSharingErrorDialogFragment extends InstrumentedDialogFragment
|
||||
* @param host The Fragment this dialog will be hosted.
|
||||
*/
|
||||
public static void show(@Nullable Fragment host) {
|
||||
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the error dialog.");
|
||||
AudioSharingErrorDialogFragment dialogFrag = new AudioSharingErrorDialogFragment();
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the error dialog.");
|
||||
AudioSharingErrorDialogFragment dialogFrag = new AudioSharingErrorDialogFragment();
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -62,32 +62,37 @@ public class AudioSharingIncompatibleDialogFragment extends InstrumentedDialogFr
|
||||
*/
|
||||
public static void show(@Nullable Fragment host, @NonNull String deviceName,
|
||||
@NonNull DialogEventListener listener) {
|
||||
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
sListener = listener;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the incompatible device dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(BUNDLE_KEY_DEVICE_NAME, deviceName);
|
||||
AudioSharingIncompatibleDialogFragment dialogFrag =
|
||||
new AudioSharingIncompatibleDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
sListener = listener;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Show up the incompatible device dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(BUNDLE_KEY_DEVICE_NAME, deviceName);
|
||||
AudioSharingIncompatibleDialogFragment dialogFrag =
|
||||
new AudioSharingIncompatibleDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -77,39 +77,45 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*/
|
||||
public static void show(
|
||||
@NonNull Fragment host,
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull CachedBluetoothDevice newDevice,
|
||||
@NonNull DialogEventListener listener,
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, update the content.");
|
||||
updateDialog(deviceItems, newDevice.getName(), dialog);
|
||||
} else {
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
final AudioSharingJoinDialogFragment dialogFrag = new AudioSharingJoinDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, update the content.");
|
||||
updateDialog(deviceItems, newDevice.getName(), dialog);
|
||||
} else {
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
final AudioSharingJoinDialogFragment dialogFrag =
|
||||
new AudioSharingJoinDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -174,7 +174,8 @@ public class AudioSharingNamePreferenceController extends BasePreferenceControll
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -113,7 +113,8 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -57,7 +57,7 @@ public class AudioSharingPlaySoundPreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return (mRingtone != null && BluetoothUtils.isAudioSharingEnabled())
|
||||
return (mRingtone != null && BluetoothUtils.isAudioSharingUIAvailable(mContext))
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
@@ -135,7 +135,8 @@ public class AudioSharingPreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -65,55 +65,66 @@ public class AudioSharingProgressDialogFragment extends InstrumentedDialogFragme
|
||||
* @param message The content to be shown on the dialog.
|
||||
*/
|
||||
public static void show(@Nullable Fragment host, @NonNull String message) {
|
||||
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
if (!sMessage.equals(message)) {
|
||||
Log.d(TAG, "Update dialog message.");
|
||||
TextView messageView = dialog.findViewById(R.id.message);
|
||||
if (messageView != null) {
|
||||
messageView.setText(message);
|
||||
}
|
||||
sMessage = message;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
if (!sMessage.equals(message)) {
|
||||
Log.d(TAG, "Update dialog message.");
|
||||
TextView messageView = dialog.findViewById(R.id.message);
|
||||
if (messageView != null) {
|
||||
messageView.setText(message);
|
||||
}
|
||||
sMessage = message;
|
||||
}
|
||||
Log.d(TAG, "Dialog is showing, return.");
|
||||
return;
|
||||
}
|
||||
sMessage = message;
|
||||
Log.d(TAG, "Show up the progress dialog.");
|
||||
Bundle args = new Bundle();
|
||||
args.putString(BUNDLE_KEY_MESSAGE, message);
|
||||
AudioSharingProgressDialogFragment dialogFrag =
|
||||
new AudioSharingProgressDialogFragment();
|
||||
dialogFrag.setArguments(args);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
sMessage = message;
|
||||
Log.d(TAG, "Show up the progress dialog.");
|
||||
Bundle args = new Bundle();
|
||||
args.putString(BUNDLE_KEY_MESSAGE, message);
|
||||
AudioSharingProgressDialogFragment dialogFrag = new AudioSharingProgressDialogFragment();
|
||||
dialogFrag.setArguments(args);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
/** Dismiss the {@link AudioSharingProgressDialogFragment} dialog. */
|
||||
public static void dismiss(@Nullable Fragment host) {
|
||||
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to dismiss dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to dismiss dialog, host is null");
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, dismiss.");
|
||||
dialog.dismiss();
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to dismiss dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, dismiss.");
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -62,7 +62,7 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
intent.getIntExtra(
|
||||
LocalBluetoothLeBroadcast.EXTRA_LE_AUDIO_SHARING_STATE, -1);
|
||||
if (state == LocalBluetoothLeBroadcast.BROADCAST_STATE_ON) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
Log.w(TAG, "Skip showSharingNotification, feature disabled.");
|
||||
return;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
}
|
||||
break;
|
||||
case ACTION_LE_AUDIO_SHARING_STOP:
|
||||
if (BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
if (BluetoothUtils.isBroadcasting(manager)) {
|
||||
AudioSharingUtils.stopBroadcasting(manager);
|
||||
|
@@ -77,70 +77,66 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*/
|
||||
public static void show(
|
||||
@NonNull Fragment host,
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull CachedBluetoothDevice newDevice,
|
||||
@NonNull DialogEventListener listener,
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
int newGroupId = BluetoothUtils.getGroupId(newDevice);
|
||||
if (sCachedDevice != null
|
||||
&& newGroupId == BluetoothUtils.getGroupId(sCachedDevice)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for the same device group %d, return.",
|
||||
newGroupId));
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for new device group %d, "
|
||||
+ "dismiss current dialog.",
|
||||
newGroupId));
|
||||
dialog.dismiss();
|
||||
var unused =
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() ->
|
||||
FeatureFactory.getFeatureFactory()
|
||||
.getMetricsFeatureProvider()
|
||||
.action(
|
||||
dialog.getContext(),
|
||||
SettingsEnums
|
||||
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
|
||||
SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
int newGroupId = BluetoothUtils.getGroupId(newDevice);
|
||||
if (sCachedDevice != null
|
||||
&& newGroupId == BluetoothUtils.getGroupId(sCachedDevice)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for the same device group %d, return.",
|
||||
newGroupId));
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
return;
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for new device group %d, "
|
||||
+ "dismiss current dialog.",
|
||||
newGroupId));
|
||||
dialog.dismiss();
|
||||
logDialogAutoDismiss(dialog);
|
||||
}
|
||||
}
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingStopDialogFragment dialogFrag = new AudioSharingStopDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingStopDialogFragment dialogFrag = new AudioSharingStopDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
/** Return the tag of {@link AudioSharingStopDialogFragment} dialog. */
|
||||
@@ -221,4 +217,16 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
AudioSharingDialogHelper.updateMessageStyle(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));
|
||||
}
|
||||
}
|
||||
|
@@ -426,9 +426,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
() -> {
|
||||
mSwitchBar.setEnabled(true);
|
||||
mSwitchBar.setChecked(false);
|
||||
if (mFragment != null) {
|
||||
AudioSharingConfirmDialogFragment.show(mFragment);
|
||||
}
|
||||
AudioSharingConfirmDialogFragment.show(mFragment);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -447,7 +445,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -733,13 +732,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
};
|
||||
AudioSharingUtils.postOnMainThread(
|
||||
mContext,
|
||||
() -> {
|
||||
// Check nullability to pass NullAway check
|
||||
if (mFragment != null) {
|
||||
AudioSharingDialogFragment.show(
|
||||
mFragment, mDeviceItemsForSharing, listener, eventData);
|
||||
}
|
||||
});
|
||||
() -> AudioSharingDialogFragment.show(
|
||||
mFragment, mDeviceItemsForSharing, listener, eventData));
|
||||
}
|
||||
|
||||
private void showErrorDialog() {
|
||||
|
@@ -91,7 +91,8 @@ public class StreamSettingsCategoryController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return BluetoothUtils.isAudioSharingUIAvailable(mContext) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -214,15 +214,16 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
||||
}
|
||||
|
||||
private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(mContext)) {
|
||||
if (!hasConnectedDevice) {
|
||||
return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_NO_LE_DEVICE;
|
||||
}
|
||||
return hasMetadata
|
||||
? SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_LISTEN
|
||||
: SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_DATA_ERROR;
|
||||
} else {
|
||||
return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
if (!hasConnectedDevice) {
|
||||
return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_NO_LE_DEVICE;
|
||||
}
|
||||
return hasMetadata
|
||||
? SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_LISTEN
|
||||
: SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_DATA_ERROR;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@@ -50,7 +50,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
|
||||
|
||||
@Override
|
||||
protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) {
|
||||
if (BluetoothUtils.isAudioSharingEnabled()
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(this)
|
||||
&& !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
|
||||
Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent");
|
||||
mSavedState = savedState;
|
||||
@@ -67,7 +67,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (BluetoothUtils.isAudioSharingEnabled()
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(this)
|
||||
&& !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
|
||||
Log.d(TAG, "onStart() : supported but not ready, listen to service ready");
|
||||
if (mProfileManager != null) {
|
||||
@@ -87,7 +87,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
|
||||
|
||||
@Override
|
||||
public void onServiceConnected() {
|
||||
if (BluetoothUtils.isAudioSharingEnabled()
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(this)
|
||||
&& AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
|
||||
if (mProfileManager != null) {
|
||||
mProfileManager.removeServiceListener(this);
|
||||
|
@@ -122,7 +122,7 @@ public class AudioStreamMediaService extends Service {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) {
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(this)) {
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "onCreate()");
|
||||
@@ -181,32 +181,32 @@ public class AudioStreamMediaService extends Service {
|
||||
public void onDestroy() {
|
||||
Log.d(TAG, "onDestroy()");
|
||||
super.onDestroy();
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) {
|
||||
return;
|
||||
}
|
||||
if (mDevices != null) {
|
||||
mDevices.clear();
|
||||
mDevices = null;
|
||||
}
|
||||
synchronized (mLocalSessionLock) {
|
||||
if (mLocalSession != null) {
|
||||
mLocalSession.release();
|
||||
mLocalSession = null;
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(this)) {
|
||||
if (mDevices != null) {
|
||||
mDevices.clear();
|
||||
mDevices = null;
|
||||
}
|
||||
synchronized (mLocalSessionLock) {
|
||||
if (mLocalSession != null) {
|
||||
mLocalSession.release();
|
||||
mLocalSession = null;
|
||||
}
|
||||
}
|
||||
mExecutor.execute(
|
||||
() -> {
|
||||
if (mLocalBtManager != null) {
|
||||
mLocalBtManager.getEventManager().unregisterCallback(
|
||||
mBluetoothCallback);
|
||||
}
|
||||
if (mLeBroadcastAssistant != null && mBroadcastAssistantCallback != null) {
|
||||
mLeBroadcastAssistant.unregisterServiceCallBack(
|
||||
mBroadcastAssistantCallback);
|
||||
}
|
||||
if (mVolumeControl != null && mVolumeControlCallback != null) {
|
||||
mVolumeControl.unregisterCallback(mVolumeControlCallback);
|
||||
}
|
||||
});
|
||||
}
|
||||
mExecutor.execute(
|
||||
() -> {
|
||||
if (mLocalBtManager != null) {
|
||||
mLocalBtManager.getEventManager().unregisterCallback(mBluetoothCallback);
|
||||
}
|
||||
if (mLeBroadcastAssistant != null && mBroadcastAssistantCallback != null) {
|
||||
mLeBroadcastAssistant.unregisterServiceCallBack(
|
||||
mBroadcastAssistantCallback);
|
||||
}
|
||||
if (mVolumeControl != null && mVolumeControlCallback != null) {
|
||||
mVolumeControl.unregisterCallback(mVolumeControlCallback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user