FileDocCategorySizeDatePackage
BasicNfcEeTest.javaAPI DocAndroid 5.1 API4093Thu Mar 12 22:22:40 GMT 2015com.android.nfc_extras.tests

BasicNfcEeTest

public class BasicNfcEeTest extends android.test.InstrumentationTestCase

Fields Summary
private android.content.Context
mContext
private com.android.nfc_extras.NfcAdapterExtras
mAdapterExtras
private com.android.nfc_extras.NfcExecutionEnvironment
mEe
public static final byte[]
SELECT_CARD_MANAGER_COMMAND
public static final byte[]
SELECT_CARD_MANAGER_RESPONSE
Constructors Summary
Methods Summary
private static voidassertByteArrayEquals(byte[] b1, byte[] b2)

        assertEquals(b1.length, b2.length);
        for (int i = 0; i < b1.length; i++) {
            assertEquals(b1[i], b2[i]);
        }
    
protected voidsetUp()


    
         
        super.setUp();
        mContext = getInstrumentation().getTargetContext();
        mAdapterExtras = NfcAdapterExtras.get(NfcAdapter.getDefaultAdapter(mContext));
        mEe = mAdapterExtras.getEmbeddedExecutionEnvironment();
    
public voidtestDisableEe()

        mAdapterExtras.setCardEmulationRoute(
                new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null));
        CardEmulationRoute newRoute = mAdapterExtras.getCardEmulationRoute();
        assertEquals(CardEmulationRoute.ROUTE_OFF, newRoute.route);
        assertNull(newRoute.nfcEe);
    
public voidtestEnableEe()

        mAdapterExtras.setCardEmulationRoute(
                new CardEmulationRoute(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, mEe));
        CardEmulationRoute newRoute = mAdapterExtras.getCardEmulationRoute();
        assertEquals(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, newRoute.route);
        assertEquals(mEe, newRoute.nfcEe);
    
public voidtestSendCardManagerApdu()

        mEe.open();

        try {
            byte[] out = mEe.transceive(SELECT_CARD_MANAGER_COMMAND);
            assertTrue(out.length >= SELECT_CARD_MANAGER_RESPONSE.length);
            byte[] trailing = Arrays.copyOfRange(out,
                    out.length - SELECT_CARD_MANAGER_RESPONSE.length,
                    out.length);
            assertByteArrayEquals(SELECT_CARD_MANAGER_RESPONSE, trailing);

        } finally {
            mEe.close();
        }

    
public voidtestSendCardManagerApduMultiple()

        for (int i=0; i<10; i++) {
            try {
            mEe.open();

            try {
                byte[] out = mEe.transceive(SELECT_CARD_MANAGER_COMMAND);
                byte[] trailing = Arrays.copyOfRange(out,
                        out.length - SELECT_CARD_MANAGER_RESPONSE.length,
                        out.length);

            } finally {
                try {Thread.sleep(1000);} catch (InterruptedException e) {}
                mEe.close();
            }
            } catch (IOException e) {}
        }

        testSendCardManagerApdu();