Merge "[Audiosharing] Add audio sharing loggings (P4)" into main
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_BLUETOOTH_DEVICE;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastAssistant;
|
||||
@@ -44,6 +45,7 @@ import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||
@@ -56,6 +58,7 @@ import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -80,6 +83,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
@Nullable private final LocalBluetoothProfileManager mProfileManager;
|
||||
@Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant;
|
||||
private final Executor mExecutor;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@Nullable private PreferenceGroup mPreferenceGroup;
|
||||
@Nullable private Preference mAudioSharingSettingsPreference;
|
||||
@Nullable private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
@@ -114,6 +118,10 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
@NonNull BluetoothDevice sink,
|
||||
@NonNull BluetoothLeBroadcastMetadata source,
|
||||
int reason) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_JOIN_FAILED,
|
||||
SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext,
|
||||
String.format(
|
||||
@@ -143,6 +151,10 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
@Override
|
||||
public void onSourceRemoveFailed(
|
||||
@NonNull BluetoothDevice sink, int sourceId, int reason) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_LEAVE_FAILED,
|
||||
SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext,
|
||||
String.format(
|
||||
@@ -183,6 +195,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
||||
? null
|
||||
: mProfileManager.getLeAudioBroadcastAssistantProfile();
|
||||
mExecutor = Executors.newSingleThreadExecutor();
|
||||
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,7 +60,9 @@ public class AudioSharingDialogHandler {
|
||||
@Nullable private final LocalBluetoothLeBroadcast mBroadcast;
|
||||
@Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private List<BluetoothDevice> mTargetSinks = new ArrayList<>();
|
||||
// The target sinks to join broadcast onPlaybackStarted
|
||||
@Nullable private List<BluetoothDevice> mTargetSinks;
|
||||
private boolean mIsStoppingBroadcast = false;
|
||||
|
||||
@VisibleForTesting
|
||||
final BluetoothLeBroadcast.Callback mBroadcastCallback =
|
||||
@@ -78,8 +80,15 @@ public class AudioSharingDialogHandler {
|
||||
@Override
|
||||
public void onBroadcastStartFailed(int reason) {
|
||||
Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext, "Fail to start broadcast, reason " + reason);
|
||||
if (mTargetSinks != null) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_START_FAILED,
|
||||
SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext, "Fail to start broadcast, reason " + reason);
|
||||
mTargetSinks = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,13 +110,21 @@ public class AudioSharingDialogHandler {
|
||||
+ reason
|
||||
+ ", broadcastId = "
|
||||
+ broadcastId);
|
||||
mIsStoppingBroadcast = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStopFailed(int reason) {
|
||||
Log.d(TAG, "onBroadcastStopFailed(), reason = " + reason);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext, "Fail to stop broadcast, reason " + reason);
|
||||
if (mIsStoppingBroadcast) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_STOP_FAILED,
|
||||
SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext, "Fail to stop broadcast, reason " + reason);
|
||||
mIsStoppingBroadcast = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +141,7 @@ public class AudioSharingDialogHandler {
|
||||
+ reason
|
||||
+ ", broadcastId = "
|
||||
+ broadcastId);
|
||||
if (!mTargetSinks.isEmpty()) {
|
||||
if (mTargetSinks != null) {
|
||||
AudioSharingUtils.addSourceToTargetSinks(mTargetSinks, mLocalBtManager);
|
||||
new SubSettingLauncher(mContext)
|
||||
.setDestination(AudioSharingDashboardFragment.class.getName())
|
||||
@@ -134,7 +151,7 @@ public class AudioSharingDialogHandler {
|
||||
.getMetricsCategory()
|
||||
: SettingsEnums.PAGE_UNKNOWN)
|
||||
.launch();
|
||||
mTargetSinks = new ArrayList<>();
|
||||
mTargetSinks = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +220,7 @@ public class AudioSharingDialogHandler {
|
||||
AudioSharingStopDialogFragment.DialogEventListener listener =
|
||||
() -> {
|
||||
cachedDevice.setActive();
|
||||
mIsStoppingBroadcast = true;
|
||||
AudioSharingUtils.stopBroadcasting(mLocalBtManager);
|
||||
};
|
||||
Pair<Integer, Object>[] eventData =
|
||||
|
||||
@@ -140,6 +140,13 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
return sCachedDevice;
|
||||
}
|
||||
|
||||
/** Test only: get the {@link DialogEventListener} passed to the dialog. */
|
||||
@VisibleForTesting
|
||||
@Nullable
|
||||
DialogEventListener getListener() {
|
||||
return sListener;
|
||||
}
|
||||
|
||||
/** Test only: get the event data passed to the dialog. */
|
||||
@VisibleForTesting
|
||||
@NonNull
|
||||
|
||||
@@ -134,8 +134,11 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
@Override
|
||||
public void onBroadcastStartFailed(int reason) {
|
||||
Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
|
||||
// TODO: handle broadcast start fail
|
||||
updateSwitch();
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_START_FAILED,
|
||||
SettingsEnums.AUDIO_SHARING_SETTINGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,8 +167,11 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
@Override
|
||||
public void onBroadcastStopFailed(int reason) {
|
||||
Log.d(TAG, "onBroadcastStopFailed(), reason = " + reason);
|
||||
// TODO: handle broadcast stop fail
|
||||
updateSwitch();
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_STOP_FAILED,
|
||||
SettingsEnums.AUDIO_SHARING_SETTINGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,7 +195,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
public void onPlaybackStopped(int reason, int broadcastId) {}
|
||||
};
|
||||
|
||||
private final BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
|
||||
@VisibleForTesting
|
||||
final BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
|
||||
new BluetoothLeBroadcastAssistant.Callback() {
|
||||
@Override
|
||||
public void onSearchStarted(int reason) {}
|
||||
@@ -207,16 +214,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
public void onSourceFound(@NonNull BluetoothLeBroadcastMetadata source) {}
|
||||
|
||||
@Override
|
||||
public void onSourceAdded(@NonNull BluetoothDevice sink, int sourceId, int reason) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"onSourceAdded(), sink = "
|
||||
+ sink
|
||||
+ ", sourceId = "
|
||||
+ sourceId
|
||||
+ ", reason = "
|
||||
+ reason);
|
||||
}
|
||||
public void onSourceAdded(
|
||||
@NonNull BluetoothDevice sink, int sourceId, int reason) {}
|
||||
|
||||
@Override
|
||||
public void onSourceAddFailed(
|
||||
@@ -231,6 +230,10 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
+ source
|
||||
+ ", reason = "
|
||||
+ reason);
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_JOIN_FAILED,
|
||||
SettingsEnums.AUDIO_SHARING_SETTINGS);
|
||||
AudioSharingUtils.toastMessage(
|
||||
mContext,
|
||||
String.format(
|
||||
@@ -318,15 +321,17 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
// Filter out unnecessary callbacks when switch is disabled.
|
||||
if (!buttonView.isEnabled()) return;
|
||||
if (mBroadcast == null || mAssistant == null) {
|
||||
mSwitchBar.setChecked(false);
|
||||
Log.d(TAG, "Skip onCheckedChanged, profile not support.");
|
||||
return;
|
||||
}
|
||||
mSwitchBar.setEnabled(false);
|
||||
boolean isBroadcasting = AudioSharingUtils.isBroadcasting(mBtManager);
|
||||
if (isChecked) {
|
||||
mSwitchBar.setEnabled(false);
|
||||
boolean isBroadcasting = AudioSharingUtils.isBroadcasting(mBtManager);
|
||||
if (mAssistant == null || mBroadcast == null || isBroadcasting) {
|
||||
Log.d(TAG, "Skip startAudioSharing, already broadcasting or not support.");
|
||||
if (isBroadcasting) {
|
||||
Log.d(TAG, "Skip startAudioSharing, already broadcasting.");
|
||||
mSwitchBar.setEnabled(true);
|
||||
if (!isBroadcasting) {
|
||||
mSwitchBar.setChecked(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST is always true in
|
||||
@@ -352,6 +357,11 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
}
|
||||
startAudioSharing();
|
||||
} else {
|
||||
if (!isBroadcasting) {
|
||||
Log.d(TAG, "Skip stopAudioSharing, already not broadcasting.");
|
||||
mSwitchBar.setEnabled(true);
|
||||
return;
|
||||
}
|
||||
stopAudioSharing();
|
||||
}
|
||||
}
|
||||
@@ -454,18 +464,18 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
}
|
||||
if (mBroadcast != null) {
|
||||
mBroadcast.startPrivateBroadcast();
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_MAIN_SWITCH_ON,
|
||||
deviceItems.size());
|
||||
}
|
||||
}
|
||||
|
||||
private void stopAudioSharing() {
|
||||
mSwitchBar.setEnabled(false);
|
||||
if (!AudioSharingUtils.isBroadcasting(mBtManager)) {
|
||||
Log.d(TAG, "Skip stopAudioSharing, already not broadcasting or broadcast not support.");
|
||||
mSwitchBar.setEnabled(true);
|
||||
return;
|
||||
}
|
||||
if (mBroadcast != null) {
|
||||
mBroadcast.stopBroadcast(mBroadcast.getLatestBroadcastId());
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, SettingsEnums.ACTION_AUDIO_SHARING_MAIN_SWITCH_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user