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