Move enable/disable LE Audio to Utils

Bug: 381353150
Test: atest UtilsTest
Flag: EXEMPT minor refactor
Change-Id: Id017f2b5a0f51d19878bf91b219334baeda97d6d
This commit is contained in:
Haijie Hong
2025-03-18 11:25:33 +08:00
parent 16fa7c1e33
commit a333827d6d
4 changed files with 313 additions and 106 deletions

View File

@@ -18,24 +18,48 @@ package com.android.settings.testutils.shadow;
import android.content.Context;
import androidx.annotation.NonNull;
import com.android.settings.bluetooth.Utils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import java.util.HashMap;
import java.util.Map;
/** Robolectric shadow for the bluetooth utils. */
@Implements(Utils.class)
public class ShadowBluetoothUtils {
public static LocalBluetoothManager sLocalBluetoothManager;
private static final Map<CachedBluetoothDevice, Boolean> sLeAudioState = new HashMap<>();
@Implementation
protected static LocalBluetoothManager getLocalBtManager(Context context) {
return sLocalBluetoothManager;
}
/** Sets le audio state for the device. */
@Implementation
public static void setLeAudioEnabled(
@NonNull LocalBluetoothManager manager,
@NonNull CachedBluetoothDevice cachedDevice,
boolean enable) {
sLeAudioState.put(cachedDevice, enable);
}
/** Checks whether le audio is enabled for the device. */
public static boolean isLeAudioEnabled(@NonNull CachedBluetoothDevice cachedDevice) {
if (sLeAudioState.containsKey(cachedDevice)) {
return sLeAudioState.get(cachedDevice);
}
return false;
}
/** Resets the local bluetooth manager to null. */
@Resetter
public static void reset() {