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

Commit 1a3a69cc authored by Alice Kuo's avatar Alice Kuo Committed by Rongxuan Liu
Browse files

Correct the getConnectionState return value

The return value of AdpaterService.getConnectionState get from native
layer. The definitions are private inside BluetoothDevice. Clone the
definition to the other file to handle the return value correctly. We
should refactor this part later.

Bug: 300157212
Test: atest PhonePolicyTest
Change-Id: Ibdbc07bb32e353aae82cd4614cf1f713c962b5cb
parent f705f3d2
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -229,6 +229,14 @@ public class AdapterService extends Service {

    private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;

    /**
     * Connection state bitmask as returned by getConnectionState.
     */
    public static final int CONNECTION_STATE_DISCONNECTED = 0;
    public static final int CONNECTION_STATE_CONNECTED = 1;
    public static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2;
    public static final int CONNECTION_STATE_ENCRYPTED_LE = 4;

    // Report ID definition
    public enum BqrQualityReportId {
        QUALITY_REPORT_ID_MONITOR_MODE(0x01),
@@ -2899,7 +2907,7 @@ public class AdapterService extends Service {
            if (service == null
                    || !Utils.checkConnectPermissionForDataDelivery(
                            service, attributionSource, "AdapterService getConnectionState")) {
                return BluetoothProfile.STATE_DISCONNECTED;
                return CONNECTION_STATE_DISCONNECTED;
            }

            return service.getConnectionState(device);
+2 −1
Original line number Diff line number Diff line
@@ -653,7 +653,8 @@ class PhonePolicy implements AdapterService.BluetoothStateCallback {
        }

        /* Make sure that device is still connected before connecting other profiles */
        if (mAdapterService.getConnectionState(device) != BluetoothAdapter.STATE_CONNECTED) {
        if (mAdapterService.getConnectionState(device)
                == AdapterService.CONNECTION_STATE_DISCONNECTED) {
            debugLog("processConnectOtherProfiles: device is not connected anymore " + device);
            return;
        }
+2 −2
Original line number Diff line number Diff line
@@ -462,7 +462,7 @@ public class PhonePolicyTest {

        // ACL is connected, lets simulate this.
        when(mAdapterService.getConnectionState(bondedDevices[0]))
                .thenReturn(BluetoothProfile.STATE_CONNECTED);
                .thenReturn(AdapterService.CONNECTION_STATE_ENCRYPTED_BREDR);

        // We send a connection successful for one profile since the re-connect *only* works if we
        // have already connected successfully over one of the profiles
@@ -507,7 +507,7 @@ public class PhonePolicyTest {
        // ACL is disconnected just after HEADSET profile got connected and connectOtherProfile
        // was scheduled. Lets simulate this.
        when(mAdapterService.getConnectionState(bondedDevices[0]))
                .thenReturn(BluetoothProfile.STATE_DISCONNECTED);
                .thenReturn(AdapterService.CONNECTION_STATE_DISCONNECTED);

        // We send a connection successful for one profile since the re-connect *only* works if we
        // have already connected successfully over one of the profiles