[Audiosharing] Add audio sharing loggings (P1)

Bug: 331515891
Test: atest
Change-Id: I7396f99538f36b47086e0c4f45ef775535f2f321
This commit is contained in:
Yiyi Shen
2024-05-29 14:15:30 +08:00
parent bce1511a75
commit d1ea3b4d96
17 changed files with 145 additions and 6 deletions

View File

@@ -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() {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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) {