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

Commit 3ec9b3b6 authored by Qingqi Lei's avatar Qingqi Lei
Browse files

Add unit tests to check APDU channel is always released.

Bug: 382549728
Flag: TEST_ONLY


Change-Id: I185a581729c983e580307f99fc07531ab7d2a862
parent 578bb132
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -122,7 +122,11 @@ public class ApduSenderTest {
    }

    @After
    public void tearDown() {
    public void tearDown() throws InterruptedException {
        // Send an APDU to verify that the channel lock is not stuck (b/382549728).
        // Sameas testSend(), but not verifying mMockCi interactions.
        checkChannelLock();

        mHandler.removeCallbacksAndMessages(null);
        mHandler = null;
        mLooper = null;
@@ -536,4 +540,20 @@ public class ApduSenderTest {
                .remove(SHARED_PREFS_KEY_CHANNEL_RESPONSE)
                .apply();
    }

    /**
     * Send an APDU to verify that the channel lock is not stuck (b/382549728).
     * Same as testSend(), but not verifying mMockCi interactions.
     */
    private void checkChannelLock() throws InterruptedException {
        int channel = LogicalChannelMocker.mockOpenLogicalChannelResponse(mMockCi, "9000");
        LogicalChannelMocker.mockSendToLogicalChannel(mMockCi, channel, "A1A1A19000");
        LogicalChannelMocker.mockCloseLogicalChannel(mMockCi, channel, /* error= */ null);

        mSender.send((selectResponse, requestBuilder) -> requestBuilder.addApdu(
                10, 1, 2, 3, 0, "a"), mResponseCaptor, mHandler);
        mLooper.processAllMessages();

        assertEquals("A1A1A1", IccUtils.bytesToHexString(mResponseCaptor.response));
    }
}