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

Commit 1c9476ad authored by Qingqi Lei's avatar Qingqi Lei Committed by Android (Google) Code Review
Browse files

Merge "Add unit tests to check APDU channel is always released." into main

parents d8ca37ec 3ec9b3b6
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));
    }
}