summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author MichaƂ Narajowski <narajn@google.com> 2023-03-07 10:09:31 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-03-07 10:09:31 +0000
commit180ed70ad2d09a31e6b1f4fe2395d5fc4a09fd84 (patch)
treef2525e63c4deadcff1ea2c787f353b518d7120af
parent2dbeb96d78f286002269335d3d8e6f87f343dfbc (diff)
parentfb15a05e901482439ef96ab8f4d51b2d9111da63 (diff)
Merge changes I3af271d0,I46df1c8b,I1eb116e4,I492bfc97 am: fb15a05e90
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2469446 Change-Id: I4c5d6d872163c454ee8d5f942672004c645dc6b1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
index 79e99387b2fa..7ffd8183e604 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
@@ -74,6 +74,8 @@ public class CachedBluetoothDeviceTest {
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
private BluetoothDevice mDevice;
@Mock
private BluetoothDevice mSubDevice;
@@ -92,15 +94,76 @@ public class CachedBluetoothDeviceTest {
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
when(mDevice.getAddress()).thenReturn(DEVICE_ADDRESS);
when(mHfpProfile.isProfileReady()).thenReturn(true);
+ when(mHfpProfile.getProfileId()).thenReturn(BluetoothProfile.HEADSET);
when(mA2dpProfile.isProfileReady()).thenReturn(true);
+ when(mA2dpProfile.getProfileId()).thenReturn(BluetoothProfile.A2DP);
when(mPanProfile.isProfileReady()).thenReturn(true);
+ when(mPanProfile.getProfileId()).thenReturn(BluetoothProfile.PAN);
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
+ when(mHearingAidProfile.getProfileId()).thenReturn(BluetoothProfile.HEARING_AID);
+ when(mLeAudioProfile.isProfileReady()).thenReturn(true);
+ when(mLeAudioProfile.getProfileId()).thenReturn(BluetoothProfile.LE_AUDIO);
mCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mDevice));
mSubCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mSubDevice));
doAnswer((invocation) -> mBatteryLevel).when(mCachedDevice).getBatteryLevel();
doAnswer((invocation) -> mBatteryLevel).when(mSubCachedDevice).getBatteryLevel();
}
+ private void testTransitionFromConnectingToDisconnected(
+ LocalBluetoothProfile connectingProfile, LocalBluetoothProfile connectedProfile,
+ int connectionPolicy, String expectedSummary) {
+ // Arrange:
+ // At least one profile has to be connected
+ updateProfileStatus(connectedProfile, BluetoothProfile.STATE_CONNECTED);
+ // Set profile under test to CONNECTING
+ updateProfileStatus(connectingProfile, BluetoothProfile.STATE_CONNECTING);
+ // Set connection policy
+ when(connectingProfile.getConnectionPolicy(mDevice)).thenReturn(connectionPolicy);
+
+ // Act & Assert:
+ // Get the expected connection summary.
+ updateProfileStatus(connectingProfile, BluetoothProfile.STATE_DISCONNECTED);
+ assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(expectedSummary);
+ }
+
+ @Test
+ public void onProfileStateChanged_testConnectingToDisconnected_policyAllowed_problem() {
+ String connectTimeoutString = mContext.getString(R.string.profile_connect_timeout_subtext);
+
+ testTransitionFromConnectingToDisconnected(mA2dpProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_ALLOWED, connectTimeoutString);
+ testTransitionFromConnectingToDisconnected(mHearingAidProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_ALLOWED, connectTimeoutString);
+ testTransitionFromConnectingToDisconnected(mHfpProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_ALLOWED, connectTimeoutString);
+ testTransitionFromConnectingToDisconnected(mLeAudioProfile, mA2dpProfile,
+ BluetoothProfile.CONNECTION_POLICY_ALLOWED, connectTimeoutString);
+ }
+
+ @Test
+ public void onProfileStateChanged_testConnectingToDisconnected_policyForbidden_noProblem() {
+ testTransitionFromConnectingToDisconnected(mA2dpProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, null);
+ testTransitionFromConnectingToDisconnected(mHearingAidProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, null);
+ testTransitionFromConnectingToDisconnected(mHfpProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, null);
+ testTransitionFromConnectingToDisconnected(mLeAudioProfile, mA2dpProfile,
+ BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, null);
+ }
+
+ @Test
+ public void onProfileStateChanged_testConnectingToDisconnected_policyUnknown_noProblem() {
+ testTransitionFromConnectingToDisconnected(mA2dpProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null);
+ testTransitionFromConnectingToDisconnected(mHearingAidProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null);
+ testTransitionFromConnectingToDisconnected(mHfpProfile, mLeAudioProfile,
+ BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null);
+ testTransitionFromConnectingToDisconnected(mLeAudioProfile, mA2dpProfile,
+ BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null);
+ }
+
@Test
public void getConnectionSummary_testProfilesInactive_returnPairing() {
// Arrange: