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

Commit a2af1593 authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Check connection policy before showing "Problem connecting"" into main

parents 759f9ccc 6f2ca821
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -1863,10 +1863,31 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                + " mIsLeAudioProfileConnectedFail=" + mIsLeAudioProfileConnectedFail
                + " mIsHeadsetProfileConnectedFail=" + mIsHeadsetProfileConnectedFail
                + " isConnectedSapDevice()=" + isConnectedSapDevice());

        return mIsA2dpProfileConnectedFail || mIsHearingAidProfileConnectedFail
                || (!isConnectedSapDevice() && mIsHeadsetProfileConnectedFail)
                || mIsLeAudioProfileConnectedFail;
        if (mIsA2dpProfileConnectedFail) {
            A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
            if (a2dpProfile != null && a2dpProfile.isEnabled(mDevice)) {
                return true;
            }
        }
        if (mIsHearingAidProfileConnectedFail) {
            HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
            if (hearingAidProfile != null && hearingAidProfile.isEnabled(mDevice)) {
                return true;
            }
        }
        if (!isConnectedSapDevice() && mIsHeadsetProfileConnectedFail) {
            HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile();
            if (headsetProfile != null && headsetProfile.isEnabled(mDevice)) {
                return true;
            }
        }
        if (mIsLeAudioProfileConnectedFail) {
            LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
            if (leAudioProfile != null && leAudioProfile.isEnabled(mDevice)) {
                return true;
            }
        }
        return false;
    }

    /**
+19 −0
Original line number Diff line number Diff line
@@ -182,6 +182,8 @@ public class CachedBluetoothDeviceTest {
        updateProfileStatus(connectingProfile, BluetoothProfile.STATE_CONNECTING);
        // Set connection policy
        when(connectingProfile.getConnectionPolicy(mDevice)).thenReturn(connectionPolicy);
        when(connectingProfile.isEnabled(mDevice))
                .thenReturn(connectionPolicy > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);

        // Act & Assert:
        //   Get the expected connection summary.
@@ -191,6 +193,9 @@ public class CachedBluetoothDeviceTest {

    @Test
    public void onProfileStateChanged_testConnectingToDisconnected_policyAllowed_problem() {
        when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
        when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);

        String connectTimeoutString = mContext.getString(R.string.profile_connect_timeout_subtext);

        testTransitionFromConnectingToDisconnected(mA2dpProfile, mLeAudioProfile,
@@ -205,6 +210,9 @@ public class CachedBluetoothDeviceTest {

    @Test
    public void onProfileStateChanged_testConnectingToDisconnected_policyForbidden_noProblem() {
        when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
        when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);

        testTransitionFromConnectingToDisconnected(mA2dpProfile, mLeAudioProfile,
        BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, null);
        testTransitionFromConnectingToDisconnected(mHearingAidProfile, mLeAudioProfile,
@@ -217,6 +225,9 @@ public class CachedBluetoothDeviceTest {

    @Test
    public void onProfileStateChanged_testConnectingToDisconnected_policyUnknown_noProblem() {
        when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
        when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);

        testTransitionFromConnectingToDisconnected(mA2dpProfile, mLeAudioProfile,
        BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null);
        testTransitionFromConnectingToDisconnected(mHearingAidProfile, mLeAudioProfile,
@@ -1830,6 +1841,10 @@ public class CachedBluetoothDeviceTest {
    @Test
    public void getConnectionSummary_profileConnectedFail_showErrorMessage() {
        final A2dpProfile profile = mock(A2dpProfile.class);
        when(mProfileManager.getA2dpProfile()).thenReturn(profile);
        when(profile.getConnectionPolicy(mDevice))
                .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        when(profile.isEnabled(mDevice)).thenReturn(true);
        mCachedDevice.onProfileStateChanged(profile, BluetoothProfile.STATE_CONNECTED);
        mCachedDevice.setProfileConnectedStatus(BluetoothProfile.A2DP, true);

@@ -1842,6 +1857,10 @@ public class CachedBluetoothDeviceTest {
    @Test
    public void getTvConnectionSummary_profileConnectedFail_showErrorMessage() {
        final A2dpProfile profile = mock(A2dpProfile.class);
        when(mProfileManager.getA2dpProfile()).thenReturn(profile);
        when(profile.getConnectionPolicy(mDevice))
                .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        when(profile.isEnabled(mDevice)).thenReturn(true);
        mCachedDevice.onProfileStateChanged(profile, BluetoothProfile.STATE_CONNECTED);
        mCachedDevice.setProfileConnectedStatus(BluetoothProfile.A2DP, true);