Merge "[Settings] Change the way in MobileNetworkSummaryController for getting the subscription info from room db"
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 3078717..599a145 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -93,10 +93,14 @@
<attr name="currentPageIndicatorColor" format="color" />
</declare-styleable>
- <!-- For ConversationMessageView -->
- <declare-styleable name="ConversationMessageView">
- <attr name="incoming" format="boolean" />
+ <declare-styleable name="MessageView">
<attr name="messageText" format="reference" />
+ </declare-styleable>
+
+ <!-- For ConversationMessageView -->
+ <declare-styleable name="ConversationMessageView" parent="MessageView">
+ <attr name="incoming" format="boolean" />
+ <attr name="messageText" />
<attr name="timestampText" format="reference" />
<attr name="iconText" format="reference" />
<attr name="iconTextColor" format="reference|color" />
@@ -146,16 +150,9 @@
<attr name="android:gravity" />
</declare-styleable>
- <!-- For biometric enroll checkboxes -->
- <declare-styleable name="BiometricEnrollCheckbox">
- <attr name="icon" format="reference" />
- <attr name="title" format="reference" />
- <attr name="description" format="reference" />
- </declare-styleable>
-
<!-- For Face enroll accessibility toggle -->
- <declare-styleable name="FaceEnrollAccessibilityToggle">
- <attr name="messageText" format="reference" />
+ <declare-styleable name="FaceEnrollAccessibilityToggle" parent="MessageView">
+ <attr name="messageText" />
</declare-styleable>
<!-- For TwoStatesButtonPreference -->
diff --git a/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java b/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java
index 2c76f05..cbaf75f 100644
--- a/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java
@@ -27,10 +27,10 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.intentpicker.AppLaunchSettings;
import com.android.settings.applications.intentpicker.IntentPickerUtils;
-import com.android.settingslib.R;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
diff --git a/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java b/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java
index 690c07e..92786c9 100644
--- a/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java
+++ b/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java
@@ -26,7 +26,7 @@
import androidx.fragment.app.FragmentTransaction;
-import com.android.settingslib.R;
+import com.android.settings.R;
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
import com.android.settingslib.bluetooth.BluetoothUtils;
diff --git a/src/com/android/settings/bluetooth/QrCodeScanModeBaseActivity.java b/src/com/android/settings/bluetooth/QrCodeScanModeBaseActivity.java
index 06f3619..4af75ad 100644
--- a/src/com/android/settings/bluetooth/QrCodeScanModeBaseActivity.java
+++ b/src/com/android/settings/bluetooth/QrCodeScanModeBaseActivity.java
@@ -22,7 +22,7 @@
import androidx.fragment.app.FragmentManager;
-import com.android.settingslib.R;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.ObservableActivity;
import com.google.android.setupdesign.util.ThemeHelper;
diff --git a/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java b/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java
index 0253aa6..b6f338a 100644
--- a/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java
+++ b/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java
@@ -39,8 +39,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
+import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
-import com.android.settingslib.R;
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.qrcode.QrCamera;
diff --git a/src/com/android/settings/dashboard/profileselector/UserAdapter.java b/src/com/android/settings/dashboard/profileselector/UserAdapter.java
index e88b9cb..cf7fafb 100644
--- a/src/com/android/settings/dashboard/profileselector/UserAdapter.java
+++ b/src/com/android/settings/dashboard/profileselector/UserAdapter.java
@@ -36,7 +36,7 @@
import com.android.internal.util.UserIcons;
import com.android.internal.widget.RecyclerView;
-import com.android.settingslib.R;
+import com.android.settings.R;
import com.android.settingslib.Utils;
import java.util.ArrayList;
diff --git a/src/com/android/settings/homepage/TopLevelHighlightMixin.java b/src/com/android/settings/homepage/TopLevelHighlightMixin.java
index 9d727a5..f361ed6 100644
--- a/src/com/android/settings/homepage/TopLevelHighlightMixin.java
+++ b/src/com/android/settings/homepage/TopLevelHighlightMixin.java
@@ -69,17 +69,18 @@
return 0;
}
- public static final Creator<TopLevelHighlightMixin> CREATOR = new Creator<>() {
- @Override
- public TopLevelHighlightMixin createFromParcel(Parcel source) {
- return new TopLevelHighlightMixin(source);
- }
+ public static final Creator<TopLevelHighlightMixin> CREATOR =
+ new Creator<TopLevelHighlightMixin>() {
+ @Override
+ public TopLevelHighlightMixin createFromParcel(Parcel source) {
+ return new TopLevelHighlightMixin(source);
+ }
- @Override
- public TopLevelHighlightMixin[] newArray(int size) {
- return new TopLevelHighlightMixin[size];
- }
- };
+ @Override
+ public TopLevelHighlightMixin[] newArray(int size) {
+ return new TopLevelHighlightMixin[size];
+ }
+ };
@Override
public void onShow(DialogInterface dialog) {
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 150dbe0..efc53b9 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -20,22 +20,15 @@
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_CACHED;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER;
-import static android.os.UserHandle.USER_SYSTEM;
-import android.Manifest;
import android.app.INotificationManager;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationHistory;
import android.app.NotificationManager;
-import android.app.compat.CompatChanges;
-import android.app.role.RoleManager;
import android.app.usage.IUsageStatsManager;
import android.app.usage.UsageEvents;
import android.companion.ICompanionDeviceManager;
-import android.compat.annotation.ChangeId;
-import android.compat.annotation.EnabledAfter;
-import android.compat.annotation.EnabledSince;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -51,7 +44,6 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
-import android.provider.Settings;
import android.service.notification.ConversationChannelWrapper;
import android.service.notification.NotificationListenerFilter;
import android.text.format.DateUtils;
@@ -61,8 +53,7 @@
import androidx.annotation.VisibleForTesting;
import com.android.internal.util.CollectionUtils;
-import com.android.settingslib.R;
-import com.android.settingslib.Utils;
+import com.android.settings.R;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.notification.ConversationIconFactory;
diff --git a/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java
index f7dc391..5614e5d 100644
--- a/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java
+++ b/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java
@@ -23,6 +23,9 @@
import android.os.UserHandle;
import android.provider.Settings;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.R;
import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin;
@@ -34,9 +37,6 @@
import java.util.ArrayList;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
public class ShowOnLockScreenNotificationPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
diff --git a/src/com/android/settings/notification/app/BubblePreference.java b/src/com/android/settings/notification/app/BubblePreference.java
index f0046d7..9de7e0c 100644
--- a/src/com/android/settings/notification/app/BubblePreference.java
+++ b/src/com/android/settings/notification/app/BubblePreference.java
@@ -22,7 +22,6 @@
import android.content.Context;
import android.content.res.ColorStateList;
-import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
@@ -31,8 +30,8 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
+import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settingslib.R;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreferenceHelper;
diff --git a/src/com/android/settings/notification/app/ConversationPriorityPreference.java b/src/com/android/settings/notification/app/ConversationPriorityPreference.java
index 67bffbf..3e503a3 100644
--- a/src/com/android/settings/notification/app/ConversationPriorityPreference.java
+++ b/src/com/android/settings/notification/app/ConversationPriorityPreference.java
@@ -24,7 +24,6 @@
import android.content.Context;
import android.content.res.ColorStateList;
-import android.graphics.drawable.Drawable;
import android.transition.AutoTransition;
import android.transition.TransitionManager;
import android.util.AttributeSet;
@@ -37,8 +36,8 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
+import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settingslib.R;
public class ConversationPriorityPreference extends Preference {
diff --git a/src/com/android/settings/notification/app/ImportancePreference.java b/src/com/android/settings/notification/app/ImportancePreference.java
index d3cd013..857c94e 100644
--- a/src/com/android/settings/notification/app/ImportancePreference.java
+++ b/src/com/android/settings/notification/app/ImportancePreference.java
@@ -27,21 +27,19 @@
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.transition.AutoTransition;
-import android.transition.Transition;
import android.transition.TransitionManager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
-import com.android.settings.Utils;
-import com.android.settingslib.R;
-
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
+import com.android.settings.R;
+import com.android.settings.Utils;
+
public class ImportancePreference extends Preference {
private boolean mIsConfigurable = true;
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index 5b70d16..38fecfc 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -45,6 +45,7 @@
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -215,6 +216,25 @@
}
/**
+ * Get LE Audio profile connected devices
+ */
+ protected List<BluetoothDevice> getConnectedLeAudioDevices() {
+ final List<BluetoothDevice> connectedDevices = new ArrayList<>();
+ final LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
+ if (leAudioProfile == null) {
+ Log.d(TAG, "LeAudioProfile is null");
+ return connectedDevices;
+ }
+ final List<BluetoothDevice> devices = leAudioProfile.getConnectedDevices();
+ for (BluetoothDevice device : devices) {
+ if (device.isConnected()) {
+ connectedDevices.add(device);
+ }
+ }
+ return connectedDevices;
+ }
+
+ /**
* get hearing aid profile connected device, exclude other devices with same hiSyncId.
*/
protected List<BluetoothDevice> getConnectedHearingAidDevices() {
@@ -260,6 +280,24 @@
}
/**
+ * Find active LE Audio device
+ */
+ protected BluetoothDevice findActiveLeAudioDevice() {
+ final LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
+
+ if (leAudioProfile != null) {
+ List<BluetoothDevice> activeDevices = leAudioProfile.getActiveDevices();
+ for (BluetoothDevice leAudioDevice : activeDevices) {
+ if (leAudioDevice != null) {
+ return leAudioDevice;
+ }
+ }
+ }
+ Log.d(TAG, "There is no LE audio profile or no active LE audio device");
+ return null;
+ }
+
+ /**
* Find the active device from the corresponding profile.
*
* @return the active device. Return null if the
diff --git a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
index 15f47cf..35cc65f 100644
--- a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
+++ b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
@@ -103,6 +103,7 @@
mConnectedDevices.clear();
mConnectedDevices.addAll(getConnectedHfpDevices());
mConnectedDevices.addAll(getConnectedHearingAidDevices());
+ mConnectedDevices.addAll(getConnectedLeAudioDevices());
final int numDevices = mConnectedDevices.size();
if (numDevices == 0) {
@@ -181,12 +182,22 @@
@Override
public BluetoothDevice findActiveDevice() {
- BluetoothDevice activeDevice = findActiveHearingAidDevice();
+ BluetoothDevice haActiveDevice = findActiveHearingAidDevice();
+ BluetoothDevice leAudioActiveDevice = findActiveLeAudioDevice();
final HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile();
- if (activeDevice == null && headsetProfile != null) {
- activeDevice = headsetProfile.getActiveDevice();
+ if (haActiveDevice != null) {
+ return haActiveDevice;
}
- return activeDevice;
+
+ if (leAudioActiveDevice != null) {
+ return leAudioActiveDevice;
+ }
+
+ if (headsetProfile != null && headsetProfile.getActiveDevice() != null) {
+ return headsetProfile.getActiveDevice();
+ }
+
+ return null;
}
}
diff --git a/src/com/android/settings/sound/MediaOutputPreferenceController.java b/src/com/android/settings/sound/MediaOutputPreferenceController.java
index 4ec00e3..758f7e3 100644
--- a/src/com/android/settings/sound/MediaOutputPreferenceController.java
+++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java
@@ -88,9 +88,11 @@
// Find active device and set its name as the preference's summary
List<BluetoothDevice> connectedA2dpDevices = getConnectedA2dpDevices();
List<BluetoothDevice> connectedHADevices = getConnectedHearingAidDevices();
+ List<BluetoothDevice> connectedLeAudioDevices = getConnectedLeAudioDevices();
if (mAudioManager.getMode() == AudioManager.MODE_NORMAL
&& ((connectedA2dpDevices != null && !connectedA2dpDevices.isEmpty())
- || (connectedHADevices != null && !connectedHADevices.isEmpty()))) {
+ || (connectedHADevices != null && !connectedHADevices.isEmpty())
+ || (connectedLeAudioDevices != null && !connectedLeAudioDevices.isEmpty()))) {
activeDevice = findActiveDevice();
}
mPreference.setTitle(mContext.getString(R.string.media_output_label_title,
@@ -103,13 +105,23 @@
@Override
public BluetoothDevice findActiveDevice() {
- BluetoothDevice activeDevice = findActiveHearingAidDevice();
+ BluetoothDevice haActiveDevice = findActiveHearingAidDevice();
+ BluetoothDevice leAudioActiveDevice = findActiveLeAudioDevice();
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
- if (activeDevice == null && a2dpProfile != null) {
- activeDevice = a2dpProfile.getActiveDevice();
+ if (haActiveDevice != null) {
+ return haActiveDevice;
}
- return activeDevice;
+
+ if (leAudioActiveDevice != null) {
+ return leAudioActiveDevice;
+ }
+
+ if (a2dpProfile != null && a2dpProfile.getActiveDevice() != null) {
+ return a2dpProfile.getActiveDevice();
+ }
+
+ return null;
}
/**
diff --git a/src/com/android/settings/widget/UsageGraph.java b/src/com/android/settings/widget/UsageGraph.java
index 505dc58..11ebd21 100644
--- a/src/com/android/settings/widget/UsageGraph.java
+++ b/src/com/android/settings/widget/UsageGraph.java
@@ -37,8 +37,8 @@
import androidx.annotation.VisibleForTesting;
+import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
-import com.android.settingslib.R;
public class UsageGraph extends View {
diff --git a/src/com/android/settings/widget/UsageView.java b/src/com/android/settings/widget/UsageView.java
index 25bbbe3..6a721db 100644
--- a/src/com/android/settings/widget/UsageView.java
+++ b/src/com/android/settings/widget/UsageView.java
@@ -28,7 +28,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;
-import com.android.settingslib.R;
+import com.android.settings.R;
import java.util.Locale;
diff --git a/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java b/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
index 1c069246..54a4d04 100644
--- a/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
+++ b/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
@@ -21,7 +21,7 @@
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceViewHolder;
-import com.android.settingslib.R;
+import com.android.settings.R;
import com.android.wifitrackerlib.WifiEntry;
/**
diff --git a/src/com/android/settings/wifi/LinkablePreference.java b/src/com/android/settings/wifi/LinkablePreference.java
index 9581e7a..d29482d 100644
--- a/src/com/android/settings/wifi/LinkablePreference.java
+++ b/src/com/android/settings/wifi/LinkablePreference.java
@@ -29,7 +29,7 @@
import androidx.preference.PreferenceViewHolder;
import com.android.settings.LinkifyUtils;
-import com.android.settingslib.R;
+import com.android.settings.R;
/**
* A preference with a title that can have linkable content on click.
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index c5c47d2..6bf6135 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -125,7 +125,7 @@
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
- assertThat(info.chargeLabel.toString()).isEqualTo(STATUS_CHARGING_NO_TIME);
+ assertThat(info.chargeLabel.toString()).ignoringCase().isEqualTo(STATUS_CHARGING_NO_TIME);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java
index 496897f..c7dfb15 100644
--- a/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java
@@ -28,6 +28,8 @@
import android.content.Context;
import android.provider.Settings;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.R;
import com.android.settings.RestrictedListPreference;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
@@ -42,11 +44,8 @@
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
-import androidx.preference.PreferenceScreen;
-
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class, ShadowRestrictedLockUtilsInternal.class})
public class ShowOnLockscreenNotificationPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
index b04a2cd..77ddfbd 100644
--- a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
@@ -53,12 +53,12 @@
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -74,7 +74,6 @@
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -102,6 +101,8 @@
private HeadsetProfile mHeadsetProfile;
@Mock
private HearingAidProfile mHearingAidProfile;
+ @Mock
+ private LeAudioProfile mLeAudioProfile;
private Context mContext;
private PreferenceScreen mScreen;
@@ -117,6 +118,7 @@
private AudioSwitchPreferenceController mController;
private List<BluetoothDevice> mProfileConnectedDevices;
private List<BluetoothDevice> mHearingAidActiveDevices;
+ private List<BluetoothDevice> mLeAudioActiveDevices;
private List<BluetoothDevice> mEmptyDevices;
private ShadowPackageManager mPackageManager;
@@ -136,6 +138,7 @@
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
+ when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mPackageManager = Shadow.extract(mContext.getPackageManager());
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
@@ -156,6 +159,7 @@
mPreference = new ListPreference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
+ mLeAudioActiveDevices = new ArrayList<>();
mEmptyDevices = new ArrayList<>(2);
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
@@ -391,6 +395,55 @@
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
}
+ @Test
+ public void getConnectedLeAudioDevices_connectedLeAudioDevice_shouldAddDeviceToList() {
+ mEmptyDevices.clear();
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+
+ mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
+
+ assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
+ }
+
+ @Test
+ public void getConnectedLeAudioDevices_disconnectedLeAudioDevice_shouldNotAddDeviceToList() {
+ BluetoothDevice connectdBtLeAduioDevice =
+ spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
+ when(connectdBtLeAduioDevice.isConnected()).thenReturn(true);
+ BluetoothDevice disonnectdBtLeAduioDevice =
+ spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
+ when(disonnectdBtLeAduioDevice.isConnected()).thenReturn(false);
+ mEmptyDevices.clear();
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ mProfileConnectedDevices.add(connectdBtLeAduioDevice);
+ mProfileConnectedDevices.add(disonnectdBtLeAduioDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+
+ mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
+
+ assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, connectdBtLeAduioDevice);
+ }
+
+ @Test
+ public void findActiveLeAudioDevice_noActiveDevice_returnNull() {
+ mLeAudioActiveDevices.clear();
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveLeAudioDevice()).isNull();
+ }
+
+ @Test
+ public void findActiveLeAudioDevice_withActiveDevice_returnActiveDevice() {
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveLeAudioDevice()).isEqualTo(mBluetoothDevice);
+ }
+
private class AudioSwitchPreferenceControllerTestable extends
AudioSwitchPreferenceController {
AudioSwitchPreferenceControllerTestable(Context context, String key) {
diff --git a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
index 2580bfd..7543b5f 100644
--- a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.sound;
+import static android.media.AudioSystem.DEVICE_OUT_BLE_HEADSET;
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
@@ -46,19 +47,18 @@
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBluetoothDevice;
@@ -66,7 +66,6 @@
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -78,10 +77,12 @@
private static final String TEST_DEVICE_NAME_2 = "Test_HFP_BT_Device_NAME_2";
private static final String TEST_HAP_DEVICE_NAME_1 = "Test_HAP_BT_Device_NAME_1";
private static final String TEST_HAP_DEVICE_NAME_2 = "Test_HAP_BT_Device_NAME_2";
+ private static final String TEST_LE_AUDIO_DEVICE_NAME_1 = "Test_LE_AUDIO_Device_NAME_1";
private static final String TEST_DEVICE_ADDRESS_1 = "00:A1:A1:A1:A1:A1";
private static final String TEST_DEVICE_ADDRESS_2 = "00:B2:B2:B2:B2:B2";
private static final String TEST_DEVICE_ADDRESS_3 = "00:C3:C3:C3:C3:C3";
private static final String TEST_DEVICE_ADDRESS_4 = "00:D4:D4:D4:D4:D4";
+ private static final String TEST_DEVICE_ADDRESS_5 = "00:E5:E5:E5:E5:E5";
private final static long HISYNCID1 = 10;
private final static long HISYNCID2 = 11;
@@ -96,6 +97,8 @@
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
private Context mContext;
@@ -113,6 +116,7 @@
private HandsFreeProfileOutputPreferenceController mController;
private List<BluetoothDevice> mProfileConnectedDevices;
private List<BluetoothDevice> mHearingAidActiveDevices;
+ private List<BluetoothDevice> mLeAudioActiveDevices;
@Before
public void setUp() {
@@ -129,24 +133,29 @@
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
+ when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
when(mBluetoothDevice.isConnected()).thenReturn(true);
mSecondBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
when(mSecondBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_2);
+ when(mSecondBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_2);
when(mSecondBluetoothDevice.isConnected()).thenReturn(true);
mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
when(mLeftBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_1);
+ when(mLeftBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_1);
when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_4));
when(mRightBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_2);
+ when(mRightBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_2);
when(mRightBluetoothHapDevice.isConnected()).thenReturn(true);
mController = new HandsFreeProfileOutputPreferenceController(mContext, TEST_KEY);
@@ -154,6 +163,7 @@
mPreference = new ListPreference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
+ mLeAudioActiveDevices = new ArrayList<>();
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mScreen.getContext()).thenReturn(mContext);
@@ -245,7 +255,6 @@
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_oneHeadsetsAvailableAndActivated_shouldSetDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
@@ -267,7 +276,6 @@
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_moreThanOneHfpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
@@ -328,7 +336,6 @@
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -353,7 +360,6 @@
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -382,7 +388,6 @@
* ConnectedDevice should not contain second HAP device with same HisyncId
*/
@Test
- @Ignore
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -416,7 +421,6 @@
* ConnectedDevice should not contain second HAP device with same HisyncId
*/
@Test
- @Ignore
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -449,7 +453,6 @@
* ConnectedDevice should contain both HAP device with different HisyncId
*/
@Test
- @Ignore
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -474,6 +477,25 @@
}
@Test
+ public void updateState_leAudioDeviceActive_shouldSetActivatedDeviceName() {
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
+ when(mBluetoothDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isTrue();
+ assertThat(mPreference.getSummary()).isEqualTo(mBluetoothDevice.getName());
+ }
+
+ @Test
public void findActiveDevice_onlyHeadsetDeviceActive_returnHeadsetDevice() {
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
@@ -489,12 +511,60 @@
assertThat(mController.findActiveDevice()).isNull();
}
+ @Test
+ public void findActiveDevice_allProfilesWithActiveDevice_returnHADevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mController.mConnectedDevices.clear();
+ mController.mConnectedDevices.add(mBluetoothDevice);
+ mController.mConnectedDevices.add(mLeftBluetoothHapDevice);
+ mController.mConnectedDevices.add(btLeDevice);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
+ when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(mLeftBluetoothHapDevice);
+ }
+
+ @Test
+ public void findActiveDevice_headsetDeviceAndLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
+ @Test
+ public void findActiveDevice_onlyLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mHeadsetProfile.getActiveDevice()).thenReturn(null);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
+
/**
* One Bluetooth devices are available, and select the device.
* Preference summary should be device name.
*/
@Test
- @Ignore
public void onPreferenceChange_toBtDevice_shouldSetBtDeviceName() {
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
@@ -509,16 +579,10 @@
* Preference summary should be second device name.
*/
@Test
- @Ignore
public void onPreferenceChange_toBtDevices_shouldSetSecondBtDeviceName() {
- ShadowBluetoothDevice shadowBluetoothDevice;
- BluetoothDevice secondBluetoothDevice;
- secondBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2);
- shadowBluetoothDevice = Shadows.shadowOf(secondBluetoothDevice);
- shadowBluetoothDevice.setName(TEST_DEVICE_NAME_2);
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
- mController.mConnectedDevices.add(secondBluetoothDevice);
+ mController.mConnectedDevices.add(mSecondBluetoothDevice);
mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_2);
diff --git a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
index 10471cb..036d58c 100644
--- a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.sound;
+import static android.media.AudioSystem.DEVICE_OUT_BLE_HEADSET;
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
import static android.media.AudioSystem.DEVICE_OUT_EARPIECE;
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
@@ -56,13 +57,13 @@
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.media.MediaOutputConstants;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -79,7 +80,6 @@
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -91,10 +91,12 @@
private static final String TEST_DEVICE_NAME_2 = "Test_A2DP_BT_Device_NAME_2";
private static final String TEST_HAP_DEVICE_NAME_1 = "Test_HAP_BT_Device_NAME_1";
private static final String TEST_HAP_DEVICE_NAME_2 = "Test_HAP_BT_Device_NAME_2";
+ private static final String TEST_LE_AUDIO_DEVICE_NAME_1 = "Test_LE_AUDIO_Device_NAME_1";
private static final String TEST_DEVICE_ADDRESS_1 = "00:A1:A1:A1:A1:A1";
private static final String TEST_DEVICE_ADDRESS_2 = "00:B2:B2:B2:B2:B2";
private static final String TEST_DEVICE_ADDRESS_3 = "00:C3:C3:C3:C3:C3";
private static final String TEST_DEVICE_ADDRESS_4 = "00:D4:D4:D4:D4:D4";
+ private static final String TEST_DEVICE_ADDRESS_5 = "00:E5:E5:E5:E5:E5";
private static final String TEST_PACKAGE_NAME = "com.test.packagename";
private static final String TEST_APPLICATION_LABEL = "APP Test Label";
@@ -109,6 +111,8 @@
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
@Mock
private MediaSessionManager mMediaSessionManager;
@@ -130,6 +134,7 @@
private MediaOutputPreferenceController mController;
private List<BluetoothDevice> mProfileConnectedDevices;
private List<BluetoothDevice> mHearingAidActiveDevices;
+ private List<BluetoothDevice> mLeAudioActiveDevices;
private List<MediaController> mMediaControllers = new ArrayList<>();
private MediaController.PlaybackInfo mPlaybackInfo;
private PlaybackState mPlaybackState;
@@ -170,12 +175,14 @@
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
+ when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
when(mBluetoothDevice.isConnected()).thenReturn(true);
mSecondBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
@@ -184,6 +191,7 @@
mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
when(mLeftBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_1);
+ when(mLeftBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_1);
when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_4));
@@ -195,6 +203,7 @@
mPreference = new Preference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
+ mLeAudioActiveDevices = new ArrayList<>();
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mScreen.getContext()).thenReturn(mContext);
@@ -234,7 +243,6 @@
* Preference summary should be device's name
*/
@Test
- @Ignore
public void updateState_withActiveBtDevice_setActivatedDeviceName() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
@@ -254,7 +262,6 @@
* Preference summary should be device's name
*/
@Test
- @Ignore
public void updateState_withActiveHADevice_setActivatedDeviceName() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
@@ -270,6 +277,24 @@
}
@Test
+ public void updateState_withActiveLeAudioDevice_setActivatedDeviceName() {
+ mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ mProfileConnectedDevices.add(mSecondBluetoothDevice);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mPreference.getSummary()).isNull();
+ mController.updateState(mPreference);
+ assertThat(mPreference.getSummary()).isEqualTo(TEST_LE_AUDIO_DEVICE_NAME_1);
+ }
+
+ @Test
public void updateState_noActiveLocalPlayback_noTitle() {
mPlaybackState = new PlaybackState.Builder()
.setState(PlaybackState.STATE_NONE, 0, 1)
@@ -350,6 +375,49 @@
assertThat(mController.findActiveDevice()).isNull();
}
+ @Test
+ public void findActiveDevice_allProfilesWithActiveDevice_returnHADevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(mLeftBluetoothHapDevice);
+ }
+
+ @Test
+ public void findActiveDevice_a2dpDeviceAndLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
+ @Test
+ public void findActiveDevice_onlyLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mA2dpProfile.getActiveDevice()).thenReturn(null);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
private void initPackage() {
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mAppInfo = new ApplicationInfo();