[Audiosharing] Add audio sharing loggings (P1)
Bug: 331515891 Test: atest Change-Id: I7396f99538f36b47086e0c4f45ef775535f2f321
This commit is contained in:
@@ -17,6 +17,7 @@ package com.android.settings.connecteddevice;
|
||||
|
||||
import static com.android.settingslib.Utils.isAudioModeOngoingCall;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
import android.bluetooth.BluetoothLeBroadcastAssistant;
|
||||
@@ -47,6 +48,7 @@ import com.android.settings.connecteddevice.audiosharing.AudioSharingDialogHandl
|
||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -279,6 +281,8 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
||||
((BluetoothDevicePreference) preference).getBluetoothDevice();
|
||||
if (AudioSharingUtils.isFeatureEnabled() && mDialogHandler != null) {
|
||||
mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ true);
|
||||
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
|
||||
.action(mContext, SettingsEnums.ACTION_MEDIA_DEVICE_CLICK);
|
||||
} else {
|
||||
cachedDevice.setActive();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -70,6 +71,7 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
mMetricsFeatureProvider.logClickedPreference(preference, mMetricsCategory);
|
||||
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_AUDIO_SHARING_DEVICE_CLICK);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_ACTIVE;
|
||||
return SettingsEnums.DIALOG_AUDIO_SHARING_CALL_AUDIO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.content.Context;
|
||||
@@ -32,9 +33,11 @@ import androidx.preference.TwoStatePreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -53,6 +56,7 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere
|
||||
@Nullable private final LocalBluetoothLeBroadcast mBroadcast;
|
||||
@Nullable private TwoStatePreference mPreference;
|
||||
private final Executor mExecutor;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private AtomicBoolean mCallbacksRegistered = new AtomicBoolean(false);
|
||||
|
||||
private final BluetoothLeBroadcast.Callback mBroadcastCallback =
|
||||
@@ -108,6 +112,7 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere
|
||||
mProfileManager = mBtManager == null ? null : mBtManager.getProfileManager();
|
||||
mBroadcast = mProfileManager == null ? null : mProfileManager.getLeAudioBroadcastProfile();
|
||||
mExecutor = Executors.newSingleThreadExecutor();
|
||||
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,6 +183,8 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere
|
||||
}
|
||||
mBroadcast.setImproveCompatibility(isChecked);
|
||||
// TODO: call updateBroadcast once framework change ready.
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, SettingsEnums.ACTION_AUDIO_SHARING_IMPROVE_COMPATIBILITY, isChecked);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -33,8 +34,7 @@ public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragmen
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
// TODO: add metrics category.
|
||||
return 0;
|
||||
return SettingsEnums.DIALOG_AUDIO_SHARING_CONFIRMATION;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragmen
|
||||
.setTitleIcon(com.android.settingslib.R.drawable.ic_bt_le_audio_sharing)
|
||||
.setIsCustomBodyEnabled(true)
|
||||
.setCustomMessage(R.string.audio_sharing_comfirm_dialog_content)
|
||||
.setPositiveButton(com.android.settings.R.string.okay, (d, w) -> dismiss())
|
||||
.setPositiveButton(com.android.settings.R.string.okay, (d, w) -> {})
|
||||
.build();
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
return dialog;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothCsipSetCoordinator;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
@@ -156,6 +157,10 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat
|
||||
if (mVolumeControl != null) {
|
||||
mVolumeControl.setDeviceVolume(
|
||||
cachedDevice.getDevice(), progress, /* isGroupOp= */ true);
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME,
|
||||
/* isPrimary= */ false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +175,10 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat
|
||||
- audioManager.getStreamMinVolume(AudioManager.STREAM_MUSIC);
|
||||
int volume = Math.round((float) progress * streamVolumeRange / seekbarRange);
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME,
|
||||
/* isPrimary= */ true);
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "Fail to setAudioManagerStreamVolumeForFallbackDevice, error = " + e);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return AudioSharingUtils.isBroadcasting(Utils.getLocalBtManager(getContext()))
|
||||
? SettingsEnums.DIALOG_START_AUDIO_SHARING
|
||||
? SettingsEnums.DIALOG_AUDIO_SHARING_ADD_DEVICE
|
||||
: SettingsEnums.DIALOG_START_AUDIO_SHARING;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
@@ -31,6 +32,8 @@ import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
public class AudioSharingPlaySoundPreferenceController
|
||||
extends AudioSharingBasePreferenceController {
|
||||
@@ -39,6 +42,7 @@ public class AudioSharingPlaySoundPreferenceController
|
||||
|
||||
private static final String PREF_KEY = "audio_sharing_play_sound";
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private Ringtone mRingtone;
|
||||
|
||||
public AudioSharingPlaySoundPreferenceController(Context context) {
|
||||
@@ -47,6 +51,7 @@ public class AudioSharingPlaySoundPreferenceController
|
||||
if (mRingtone != null) {
|
||||
mRingtone.setStreamType(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,6 +79,9 @@ public class AudioSharingPlaySoundPreferenceController
|
||||
.build());
|
||||
if (!mRingtone.isPlaying()) {
|
||||
mRingtone.play();
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_PLAY_TEST_SOUND);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.w(TAG, "Fail to play sample, error = " + e);
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -30,8 +31,10 @@ import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "AudioSharingNotification";
|
||||
@@ -54,6 +57,8 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
Log.w(TAG, "Received unexpected intent with null action.");
|
||||
return;
|
||||
}
|
||||
MetricsFeatureProvider metricsFeatureProvider =
|
||||
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
switch (action) {
|
||||
case LocalBluetoothLeBroadcast.ACTION_LE_AUDIO_SHARING_STATE_CHANGE:
|
||||
int state =
|
||||
@@ -61,8 +66,12 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
LocalBluetoothLeBroadcast.EXTRA_LE_AUDIO_SHARING_STATE, -1);
|
||||
if (state == LocalBluetoothLeBroadcast.BROADCAST_STATE_ON) {
|
||||
showSharingNotification(context);
|
||||
metricsFeatureProvider.action(
|
||||
context, SettingsEnums.ACTION_SHOW_AUDIO_SHARING_NOTIFICATION);
|
||||
} else if (state == LocalBluetoothLeBroadcast.BROADCAST_STATE_OFF) {
|
||||
cancelSharingNotification(context);
|
||||
metricsFeatureProvider.action(
|
||||
context, SettingsEnums.ACTION_CANCEL_AUDIO_SHARING_NOTIFICATION);
|
||||
} else {
|
||||
Log.w(
|
||||
TAG,
|
||||
@@ -72,6 +81,8 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
case ACTION_LE_AUDIO_SHARING_STOP:
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
AudioSharingUtils.stopBroadcasting(manager);
|
||||
metricsFeatureProvider.action(
|
||||
context, SettingsEnums.ACTION_STOP_AUDIO_SHARING_FROM_NOTIFICATION);
|
||||
break;
|
||||
default:
|
||||
Log.w(TAG, "Received unexpected intent " + intent.getAction());
|
||||
@@ -98,7 +109,11 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
stopIntent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
Intent settingsIntent =
|
||||
new Intent(ACTION_LE_AUDIO_SHARING_SETTINGS).setPackage(context.getPackageName());
|
||||
new Intent(ACTION_LE_AUDIO_SHARING_SETTINGS)
|
||||
.setPackage(context.getPackageName())
|
||||
.putExtra(
|
||||
MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
|
||||
SettingsEnums.NOTIFICATION_AUDIO_SHARING);
|
||||
PendingIntent settingsPendingIntent =
|
||||
PendingIntent.getActivity(
|
||||
context,
|
||||
|
||||
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
@@ -58,6 +59,7 @@ import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater;
|
||||
import com.android.settings.bluetooth.BluetoothDevicePreference;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingDialogHandler;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
@@ -128,6 +130,7 @@ public class AvailableMediaDeviceGroupControllerTest {
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private Context mContext;
|
||||
private FragmentManager mFragManager;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Preference mPreference;
|
||||
private AvailableMediaDeviceGroupController mAvailableMediaDeviceGroupController;
|
||||
private AudioManager mAudioManager;
|
||||
@@ -157,6 +160,7 @@ public class AvailableMediaDeviceGroupControllerTest {
|
||||
BluetoothStatusCodes.FEATURE_NOT_SUPPORTED);
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mAudioManager = mContext.getSystemService(AudioManager.class);
|
||||
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
|
||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBtProfileManager);
|
||||
@@ -414,6 +418,8 @@ public class AvailableMediaDeviceGroupControllerTest {
|
||||
mAvailableMediaDeviceGroupController.onDeviceClick(preference);
|
||||
verify(mDialogHandler)
|
||||
.handleDeviceConnected(mCachedBluetoothDevice, /* userTriggered= */ true);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_MEDIA_DEVICE_CLICK);
|
||||
}
|
||||
|
||||
private void setUpBroadcast() {
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
@@ -43,6 +44,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import com.android.settings.bluetooth.BluetoothDevicePreference;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
@@ -102,6 +104,7 @@ public class AudioSharingBluetoothDeviceUpdaterTest {
|
||||
private AudioSharingBluetoothDeviceUpdater mDeviceUpdater;
|
||||
private Collection<CachedBluetoothDevice> mCachedDevices;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -113,6 +116,7 @@ public class AudioSharingBluetoothDeviceUpdaterTest {
|
||||
mShadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mLocalBtManager = Utils.getLocalBtManager(mContext);
|
||||
when(mLocalBtManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager);
|
||||
@@ -255,6 +259,14 @@ public class AudioSharingBluetoothDeviceUpdaterTest {
|
||||
assertThat(mDeviceUpdater.getPreferenceKey()).isEqualTo(PREF_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceClick_logClick() {
|
||||
Preference preference = new Preference(mContext);
|
||||
mDeviceUpdater.onPreferenceClick(preference);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_AUDIO_SHARING_DEVICE_CLICK);
|
||||
}
|
||||
|
||||
private void setupPreferenceMapWithDevice() {
|
||||
// Add device to preferenceMap
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
@@ -82,6 +83,12 @@ public class AudioSharingCallAudioDialogFragmentTest {
|
||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_correctValue() {
|
||||
assertThat(mFragment.getMetricsCategory())
|
||||
.isEqualTo(SettingsEnums.DIALOG_AUDIO_SHARING_CALL_AUDIO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
@@ -27,9 +27,11 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
@@ -44,6 +46,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
@@ -94,6 +97,7 @@ public class AudioSharingCompatibilityPreferenceControllerTest {
|
||||
private AudioSharingCompatibilityPreferenceController mController;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Lifecycle mLifecycle;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
|
||||
@@ -109,6 +113,7 @@ public class AudioSharingCompatibilityPreferenceControllerTest {
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBtEventManager);
|
||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mBtProfileManager);
|
||||
when(mBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
|
||||
@@ -258,6 +263,8 @@ public class AudioSharingCompatibilityPreferenceControllerTest {
|
||||
doNothing().when(mBroadcast).setImproveCompatibility(anyBoolean());
|
||||
boolean setChecked = mController.setChecked(false);
|
||||
verify(mBroadcast).setImproveCompatibility(false);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_AUDIO_SHARING_IMPROVE_COMPATIBILITY, false);
|
||||
assertThat(setChecked).isTrue();
|
||||
}
|
||||
|
||||
@@ -266,6 +273,7 @@ public class AudioSharingCompatibilityPreferenceControllerTest {
|
||||
when(mBroadcast.getImproveCompatibility()).thenReturn(true);
|
||||
boolean setChecked = mController.setChecked(true);
|
||||
verify(mBroadcast, times(0)).setImproveCompatibility(anyBoolean());
|
||||
verifyNoInteractions(mFeatureFactory.metricsFeatureProvider);
|
||||
assertThat(setChecked).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
@@ -42,6 +43,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
@@ -96,12 +98,14 @@ public class AudioSharingDeviceVolumeControlUpdaterTest {
|
||||
private Context mContext;
|
||||
private AudioSharingDeviceVolumeControlUpdater mDeviceUpdater;
|
||||
private Collection<CachedBluetoothDevice> mCachedDevices;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
|
||||
mLocalBtManager = Utils.getLocalBtManager(mContext);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(mLocalBtManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager);
|
||||
when(mLocalBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
|
||||
@@ -250,6 +254,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest {
|
||||
|
||||
verify(mVolumeControl).setDeviceVolume(mBluetoothDevice, 255, true);
|
||||
verifyNoInteractions(mAudioManager);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME,
|
||||
/* isPrimary= */ false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,6 +281,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest {
|
||||
|
||||
verifyNoInteractions(mVolumeControl);
|
||||
verify(mAudioManager).setStreamVolume(AudioManager.STREAM_MUSIC, 10, 0);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME,
|
||||
/* isPrimary= */ true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
@@ -30,9 +31,14 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -55,6 +61,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
shadows = {
|
||||
ShadowAlertDialogCompat.class,
|
||||
ShadowBluetoothAdapter.class,
|
||||
ShadowBluetoothUtils.class,
|
||||
})
|
||||
public class AudioSharingJoinDialogFragmentTest {
|
||||
|
||||
@@ -78,6 +85,9 @@ public class AudioSharingJoinDialogFragmentTest {
|
||||
|
||||
@Mock private CachedBluetoothDevice mCachedDevice1;
|
||||
@Mock private CachedBluetoothDevice mCachedDevice2;
|
||||
@Mock private LocalBluetoothManager mLocalBtManager;
|
||||
@Mock private LocalBluetoothProfileManager mBtProfileManager;
|
||||
@Mock private LocalBluetoothLeBroadcast mBroadcast;
|
||||
private Fragment mParent;
|
||||
private AudioSharingJoinDialogFragment mFragment;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
@@ -98,11 +108,32 @@ public class AudioSharingJoinDialogFragmentTest {
|
||||
when(mCachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME1);
|
||||
when(mCachedDevice2.getName()).thenReturn(TEST_DEVICE_NAME2);
|
||||
mFragment = new AudioSharingJoinDialogFragment();
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
|
||||
mLocalBtManager = Utils.getLocalBtManager(mFragment.getContext());
|
||||
when(mLocalBtManager.getProfileManager()).thenReturn(mBtProfileManager);
|
||||
when(mBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
|
||||
mParent = new Fragment();
|
||||
FragmentController.setupFragment(
|
||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_notInSharing_correctValue() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(false);
|
||||
int category = mFragment.getMetricsCategory();
|
||||
shadowMainLooper().idle();
|
||||
assertThat(category).isEqualTo(SettingsEnums.DIALOG_START_AUDIO_SHARING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_inSharing_correctValue() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
int category = mFragment.getMetricsCategory();
|
||||
shadowMainLooper().idle();
|
||||
assertThat(category).isEqualTo(SettingsEnums.DIALOG_AUDIO_SHARING_ADD_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.content.Context;
|
||||
@@ -39,6 +40,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
@@ -71,6 +73,7 @@ public class AudioSharingPlaySoundPreferenceControllerTest {
|
||||
private Lifecycle mLifecycle;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Preference mPreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -80,6 +83,7 @@ public class AudioSharingPlaySoundPreferenceControllerTest {
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
mShadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
when(mRingtone.getStreamType()).thenReturn(AudioManager.STREAM_MUSIC);
|
||||
@@ -165,6 +169,8 @@ public class AudioSharingPlaySoundPreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
mPreference.performClick();
|
||||
verify(mRingtone).play();
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_AUDIO_SHARING_PLAY_TEST_SOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -40,6 +41,7 @@ import android.content.Intent;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.R;
|
||||
@@ -77,6 +79,7 @@ public class AudioSharingReceiverTest {
|
||||
private ShadowApplication mShadowApplication;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
@Mock private LocalBluetoothProfileManager mLocalBtProfileManager;
|
||||
@Mock private LocalBluetoothLeBroadcast mBroadcast;
|
||||
@Mock private LocalBluetoothManager mLocalBtManager;
|
||||
@@ -97,6 +100,7 @@ public class AudioSharingReceiverTest {
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBtProfileManager);
|
||||
when(mLocalBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,6 +160,8 @@ public class AudioSharingReceiverTest {
|
||||
|
||||
verify(mNm, times(1))
|
||||
.notify(eq(R.drawable.ic_bt_le_audio_sharing), any(Notification.class));
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_SHOW_AUDIO_SHARING_NOTIFICATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,6 +176,8 @@ public class AudioSharingReceiverTest {
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, times(1)).cancel(R.drawable.ic_bt_le_audio_sharing);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_CANCEL_AUDIO_SHARING_NOTIFICATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,6 +204,8 @@ public class AudioSharingReceiverTest {
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mBroadcast, times(1)).stopBroadcast(broadcastId);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.ACTION_STOP_AUDIO_SHARING_FROM_NOTIFICATION);
|
||||
}
|
||||
|
||||
private AudioSharingReceiver getAudioSharingReceiver(Intent intent) {
|
||||
|
||||
Reference in New Issue
Block a user