Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c6b9bb3 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Increase audio sharing test coverage

Bug: 345686602
Test: atest
Change-Id: Iec196fc884c3b7ddd580eb8dd13b445d59e3b1b7
parent 44de7e98
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
    private static final String PREF_KEY = "calls_and_alarms";

    @VisibleForTesting
    protected enum ChangeCallAudioType {
    enum ChangeCallAudioType {
        UNKNOWN,
        CONNECTED_EARLIER,
        CONNECTED_LATER
@@ -90,7 +90,9 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
    Map<Integer, List<CachedBluetoothDevice>> mGroupedConnectedDevices = new HashMap<>();
    private List<AudioSharingDeviceItem> mDeviceItemsInSharingSession = new ArrayList<>();
    private final AtomicBoolean mCallbacksRegistered = new AtomicBoolean(false);
    private final BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =

    @VisibleForTesting
    final BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
            new BluetoothLeBroadcastAssistant.Callback() {
                @Override
                public void onSearchStarted(int reason) {}
@@ -276,7 +278,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP

    /** Test only: set callback registration status in tests. */
    @VisibleForTesting
    public void setCallbacksRegistered(boolean registered) {
    void setCallbacksRegistered(boolean registered) {
        mCallbacksRegistered.set(registered);
    }

@@ -385,7 +387,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
    }

    @VisibleForTesting
    protected void logCallAudioDeviceChange(int currentGroupId, CachedBluetoothDevice target) {
    void logCallAudioDeviceChange(int currentGroupId, CachedBluetoothDevice target) {
        var unused =
                ThreadUtils.postOnBackgroundThread(
                        () -> {
+6 −5
Original line number Diff line number Diff line
@@ -87,7 +87,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
    @Nullable private AudioSharingDialogHandler mDialogHandler;
    private AtomicBoolean mIntentHandled = new AtomicBoolean(false);

    private BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
    @VisibleForTesting
    BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
            new BluetoothLeBroadcastAssistant.Callback() {
                @Override
                public void onSearchStarted(int reason) {}
@@ -368,23 +369,23 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
    }

    @VisibleForTesting
    public void setBluetoothDeviceUpdater(@Nullable BluetoothDeviceUpdater bluetoothDeviceUpdater) {
    void setBluetoothDeviceUpdater(@Nullable BluetoothDeviceUpdater bluetoothDeviceUpdater) {
        mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
    }

    @VisibleForTesting
    public void setDialogHandler(@Nullable AudioSharingDialogHandler dialogHandler) {
    void setDialogHandler(@Nullable AudioSharingDialogHandler dialogHandler) {
        mDialogHandler = dialogHandler;
    }

    @VisibleForTesting
    public void setHostFragment(@Nullable DashboardFragment fragment) {
    void setHostFragment(@Nullable DashboardFragment fragment) {
        mFragment = fragment;
    }

    /** Test only: set intent handle state for test. */
    @VisibleForTesting
    public void setIntentHandled(boolean handled) {
    void setIntentHandled(boolean handled) {
        mIntentHandled.set(handled);
    }

+8 −10
Original line number Diff line number Diff line
@@ -79,12 +79,9 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
    private Map<Integer, Integer> mValueMap = new HashMap<Integer, Integer>();
    private AtomicBoolean mCallbacksRegistered = new AtomicBoolean(false);

    private BluetoothVolumeControl.Callback mVolumeControlCallback =
    @VisibleForTesting
    BluetoothVolumeControl.Callback mVolumeControlCallback =
            new BluetoothVolumeControl.Callback() {
                @Override
                public void onVolumeOffsetChanged(
                        @NonNull BluetoothDevice device, int volumeOffset) {}

                @Override
                public void onDeviceVolumeChanged(
                        @NonNull BluetoothDevice device,
@@ -117,7 +114,8 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
                }
            };

    private BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
    @VisibleForTesting
    BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
            new BluetoothLeBroadcastAssistant.Callback() {
                @Override
                public void onSearchStarted(int reason) {}
@@ -323,26 +321,26 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
    }

    @VisibleForTesting
    public void setDeviceUpdater(@Nullable AudioSharingDeviceVolumeControlUpdater updater) {
    void setDeviceUpdater(@Nullable AudioSharingDeviceVolumeControlUpdater updater) {
        mBluetoothDeviceUpdater = updater;
    }

    /** Test only: set callback registration status in tests. */
    @VisibleForTesting
    public void setCallbacksRegistered(boolean registered) {
    void setCallbacksRegistered(boolean registered) {
        mCallbacksRegistered.set(registered);
    }

    /** Test only: set volume map in tests. */
    @VisibleForTesting
    public void setVolumeMap(@Nullable Map<Integer, Integer> map) {
    void setVolumeMap(@Nullable Map<Integer, Integer> map) {
        mValueMap.clear();
        mValueMap.putAll(map);
    }

    /** Test only: set value for private preferenceGroup in tests. */
    @VisibleForTesting
    public void setPreferenceGroup(@Nullable PreferenceGroup group) {
    void setPreferenceGroup(@Nullable PreferenceGroup group) {
        mPreferenceGroup = group;
        mPreference = group;
    }
+2 −0
Original line number Diff line number Diff line
@@ -345,4 +345,6 @@ public class AudioSharingDialogFactory {
            return dialog;
        }
    }

    private AudioSharingDialogFactory() {}
}
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;

@@ -61,7 +62,8 @@ public class AudioSharingDialogHandler {
    private final MetricsFeatureProvider mMetricsFeatureProvider;
    private List<BluetoothDevice> mTargetSinks = new ArrayList<>();

    private final BluetoothLeBroadcast.Callback mBroadcastCallback =
    @VisibleForTesting
    final BluetoothLeBroadcast.Callback mBroadcastCallback =
            new BluetoothLeBroadcast.Callback() {
                @Override
                public void onBroadcastStarted(int reason, int broadcastId) {
Loading