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

Commit 6ac9d636 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Fix AvrcpBipClientTest

AvrcpBipClient starts connecting at initialization, which
means during the test it will fail coonnecting and set the
connection state back to disconnected. Some tests are
setting the state directly and will fail if the connection
failure takes too long.

Added two methods connectAsync and disconnectAsync which
will call the handler and start connecting/disconnecting.
These methods are package-private as there is only one
usage of AvrcpBipClient.
Initializing AvrcpBipClient won't auto connect the device.

Bug: 297490983
Tag: #feature
Test: atest BluetoothInstrumentationTests
Change-Id: Iac68c871393e78b7a93ce149e2012d55c8cf4d41
parent 7e0b6227
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -118,7 +118,9 @@ public class AvrcpBipClient {
    }

    /**
     * Creates a BIP image pull client and connects to a remote device's BIP image push server.
     * Creates a BIP image pull client
     *
     * <p>{@link connectAsync()} must be called separately.
     */
    public AvrcpBipClient(BluetoothDevice remoteDevice, int psm, Callback callback) {
        if (remoteDevice == null) {
@@ -138,7 +140,6 @@ public class AvrcpBipClient {
        Looper looper = mThread.getLooper();

        mHandler = new AvrcpBipClientHandler(looper, this);
        mHandler.obtainMessage(CONNECT).sendToTarget();
    }

    /**
@@ -165,7 +166,7 @@ public class AvrcpBipClient {
    public void shutdown() {
        debug("Shutdown client");
        try {
            mHandler.obtainMessage(DISCONNECT).sendToTarget();
            disconnectAsync();
        } catch (IllegalStateException e) {
            // Means we haven't been started or we're already stopped. Doing this makes this call
            // always safe no matter the state.
@@ -242,6 +243,11 @@ public class AvrcpBipClient {
        }
    }

    /** Connects asynchronously */
    void connectAsync() {
        mHandler.obtainMessage(CONNECT).sendToTarget();
    }

    /**
     * Connects to the remote device's BIP Image Pull server
     */
@@ -316,10 +322,14 @@ public class AvrcpBipClient {
        }
    }

    /** Disconnects asynchronously */
    void disconnectAsync() {
        mHandler.obtainMessage(DISCONNECT).sendToTarget();
    }

    /**
     * Permanently disconnects this client from the remote device's BIP server and notifies of the
     * new connection status.
     *
     */
    private synchronized void disconnect() {
        if (mSession != null) {
+1 −0
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@ public class AvrcpCoverArtManager {
        debug("Connect " + device + ", psm: " + psm);
        if (mClients.containsKey(device)) return false;
        AvrcpBipClient client = new AvrcpBipClient(device, psm, new BipClientCallback(device));
        client.connectAsync();
        mClients.put(device, client);
        mBipSessions.put(device, new AvrcpBipSession(device));
        return true;
+7 −6
Original line number Diff line number Diff line
@@ -141,11 +141,12 @@ public class AvrcpBipClientTest {

    @Test
    public void toString_returnsClientInfo() {
        AvrcpBipClient client = new AvrcpBipClient(mTestDevice, TEST_PSM,
                mArtManager.new BipClientCallback(mTestDevice));

        String expected = "<AvrcpBipClient" + " device=" + mTestDevice + " psm="
                + TEST_PSM + " state=" + client.getStateName() + ">";
        assertThat(client.toString()).isEqualTo(expected);
        String expected =
                "<AvrcpBipClient"
                        + (" device=" + mTestDevice)
                        + (" psm=" + TEST_PSM)
                        + (" state=" + mClient.getStateName())
                        + ">";
        assertThat(mClient.toString()).isEqualTo(expected);
    }
}