New CTS tests for HCE APIs.

Bug: 17617916
Change-Id: I28a5e5cb704dc1c7235b08cea0cfa13f212bd8aa
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 2b5b4f2..88adcbb 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -551,6 +551,14 @@
                 android:label="@string/nfc_hce_conflicting_non_payment_emulator"
                 android:configChanges="keyboardHidden|orientation|screenSize" />
 
+        <activity android:name=".nfc.hce.ForegroundNonPaymentEmulatorActivity"
+                android:label="@string/nfc_hce_foreground_non_payment_emulator"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
+        <activity android:name=".nfc.hce.ForegroundPaymentEmulatorActivity"
+                android:label="@string/nfc_hce_foreground_payment_emulator"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
         <activity android:name=".nfc.hce.OffHostEmulatorActivity"
                 android:label="@string/nfc_hce_offhost_service_emulator"
                 android:configChanges="keyboardHidden|orientation|screenSize" />
@@ -567,6 +575,26 @@
                 android:label="@string/nfc_hce_tap_test_emulator"
                 android:configChanges="keyboardHidden|orientation|screenSize" />
 
+        <activity android:name=".nfc.hce.DynamicAidEmulatorActivity"
+                android:label="@string/nfc_hce_payment_dynamic_aids_emulator"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
+        <activity android:name=".nfc.hce.PrefixPaymentEmulatorActivity"
+                android:label="@string/nfc_hce_payment_prefix_aids_emulator"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
+        <activity android:name=".nfc.hce.PrefixPaymentEmulator2Activity"
+                android:label="@string/nfc_hce_payment_prefix_aids_emulator_2"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
+        <activity android:name=".nfc.hce.DualNonPaymentPrefixEmulatorActivity"
+                android:label="@string/nfc_hce_other_prefix_aids_emulator"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
+        <activity android:name=".nfc.hce.ConflictingNonPaymentPrefixEmulatorActivity"
+                android:label="@string/nfc_hce_other_conflicting_prefix_aids_emulator"
+                android:configChanges="keyboardHidden|orientation|screenSize" />
+
         <!-- services used for testing NFC host-based card emulation -->
         <service android:name=".nfc.hce.PaymentService1" android:exported="true"
                  android:permission="android.permission.BIND_NFC_SERVICE"
@@ -632,6 +660,60 @@
             </intent-filter>
             <meta-data android:name="android.nfc.cardemulation.off_host_apdu_service" android:resource="@xml/offhost_aid_list"/>
         </service>
+        <service android:name=".nfc.hce.PaymentServiceDynamicAids" android:exported="true"
+                 android:permission="android.permission.BIND_NFC_SERVICE"
+                 android:enabled="false">
+            <intent-filter>
+                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/payment_aid_list_1"/>
+        </service>
+        <service android:name=".nfc.hce.PrefixPaymentService1" android:exported="true"
+                 android:permission="android.permission.BIND_NFC_SERVICE"
+                 android:enabled="false">
+            <intent-filter>
+                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/payment_prefix_aid_list"/>
+        </service>
+        <service android:name=".nfc.hce.PrefixPaymentService2" android:exported="true"
+                 android:permission="android.permission.BIND_NFC_SERVICE"
+                 android:enabled="false">
+            <intent-filter>
+                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/payment_prefix_aid_list_2"/>
+        </service>
+        <service android:name=".nfc.hce.PrefixTransportService1" android:exported="true"
+                 android:permission="android.permission.BIND_NFC_SERVICE"
+                 android:enabled="false">
+            <intent-filter>
+                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/transport_prefix_aid_list_1"/>
+        </service>
+        <service android:name=".nfc.hce.PrefixTransportService2" android:exported="true"
+                 android:permission="android.permission.BIND_NFC_SERVICE"
+                 android:enabled="false">
+            <intent-filter>
+                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/transport_prefix_aid_list_2"/>
+        </service>
+        <service android:name=".nfc.hce.PrefixAccessService" android:exported="true"
+                 android:permission="android.permission.BIND_NFC_SERVICE"
+                 android:enabled="false">
+            <intent-filter>
+                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/access_prefix_aid_list"/>
+        </service>
 
         <activity android:name=".sensors.AccelerometerTestActivity" android:label="@string/snsr_accel_test"
                 android:screenOrientation="nosensor">
diff --git a/apps/CtsVerifier/res/drawable-hdpi/nfc_hce_banner.png b/apps/CtsVerifier/res/drawable-hdpi/nfc_hce_banner.png
new file mode 100644
index 0000000..333b797
--- /dev/null
+++ b/apps/CtsVerifier/res/drawable-hdpi/nfc_hce_banner.png
Binary files differ
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index a3b920f..b5bd2d6 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -396,6 +396,14 @@
     <string name="nfc_hce_conflicting_non_payment_emulator">Two conflicting non-payment services (Emulator)</string>
     <string name="nfc_hce_conflicting_non_payment_reader">Two conflicting non-payment services (Reader)</string>
 
+    <string name="nfc_hce_foreground_non_payment_emulator">Foreground override non-payment services (Emulator)</string>
+    <string name="nfc_hce_foreground_non_payment_reader">Foreground override non-payment services (Reader)</string>
+    <string name="nfc_hce_foreground_non_payment_help">This test enables two non-payment services with conflicting AIDs. It then uses Androids API to allow the foreground app to set a preference for a specific service. This should prevent a popup dialog from showing. If you see a popup dialog during this asking you to select an app, this test has failed.</string>
+
+    <string name="nfc_hce_foreground_payment_emulator">Foreground override payment services (Emulator)</string>
+    <string name="nfc_hce_foreground_payment_reader">Foreground override payment services (Reader)</string>
+    <string name="nfc_hce_foreground_payment_help">This test enables two payment services, and asks you to set one as the default service. It then uses Androids API to allow the foreground app to set a preference for the non-default service. This will cause the non-default payment service to be invoked.</string>
+    <string name="nfc_hce_change_favor_foreground">This test requires the "Favor foreground app" setting to be enabled. Tap OK to go to Tap and Pay settings and check the Favor foreground app option</string>
     <string name="nfc_hce_offhost_service_emulator">Off-host service (Emulator)</string>
     <string name="nfc_hce_offhost_service_reader">Off-host service (Reader)</string>
     <string name="nfc_hce_offhost_emulator_help">This tests enables a service that declares some AIDs to reside off-host. This test only needs to be passed if your device has a secure element (either embedded or UICC.). The responses from the secure element are not verified by the test - it is up to the tester to verify the responses are as expected.</string>
@@ -410,12 +418,33 @@
     <string name="nfc_hce_throughput_emulator">HCE throughput test (Emulator)</string>
     <string name="nfc_hce_throughput_reader">HCE throughput test (Reader)</string>
     <string name="nfc_hce_throughput_emulator_help">This tests verifies that your HCE implementation can reach a decent throughput. While Android does not have any requirements on HCE performance, many HCE applications such as transport and payment apps do. If the average APDU roundtrip time is more than 50ms, please take a look at your implementation to see where the delay is coming from.</string>
-    <string name="nfc_hce_change_preinstalled_wallet">The device has an installed payment application that is currently set as default. To complete the test, you will be asked whether you want to make Payment Service #1 or #2 the default app. Select yes.</string>
+    <string name="nfc_hce_change_preinstalled_wallet">The device has an installed payment application that is currently set as default. To complete the test, you will be asked whether you want to make another app the default app. Select yes.</string>
     <string name="nfc_hce_change_default_help">You will now be asked whether you want to make Payment Service #1 the default app. Select yes.</string>
     <string name="nfc_hce_conflicting_non_payment_help">When tapping the first time, you will be shown a dialog that asks you to choose between TransportService #1 and TransportService #2. Select TransportService #2. Verify a dialog is shown that asks you to tap again to complete. Now tap again, and if communication with TransportService #2 is successfull the pass button will be enabled."</string>
+
+    <string name="nfc_hce_payment_dynamic_aids_emulator">Dynamic payment AIDs (Emulator)</string>
+    <string name="nfc_hce_payment_dynamic_aids_reader">Dynamic payment AIDs (Reader)</string>
+    <string name="nfc_hce_payment_dynamic_aids_help">This test tries to register dynamic AIDs for a payment service.</string>
+
+    <string name="nfc_hce_payment_prefix_aids_emulator">Payment prefix AIDs (Emulator)</string>
+    <string name="nfc_hce_payment_prefix_aids_reader">Payment prefix AIDs (Reader)</string>
+    <string name="nfc_hce_payment_prefix_aids_help">This test statically registers prefix AIDs for a payment service.</string>
+
+    <string name="nfc_hce_payment_prefix_aids_emulator_2">Payment prefix AIDs 2 (Emulator)</string>
+    <string name="nfc_hce_payment_prefix_aids_reader_2">Payment prefix AIDs 2 (Reader)</string>
+
+    <string name="nfc_hce_other_prefix_aids_emulator">Other prefix AIDs (Emulator)</string>
+    <string name="nfc_hce_other_prefix_aids_reader">Other prefix AIDs (Reader)</string>
+    <string name="nfc_hce_other_prefix_aids_help">This test dynamically registers prefix AIDs for a non-payment service.</string>
+
+    <string name="nfc_hce_other_conflicting_prefix_aids_emulator">Conflicting non-payment prefix AIDs (Emulator)</string>
+    <string name="nfc_hce_other_conflicting_prefix_aids_reader">Conflicting non-payment prefix AIDs (Reader)</string>
+    <string name="nfc_hce_other_conflicting_prefix_aids_help">This test registers conflicting prefix AIDs and makes sure AID conflict detection with prefix AIDs works properly. When tapping the first time, you will be shown a dialog that asks you to choose between TransportService #1 and TransportService #2. Select TransportService #2. Verify a dialog is shown that asks you to tap again to complete. Now tap again, and if communication with TransportService #2 is successfull the pass button will be enabled."</string>
+
     <string name="nfc_payment_service_desc">NFC Payment service</string>
     <string name="ppse">PPSE</string>
     <string name="mastercard">MasterCard</string>
+    <string name="visa">Visa</string>
     <string name="paymentService1">Payment Service #1</string>
     <string name="paymentService2">Payment Service #2</string>
     <string name="transportService1">TransportService #1</string>
diff --git a/apps/CtsVerifier/res/xml/access_prefix_aid_list.xml b/apps/CtsVerifier/res/xml/access_prefix_aid_list.xml
new file mode 100644
index 0000000..915c041
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/access_prefix_aid_list.xml
@@ -0,0 +1,3 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/accessService">
+</host-apdu-service>
diff --git a/apps/CtsVerifier/res/xml/empty_aid_list.xml b/apps/CtsVerifier/res/xml/empty_aid_list.xml
new file mode 100644
index 0000000..0646fd9
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/empty_aid_list.xml
@@ -0,0 +1,3 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/transportService1">
+</host-apdu-service>
diff --git a/apps/CtsVerifier/res/xml/payment_aid_list_1.xml b/apps/CtsVerifier/res/xml/payment_aid_list_1.xml
index 2036402..37344ff 100644
--- a/apps/CtsVerifier/res/xml/payment_aid_list_1.xml
+++ b/apps/CtsVerifier/res/xml/payment_aid_list_1.xml
@@ -1,5 +1,6 @@
 <host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
-    android:description="@string/paymentService1">
+    android:description="@string/paymentService1"
+    android:apduServiceBanner="@drawable/nfc_hce_banner">
         <aid-group android:description="@string/paymentService1" android:category="payment">
             <aid-filter android:name="325041592E5359532E4444463031"
                         android:description="@string/ppse"/>
diff --git a/apps/CtsVerifier/res/xml/payment_aid_list_2.xml b/apps/CtsVerifier/res/xml/payment_aid_list_2.xml
index 36a5af0..fbf9ce52 100644
--- a/apps/CtsVerifier/res/xml/payment_aid_list_2.xml
+++ b/apps/CtsVerifier/res/xml/payment_aid_list_2.xml
@@ -1,5 +1,5 @@
 <host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
-    android:description="@string/paymentService2">
+    android:description="@string/paymentService2" android:apduServiceBanner="@drawable/nfc_hce_banner">
         <aid-group android:description="@string/paymentService2" android:category="payment">
             <aid-filter android:name="325041592E5359532E4444463031"
                         android:description="@string/ppse"/>
diff --git a/apps/CtsVerifier/res/xml/payment_empty_aid_list.xml b/apps/CtsVerifier/res/xml/payment_empty_aid_list.xml
new file mode 100644
index 0000000..6daf5ea
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/payment_empty_aid_list.xml
@@ -0,0 +1,9 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/paymentService1" android:apduServiceBanner="@drawable/nfc_hce_banner">
+        <aid-group android:description="@string/paymentService1" android:category="payment">
+            <aid-filter android:name="325041592E5359532E4444463031"
+                        android:description="@string/ppse"/>
+            <aid-filter android:name="A0000000041010"
+                        android:description="@string/mastercard"/>
+        </aid-group>
+</host-apdu-service>
diff --git a/apps/CtsVerifier/res/xml/payment_prefix_aid_list.xml b/apps/CtsVerifier/res/xml/payment_prefix_aid_list.xml
new file mode 100644
index 0000000..cea5600
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/payment_prefix_aid_list.xml
@@ -0,0 +1,11 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/paymentService1" android:apduServiceBanner="@drawable/nfc_hce_banner">
+        <aid-group android:description="@string/paymentService1" android:category="payment">
+            <aid-filter android:name="325041592E5359532E4444463031"
+                        android:description="@string/ppse"/>
+            <aid-prefix-filter android:name="A000000004"
+                        android:description="@string/mastercard"/>
+            <aid-prefix-filter android:name="A000000003"
+                        android:description="@string/visa"/>
+        </aid-group>
+</host-apdu-service>
diff --git a/apps/CtsVerifier/res/xml/payment_prefix_aid_list_2.xml b/apps/CtsVerifier/res/xml/payment_prefix_aid_list_2.xml
new file mode 100644
index 0000000..67b4d90
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/payment_prefix_aid_list_2.xml
@@ -0,0 +1,19 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/paymentService1" android:apduServiceBanner="@drawable/nfc_hce_banner">
+        <aid-group android:description="@string/paymentService1" android:category="payment">
+            <aid-filter android:name="325041592E5359532E4444463031"
+                        android:description="@string/ppse"/>
+            <aid-prefix-filter android:name="A00000000410"
+                        android:description="@string/mastercard"/>
+            <aid-prefix-filter android:name="A0000000041010"
+                        android:description="@string/mastercard"/>
+            <aid-prefix-filter android:name="A00000000310"
+                        android:description="@string/visa"/>
+        </aid-group>
+        <aid-group android:description="@string/transportService1" android:category="other">
+            <aid-prefix-filter android:name="F0000000FF"
+                        android:description="@string/transportService1"/>
+            <aid-prefix-filter android:name="F000000000"
+                        android:description="@string/transportService1"/>
+        </aid-group>
+</host-apdu-service>
diff --git a/apps/CtsVerifier/res/xml/transport_prefix_aid_list_1.xml b/apps/CtsVerifier/res/xml/transport_prefix_aid_list_1.xml
new file mode 100644
index 0000000..0646fd9
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/transport_prefix_aid_list_1.xml
@@ -0,0 +1,3 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/transportService1">
+</host-apdu-service>
diff --git a/apps/CtsVerifier/res/xml/transport_prefix_aid_list_2.xml b/apps/CtsVerifier/res/xml/transport_prefix_aid_list_2.xml
new file mode 100644
index 0000000..44b1772
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/transport_prefix_aid_list_2.xml
@@ -0,0 +1,3 @@
+<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
+    android:description="@string/transportService2">
+</host-apdu-service>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/NfcDialogs.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/NfcDialogs.java
index 40a12ae..644e637 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/NfcDialogs.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/NfcDialogs.java
@@ -66,6 +66,22 @@
                 .setPositiveButton("OK", null)
                 .create();
     }
+
+    public static AlertDialog createChangeForegroundDialog(final Context context) {
+        return new AlertDialog.Builder(context)
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setTitle(R.string.nfc_hce_tap_reader_title)
+                .setMessage(context.getString(R.string.nfc_hce_change_favor_foreground))
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        Intent intent = new Intent(Settings.ACTION_NFC_PAYMENT_SETTINGS);
+                        context.startActivity(intent);
+                    }
+                })
+                .create();
+    }
+
     private NfcDialogs() {
     }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/AccessService.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/AccessService.java
index 969f621..51eb7ec 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/AccessService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/AccessService.java
@@ -7,9 +7,9 @@
             new ComponentName("com.android.cts.verifier",
             AccessService.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu(HceUtils.ACCESS_AID),
-        "80CA01F000"
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.ACCESS_AID, true),
+        HceUtils.buildCommandApdu("80CA01F000", true)
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/BaseEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/BaseEmulatorActivity.java
index bcd2b8d..8aa82b5 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/BaseEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/BaseEmulatorActivity.java
@@ -1,10 +1,13 @@
 package com.android.cts.verifier.nfc.hce;
 
 import android.annotation.TargetApi;
+import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.nfc.NfcAdapter;
@@ -19,7 +22,6 @@
 
 import com.android.cts.verifier.PassFailButtons;
 import com.android.cts.verifier.R;
-import com.android.cts.verifier.nfc.hce.PaymentService1;
 
 @TargetApi(19)
 public abstract class BaseEmulatorActivity extends PassFailButtons.Activity {
@@ -27,6 +29,7 @@
     NfcAdapter mAdapter;
     CardEmulation mCardEmulation;
     ProgressDialog mSetupDialog;
+    ComponentName mMakingDefault;
 
     final ArrayList<ComponentName> SERVICES = new ArrayList<ComponentName>(
             Arrays.asList(
@@ -36,7 +39,13 @@
             TransportService2.COMPONENT,
             AccessService.COMPONENT,
             ThroughputService.COMPONENT,
-            OffHostService.COMPONENT)
+            OffHostService.COMPONENT,
+            PaymentServiceDynamicAids.COMPONENT,
+            PrefixPaymentService1.COMPONENT,
+            PrefixPaymentService2.COMPONENT,
+            PrefixTransportService1.COMPONENT,
+            PrefixTransportService2.COMPONENT,
+            PrefixAccessService.COMPONENT)
     );
 
     @Override
@@ -73,6 +82,29 @@
         new SetupServicesTask().execute(components);
     }
 
+    final boolean makePaymentDefault(final ComponentName defaultComponent, int stringId) {
+        if (!mCardEmulation.isDefaultServiceForCategory(defaultComponent,
+                CardEmulation.CATEGORY_PAYMENT)) {
+            AlertDialog.Builder builder = new AlertDialog.Builder(this);
+            builder.setTitle("Note");
+            builder.setMessage(stringId);
+            mMakingDefault = defaultComponent;
+            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                @Override
+                public void onClick(DialogInterface dialog, int which) {
+                Intent changeDefault = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
+                changeDefault.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
+                changeDefault.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, defaultComponent);
+                startActivityForResult(changeDefault, 0);
+                }
+            });
+            builder.show();
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -127,5 +159,38 @@
                     CardEmulation.CATEGORY_PAYMENT);
             return true;
         }
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (resultCode == Activity.RESULT_OK) {
+            // Verify it's default
+            if (!mCardEmulation.isDefaultServiceForCategory(mMakingDefault,
+                    CardEmulation.CATEGORY_PAYMENT)) {
+                // Popup dialog-box
+                AlertDialog.Builder builder = new AlertDialog.Builder(this);
+                builder.setTitle("Test failed.");
+                builder.setMessage("The service was not made the default service according " +
+                        "to CardEmulation.getDefaultServiceForCategory(), verify the make " +
+                        "default implementation is correct.");
+                builder.setPositiveButton("OK", null);
+                builder.show();
+                onPaymentDefaultResult(mMakingDefault, false);
+            } else {
+                onPaymentDefaultResult(mMakingDefault, true);
+            }
+        } else {
+            AlertDialog.Builder builder = new AlertDialog.Builder(this);
+            builder.setTitle("Test failed.");
+            builder.setMessage("You clicked no.");
+            builder.setPositiveButton("OK", null);
+            builder.show();
+            onPaymentDefaultResult(mMakingDefault, false);
+        }
+    }
+
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+
     };
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ChangeDefaultEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ChangeDefaultEmulatorActivity.java
index 0681f49..633a152 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ChangeDefaultEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ChangeDefaultEmulatorActivity.java
@@ -1,20 +1,16 @@
 package com.android.cts.verifier.nfc.hce;
 
 import android.annotation.TargetApi;
-import android.app.AlertDialog;
 import android.content.ComponentName;
 import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
-import android.nfc.cardemulation.CardEmulation;
 import android.os.Bundle;
 
 import com.android.cts.verifier.R;
 import com.android.cts.verifier.nfc.NfcDialogs;
 
 @TargetApi(19)
-public class ChangeDefaultEmulatorActivity extends BaseEmulatorActivity implements OnClickListener {
+public class ChangeDefaultEmulatorActivity extends BaseEmulatorActivity {
     final static int STATE_IDLE = 0;
     final static int STATE_SERVICE1_SETTING_UP = 1;
     final static int STATE_SERVICE2_SETTING_UP = 2;
@@ -48,22 +44,14 @@
             setupServices(this, PaymentService1.COMPONENT, PaymentService2.COMPONENT);
             return;
         }
-        // Verify HCE service 2 is the default
-        if (!mCardEmulation.isDefaultServiceForCategory(
-                PaymentService2.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
-            mState = STATE_MAKING_SERVICE2_DEFAULT;
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle("Note");
-            builder.setMessage(R.string.nfc_hce_change_preinstalled_wallet);
-            builder.setPositiveButton("OK", this);
-            builder.show();
-        } else {
+        if (!makePaymentDefault(PaymentService2.COMPONENT,
+                R.string.nfc_hce_change_preinstalled_wallet)) {
+            // Service 2 is already default, make one default now
             mState = STATE_MAKING_SERVICE1_DEFAULT;
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle("Note");
-            builder.setMessage(R.string.nfc_hce_change_default_help);
-            builder.setPositiveButton("OK", this);
-            builder.show();
+            makePaymentDefault(PaymentService1.COMPONENT, R.string.nfc_hce_change_default_help);
+        } else {
+            mState = STATE_MAKING_SERVICE2_DEFAULT;
+            // will get callback when 2 is made default
         }
     }
 
@@ -94,57 +82,17 @@
     }
 
     @Override
-    public void onClick(DialogInterface dialog, int which) {
-        if (mState == STATE_MAKING_SERVICE1_DEFAULT) {
-            Intent changeDefault = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
-            changeDefault.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
-            changeDefault.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, PaymentService1.COMPONENT);
-            startActivityForResult(changeDefault, 0);
-        } else if (mState == STATE_MAKING_SERVICE2_DEFAULT) {
-            Intent changeDefault = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
-            changeDefault.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
-            changeDefault.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, PaymentService2.COMPONENT);
-            startActivityForResult(changeDefault, 0);
-        }
-    }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-        if (mState == STATE_MAKING_SERVICE1_DEFAULT) {
-            if (!mCardEmulation.isDefaultServiceForCategory(
-                    PaymentService1.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
-                // Popup dialog-box, fail test
-                AlertDialog.Builder builder = new AlertDialog.Builder(this);
-                builder.setTitle("Test failed.");
-                builder.setMessage("PaymentService1 is not the default service according " +
-                        "to CardEmulation.getDefaultServiceForCategory(), verify the make " +
-                        "default implementation is correct.");
-                builder.setPositiveButton("OK", null);
-                builder.show();
-            } else {
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (mState == STATE_MAKING_SERVICE2_DEFAULT) {
+            if (success) {
+                mState = STATE_MAKING_SERVICE1_DEFAULT;
+	            makePaymentDefault(PaymentService1.COMPONENT, R.string.nfc_hce_change_default_help);
+            }
+        } else if (mState == STATE_MAKING_SERVICE1_DEFAULT) {
+            if (success) {
                 mState = STATE_DEFAULT_CHANGED;
                 NfcDialogs.createHceTapReaderDialog(this, null).show();
             }
-        } else if (mState == STATE_MAKING_SERVICE2_DEFAULT) {
-            if (!mCardEmulation.isDefaultServiceForCategory(
-                    PaymentService2.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
-                // Popup dialog-box, fail test
-                AlertDialog.Builder builder = new AlertDialog.Builder(this);
-                builder.setTitle("Test failed.");
-                builder.setMessage("PaymentService2 is not the default service according " +
-                        "to CardEmulation.getDefaultServiceForCategory(), verify the make " +
-                        "default implementation is correct.");
-                builder.setPositiveButton("OK", null);
-                builder.show();
-            } else {
-                mState = STATE_MAKING_SERVICE1_DEFAULT;
-                AlertDialog.Builder builder = new AlertDialog.Builder(this);
-                builder.setTitle("Note");
-                builder.setMessage(R.string.nfc_hce_change_default_help);
-                builder.setPositiveButton("OK", this);
-                builder.show();
-            }
         }
     }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/CommandApdu.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/CommandApdu.java
new file mode 100644
index 0000000..3039efdc
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/CommandApdu.java
@@ -0,0 +1,49 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class CommandApdu implements Parcelable {
+    private String mApdu;
+    private boolean mReachable;
+
+    public CommandApdu(String apdu, boolean reachable) {
+        mApdu = apdu;
+        mReachable = reachable;
+    }
+
+    public boolean isReachable() {
+        return mReachable;
+    }
+
+    public String getApdu() {
+        return mApdu;
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    public static final Parcelable.Creator<CommandApdu> CREATOR =
+            new Parcelable.Creator<CommandApdu>() {
+        @Override
+        public CommandApdu createFromParcel(Parcel source) {
+            String apdu = source.readString();
+            boolean reachable = source.readInt() != 0 ? true : false;
+            return new CommandApdu(apdu, reachable);
+        }
+
+        @Override
+        public CommandApdu[] newArray(int size) {
+            return new CommandApdu[size];
+        }
+    };
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeString(mApdu);
+        dest.writeInt(mReachable ? 1 : 0);
+    }
+
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ConflictingNonPaymentPrefixEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ConflictingNonPaymentPrefixEmulatorActivity.java
new file mode 100644
index 0000000..3b0313a
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ConflictingNonPaymentPrefixEmulatorActivity.java
@@ -0,0 +1,54 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.nfc.cardemulation.CardEmulation;
+import android.os.Bundle;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+import java.util.ArrayList;
+
+public class ConflictingNonPaymentPrefixEmulatorActivity extends BaseEmulatorActivity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pass_fail_text);
+        setPassFailButtonClickListeners();
+        getPassButton().setEnabled(false);
+        setupServices(this, PrefixTransportService1.COMPONENT, PrefixTransportService2.COMPONENT);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    void onServicesSetup(boolean result) {
+        // Do dynamic AID registration
+        ArrayList<String> service_aids = new ArrayList<String>();
+        service_aids.add(HceUtils.TRANSPORT_PREFIX_AID + "*");
+        mCardEmulation.registerAidsForService(PrefixTransportService1.COMPONENT, CardEmulation.CATEGORY_OTHER, service_aids);
+        mCardEmulation.registerAidsForService(PrefixTransportService2.COMPONENT, CardEmulation.CATEGORY_OTHER, service_aids);
+        NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_other_conflicting_prefix_aids_help)).show();
+    }
+
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS, PrefixTransportService2.APDU_COMMAND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES, PrefixTransportService2.APDU_RESPOND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_other_conflicting_prefix_aids_reader));
+        return readerIntent;
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(PrefixTransportService2.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DefaultRouteEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DefaultRouteEmulatorActivity.java
index 2de99e7..fbf07e7 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DefaultRouteEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DefaultRouteEmulatorActivity.java
@@ -9,8 +9,8 @@
 import com.android.cts.verifier.nfc.NfcDialogs;
 
 public class DefaultRouteEmulatorActivity extends BaseEmulatorActivity {
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu("A000000476416E64726F6964484345"),
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu("A000000476416E64726F6964484345", true),
     };
     public static final String[] APDU_RESPONSE_SEQUENCE = {
         "148100009000"
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentEmulatorActivity.java
index 27b063c..0a9362a 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentEmulatorActivity.java
@@ -31,7 +31,7 @@
     public static Intent buildReaderIntent(Context context) {
         Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
         // Combine command/response APDU arrays
-        String[] commandSequences = new String[TransportService2.APDU_COMMAND_SEQUENCE.length +
+        CommandApdu[] commandSequences = new CommandApdu[TransportService2.APDU_COMMAND_SEQUENCE.length +
                                                AccessService.APDU_COMMAND_SEQUENCE.length];
         System.arraycopy(TransportService2.APDU_COMMAND_SEQUENCE, 0, commandSequences, 0,
                 TransportService2.APDU_COMMAND_SEQUENCE.length);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentPrefixEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentPrefixEmulatorActivity.java
new file mode 100644
index 0000000..c02faca
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualNonPaymentPrefixEmulatorActivity.java
@@ -0,0 +1,73 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.nfc.cardemulation.CardEmulation;
+import android.os.Bundle;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+import java.util.ArrayList;
+
+public class DualNonPaymentPrefixEmulatorActivity extends BaseEmulatorActivity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pass_fail_text);
+        setPassFailButtonClickListeners();
+        getPassButton().setEnabled(false);
+        setupServices(this, PrefixTransportService1.COMPONENT, PrefixAccessService.COMPONENT);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    void onServicesSetup(boolean result) {
+        // Do dynamic AID registration
+        ArrayList<String> service1_aids = new ArrayList<String>();
+        service1_aids.add(HceUtils.TRANSPORT_PREFIX_AID + "*");
+        ArrayList<String> service2_aids = new ArrayList<String>();
+        service2_aids.add(HceUtils.ACCESS_PREFIX_AID + "*");
+        mCardEmulation.registerAidsForService(PrefixTransportService1.COMPONENT, CardEmulation.CATEGORY_OTHER, service1_aids);
+        mCardEmulation.registerAidsForService(PrefixAccessService.COMPONENT, CardEmulation.CATEGORY_OTHER, service2_aids);
+        NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_other_prefix_aids_help)).show();
+    }
+
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        // Combine command/response APDU arrays
+        CommandApdu[] commandSequences = new CommandApdu[PrefixTransportService1.APDU_COMMAND_SEQUENCE.length +
+                PrefixAccessService.APDU_COMMAND_SEQUENCE.length];
+        System.arraycopy(PrefixTransportService1.APDU_COMMAND_SEQUENCE, 0, commandSequences, 0,
+                PrefixTransportService1.APDU_COMMAND_SEQUENCE.length);
+        System.arraycopy(PrefixAccessService.APDU_COMMAND_SEQUENCE, 0, commandSequences,
+                PrefixTransportService1.APDU_COMMAND_SEQUENCE.length,
+                PrefixAccessService.APDU_COMMAND_SEQUENCE.length);
+
+        String[] responseSequences = new String[PrefixTransportService1.APDU_RESPOND_SEQUENCE.length +
+                PrefixAccessService.APDU_RESPOND_SEQUENCE.length];
+        System.arraycopy(PrefixTransportService1.APDU_RESPOND_SEQUENCE, 0, responseSequences, 0,
+                PrefixTransportService1.APDU_RESPOND_SEQUENCE.length);
+        System.arraycopy(PrefixAccessService.APDU_RESPOND_SEQUENCE, 0, responseSequences,
+                PrefixTransportService1.APDU_RESPOND_SEQUENCE.length,
+                PrefixAccessService.APDU_RESPOND_SEQUENCE.length);
+
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS, commandSequences);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES, responseSequences);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_other_prefix_aids_reader));
+        return readerIntent;
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(PrefixAccessService.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualPaymentEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualPaymentEmulatorActivity.java
index 125045f..2e72e09 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualPaymentEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DualPaymentEmulatorActivity.java
@@ -1,11 +1,8 @@
 package com.android.cts.verifier.nfc.hce;
 
 import android.annotation.TargetApi;
-import android.app.AlertDialog;
 import android.content.ComponentName;
 import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
 import android.nfc.cardemulation.CardEmulation;
 import android.os.Bundle;
@@ -14,7 +11,7 @@
 import com.android.cts.verifier.nfc.NfcDialogs;
 
 @TargetApi(19)
-public class DualPaymentEmulatorActivity extends BaseEmulatorActivity implements OnClickListener {
+public class DualPaymentEmulatorActivity extends BaseEmulatorActivity {
     final static int STATE_IDLE = 0;
     final static int STATE_SERVICE1_SETTING_UP = 1;
     final static int STATE_SERVICE2_SETTING_UP = 2;
@@ -46,43 +43,28 @@
             return;
         }
         // Verify HCE service 2 is the default
-        if (!mCardEmulation.isDefaultServiceForCategory(
-                PaymentService2.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
+        if (makePaymentDefault(PaymentService2.COMPONENT, R.string.nfc_hce_change_preinstalled_wallet)) {
             mState = STATE_MAKING_SERVICE2_DEFAULT;
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle("Note");
-            builder.setMessage(R.string.nfc_hce_change_preinstalled_wallet);
-            builder.setPositiveButton("OK", this);
-            builder.show();
         } else {
+            // Already default
             NfcDialogs.createHceTapReaderDialog(this,null).show();
         }
     }
 
     @Override
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (success) {
+            NfcDialogs.createHceTapReaderDialog(this, null).show();
+        }
+    }
+
+    @Override
     protected void onPause() {
         super.onPause();
         if (mReceiverRegistered) {
             unregisterReceiver(mReceiver);
         }
     }
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-        if (!mCardEmulation.isDefaultServiceForCategory(
-                PaymentService2.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
-            // Popup dialog-box, fail test
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle("Test failed.");
-            builder.setMessage("PaymentService2 is not the default service according " +
-                    "to CardEmulation.getDefaultServiceForCategory(), verify the make " +
-                    "default implementation is correct.");
-            builder.setPositiveButton("OK", null);
-            builder.show();
-        } else {
-            NfcDialogs.createHceTapReaderDialog(this, null).show();
-        }
-    }
     public static Intent buildReaderIntent(Context context) {
         Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
         readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
@@ -100,12 +82,4 @@
             getPassButton().setEnabled(true);
         }
     }
-
-    @Override
-    public void onClick(DialogInterface dialog, int which) {
-        Intent changeDefault = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
-        changeDefault.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
-        changeDefault.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, PaymentService2.COMPONENT);
-        startActivityForResult(changeDefault, 0);
-    }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DynamicAidEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DynamicAidEmulatorActivity.java
new file mode 100644
index 0000000..ae8d50c
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/DynamicAidEmulatorActivity.java
@@ -0,0 +1,73 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.nfc.cardemulation.CardEmulation;
+import android.os.Bundle;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+import java.util.ArrayList;
+
+public class DynamicAidEmulatorActivity extends BaseEmulatorActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+       super.onCreate(savedInstanceState);
+       setContentView(R.layout.pass_fail_text);
+       setPassFailButtonClickListeners();
+       getPassButton().setEnabled(false);
+       setupServices(this, PaymentServiceDynamicAids.COMPONENT);
+    }
+
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+
+    @Override
+    void onServicesSetup(boolean result) {
+        ArrayList<String> paymentAids = new ArrayList<String>();
+        paymentAids.add(HceUtils.PPSE_AID);
+        paymentAids.add(HceUtils.VISA_AID);
+        // Register a different set of AIDs for the foreground
+        mCardEmulation.registerAidsForService(PaymentServiceDynamicAids.COMPONENT,
+                CardEmulation.CATEGORY_PAYMENT, paymentAids);
+        // Now make sure it's default
+        if (makePaymentDefault(PaymentServiceDynamicAids.COMPONENT,
+                R.string.nfc_hce_change_preinstalled_wallet)) {
+            // Wait for callback
+        } else {
+	        NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_payment_dynamic_aids_help)).show();
+        }
+    }
+
+    @Override
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (success) {
+	        NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_payment_dynamic_aids_help)).show();
+        }
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(PaymentServiceDynamicAids.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
+                PaymentServiceDynamicAids.APDU_COMMAND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
+                PaymentServiceDynamicAids.APDU_RESPOND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_payment_dynamic_aids_reader));
+        return readerIntent;
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ForegroundNonPaymentEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ForegroundNonPaymentEmulatorActivity.java
new file mode 100644
index 0000000..e8bf5f1
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ForegroundNonPaymentEmulatorActivity.java
@@ -0,0 +1,58 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+public class ForegroundNonPaymentEmulatorActivity extends BaseEmulatorActivity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pass_fail_text);
+        setPassFailButtonClickListeners();
+        getPassButton().setEnabled(false);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        setupServices(this, TransportService1.COMPONENT, TransportService2.COMPONENT);
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        mCardEmulation.unsetPreferredService(this);
+    }
+
+    @Override
+    void onServicesSetup(boolean result) {
+        // Tell NFC service we prefer TransportService2
+        mCardEmulation.setPreferredService(this, TransportService2.COMPONENT);
+        NfcDialogs.createHceTapReaderDialog(this,
+                getString(R.string.nfc_hce_foreground_non_payment_help)).show();
+    }
+
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
+                TransportService2.APDU_COMMAND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
+                TransportService2.APDU_RESPOND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_foreground_non_payment_reader));
+        return readerIntent;
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(TransportService2.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ForegroundPaymentEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ForegroundPaymentEmulatorActivity.java
new file mode 100644
index 0000000..27cb061
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ForegroundPaymentEmulatorActivity.java
@@ -0,0 +1,75 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.annotation.TargetApi;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.nfc.cardemulation.CardEmulation;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+@TargetApi(19)
+public class ForegroundPaymentEmulatorActivity extends BaseEmulatorActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pass_fail_text);
+        setPassFailButtonClickListeners();
+        getPassButton().setEnabled(false);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        if (!mCardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT)) {
+            // Launch tap&pay settings
+            NfcDialogs.createChangeForegroundDialog(this).show();
+        } else {
+            setupServices(this, PaymentService2.COMPONENT, PaymentService1.COMPONENT);
+        }
+    }
+
+    @Override
+    void onServicesSetup(boolean result) {
+        if (!makePaymentDefault(PaymentService1.COMPONENT,
+                R.string.nfc_hce_change_preinstalled_wallet)) {
+            mCardEmulation.setPreferredService(this, PaymentService2.COMPONENT);
+            NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_foreground_payment_help)).show();
+        } // else, wait for callback
+    }
+
+    @Override
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (success) {
+            NfcDialogs.createHceTapReaderDialog(this, null).show();
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        mCardEmulation.unsetPreferredService(this);
+    }
+
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
+                PaymentService2.APDU_COMMAND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
+                PaymentService2.APDU_RESPOND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_foreground_payment_reader));
+        return readerIntent;
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(PaymentService2.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceEmulatorTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceEmulatorTestActivity.java
index e85d387..3029796 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceEmulatorTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceEmulatorTestActivity.java
@@ -23,6 +23,9 @@
 
 import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.nfc.NfcAdapter;
+import android.nfc.cardemulation.CardEmulation;
+import android.os.Build;
 import android.os.Bundle;
 
 /** Activity that lists all the NFC HCE emulator tests. */
@@ -37,6 +40,8 @@
 
         ArrayTestListAdapter adapter = new ArrayTestListAdapter(this);
 
+        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
+        CardEmulation cardEmulation = CardEmulation.getInstance(nfcAdapter);
         if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
             adapter.add(TestListItem.newCategory(this, R.string.nfc_hce_emulator_tests));
 
@@ -62,6 +67,9 @@
                     ChangeDefaultEmulatorActivity.class.getName(),
                     new Intent(this, ChangeDefaultEmulatorActivity.class), null));
 
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_foreground_payment_emulator,
+                    ForegroundPaymentEmulatorActivity.class.getName(),
+                    new Intent(this, ForegroundPaymentEmulatorActivity.class), null));
 
             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_single_non_payment_emulator,
                     SingleNonPaymentEmulatorActivity.class.getName(),
@@ -75,6 +83,10 @@
                     ConflictingNonPaymentEmulatorActivity.class.getName(),
                     new Intent(this, ConflictingNonPaymentEmulatorActivity.class), null));
 
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_foreground_non_payment_emulator,
+                    ForegroundNonPaymentEmulatorActivity.class.getName(),
+                    new Intent(this, ForegroundNonPaymentEmulatorActivity.class), null));
+
             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_throughput_emulator,
                     ThroughputEmulatorActivity.class.getName(),
                     new Intent(this, ThroughputEmulatorActivity.class), null));
@@ -91,6 +103,29 @@
                     OnAndOffHostEmulatorActivity.class.getName(),
                     new Intent(this, OnAndOffHostEmulatorActivity.class), null));
 
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L) {
+                adapter.add(TestListItem.newTest(this, R.string.nfc_hce_payment_dynamic_aids_emulator,
+                        DynamicAidEmulatorActivity.class.getName(),
+                        new Intent(this, DynamicAidEmulatorActivity.class), null));
+
+                if (cardEmulation.supportsAidPrefixRegistration()) {
+                    adapter.add(TestListItem.newTest(this, R.string.nfc_hce_payment_prefix_aids_emulator,
+                            PrefixPaymentEmulatorActivity.class.getName(),
+                            new Intent(this, PrefixPaymentEmulatorActivity.class), null));
+
+                    adapter.add(TestListItem.newTest(this, R.string.nfc_hce_payment_prefix_aids_emulator_2,
+                            PrefixPaymentEmulator2Activity.class.getName(),
+                            new Intent(this, PrefixPaymentEmulator2Activity.class), null));
+
+                    adapter.add(TestListItem.newTest(this, R.string.nfc_hce_other_prefix_aids_emulator,
+                            DualNonPaymentPrefixEmulatorActivity.class.getName(),
+                            new Intent(this, DualNonPaymentPrefixEmulatorActivity.class), null));
+
+                    adapter.add(TestListItem.newTest(this, R.string.nfc_hce_other_conflicting_prefix_aids_emulator,
+                            ConflictingNonPaymentPrefixEmulatorActivity.class.getName(),
+                            new Intent(this, ConflictingNonPaymentPrefixEmulatorActivity.class), null));
+                }
+            }
         }
 
         setTestListAdapter(adapter);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceReaderTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceReaderTestActivity.java
index 704cc89..f628fb7 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceReaderTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceReaderTestActivity.java
@@ -61,6 +61,10 @@
                     SimpleReaderActivity.class.getName(),
                     ChangeDefaultEmulatorActivity.buildReaderIntent(this), null));
 
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_foreground_payment_reader,
+                    SimpleReaderActivity.class.getName(),
+                    ForegroundPaymentEmulatorActivity.buildReaderIntent(this), null));
+
             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_single_non_payment_reader,
                     SimpleReaderActivity.class.getName(),
                     SingleNonPaymentEmulatorActivity.buildReaderIntent(this), null));
@@ -73,6 +77,10 @@
                     SimpleReaderActivity.class.getName(),
                     ConflictingNonPaymentEmulatorActivity.buildReaderIntent(this), null));
 
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_foreground_non_payment_reader,
+                    SimpleReaderActivity.class.getName(),
+                    ForegroundNonPaymentEmulatorActivity.buildReaderIntent(this), null));
+
             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_throughput_reader,
                     SimpleReaderActivity.class.getName(),
                     ThroughputEmulatorActivity.buildReaderIntent(this), null));
@@ -88,6 +96,26 @@
             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_on_and_offhost_service_reader,
                     SimpleReaderActivity.class.getName(),
                     OnAndOffHostEmulatorActivity.buildReaderIntent(this), null));
+
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_payment_dynamic_aids_reader,
+                    SimpleReaderActivity.class.getName(),
+                    DynamicAidEmulatorActivity.buildReaderIntent(this), null));
+
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_payment_prefix_aids_reader,
+                    SimpleReaderActivity.class.getName(),
+                    PrefixPaymentEmulatorActivity.buildReaderIntent(this), null));
+
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_payment_prefix_aids_reader_2,
+                    SimpleReaderActivity.class.getName(),
+                    PrefixPaymentEmulator2Activity.buildReaderIntent(this), null));
+
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_other_prefix_aids_reader,
+                    SimpleReaderActivity.class.getName(),
+                    DualNonPaymentPrefixEmulatorActivity.buildReaderIntent(this), null));
+
+            adapter.add(TestListItem.newTest(this, R.string.nfc_hce_other_conflicting_prefix_aids_reader,
+                    SimpleReaderActivity.class.getName(),
+                    ConflictingNonPaymentPrefixEmulatorActivity.buildReaderIntent(this), null));
         }
 
         setTestListAdapter(adapter);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceService.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceService.java
index 20b34df..e9cd121 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceService.java
@@ -18,13 +18,13 @@
     final static int STATE_FAILED = 2;
 
     // Variables below only used on main thread
-    String[] mCommandApdus = null;
+    CommandApdu[] mCommandApdus = null;
     String[] mResponseApdus = null;
     int mApduIndex = 0;
     int mState = STATE_IDLE;
     long mStartTime;
 
-    public void initialize(String[] commandApdus, String[] responseApdus) {
+    public void initialize(CommandApdu[] commandApdus, String[] responseApdus) {
        mCommandApdus = commandApdus;
        mResponseApdus = responseApdus;
     }
@@ -62,12 +62,27 @@
             mStartTime = System.currentTimeMillis();
         }
 
+
+        if (mApduIndex >= mCommandApdus.length) {
+	        // Skip all APDUs which aren't supposed to reach us
+            return null;
+        }
+
+        do {
+            if (!mCommandApdus[mApduIndex].isReachable()) {
+                mApduIndex++;
+            } else {
+                break;
+            }
+        } while (mApduIndex < mCommandApdus.length);
+
         if (mApduIndex >= mCommandApdus.length) {
             Log.d(TAG, "Ignoring command APDU; protocol complete.");
             // Ignore new APDUs after completion
             return null;
         } else {
-            if (!Arrays.equals(HceUtils.hexStringToBytes(mCommandApdus[mApduIndex]), arg0)) {
+
+            if (!Arrays.equals(HceUtils.hexStringToBytes(mCommandApdus[mApduIndex].getApdu()), arg0)) {
                 Log.d(TAG, "Unexpected command APDU: " + HceUtils.getHexBytes("", arg0));
                 onApduSequenceError();
                 return null;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceUtils.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceUtils.java
index 3bab53b..c67169a 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceUtils.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/HceUtils.java
@@ -14,10 +14,14 @@
 
     public static final String PPSE_AID = "325041592E5359532E4444463031";
     public static final String MC_AID = "A0000000041010";
+    public static final String VISA_AID = "A0000000030000";
 
     public static final String TRANSPORT_AID = "F001020304";
     public static final String ACCESS_AID = "F005060708";
 
+    public static final String TRANSPORT_PREFIX_AID = "F001020304";
+    public static final String ACCESS_PREFIX_AID = "F005060708";
+
     public static void enableComponent(PackageManager pm, ComponentName component) {
         pm.setComponentEnabledSetting(
                 component,
@@ -58,11 +62,15 @@
         return data;
     }
 
-    public static final String buildSelectApdu(String aid) {
+    public static final CommandApdu buildCommandApdu(String apdu, boolean reachable) {
+        return new CommandApdu(apdu, reachable);
+    }
+
+    public static final CommandApdu buildSelectApdu(String aid, boolean reachable) {
         StringBuilder sb = new StringBuilder();
         sb.append("00A40400");
         sb.append(String.format("%02X", aid.length() / 2));
         sb.append(aid);
-        return sb.toString();
+        return new CommandApdu(sb.toString(), reachable);
     }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OffHostService.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OffHostService.java
index c087c99..d8cdf19 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OffHostService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OffHostService.java
@@ -7,11 +7,11 @@
             new ComponentName("com.android.cts.verifier",
                     OffHostService.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu("A000000151000000"),
-        "80CA9F7F00",
-        HceUtils.buildSelectApdu("A000000003000000"),
-        "80CA9F7F00"
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu("A000000151000000", true),
+        HceUtils.buildCommandApdu("80CA9F7F00", true),
+        HceUtils.buildSelectApdu("A000000003000000", true),
+        HceUtils.buildCommandApdu("80CA9F7F00", true)
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OnAndOffHostEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OnAndOffHostEmulatorActivity.java
index 3d5190f..d599959 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OnAndOffHostEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/OnAndOffHostEmulatorActivity.java
@@ -6,8 +6,8 @@
 import android.content.Intent;
 import android.os.Bundle;
 
-import com.android.cts.verifier.R;
 import com.android.cts.verifier.nfc.NfcDialogs;
+import com.android.cts.verifier.R;
 
 @TargetApi(19)
 public class OnAndOffHostEmulatorActivity extends BaseEmulatorActivity {
@@ -32,7 +32,7 @@
 
     public static Intent buildReaderIntent(Context context) {
         // Combine command/response APDU arrays
-        String[] commandSequences = new String[OffHostService.APDU_COMMAND_SEQUENCE.length +
+        CommandApdu[] commandSequences = new CommandApdu[OffHostService.APDU_COMMAND_SEQUENCE.length +
                                                AccessService.APDU_COMMAND_SEQUENCE.length];
         System.arraycopy(OffHostService.APDU_COMMAND_SEQUENCE, 0, commandSequences, 0,
                 OffHostService.APDU_COMMAND_SEQUENCE.length);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService1.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService1.java
index f6119eb..80df0cb 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService1.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService1.java
@@ -9,10 +9,10 @@
             new ComponentName("com.android.cts.verifier",
             PaymentService1.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu(HceUtils.PPSE_AID),
-        HceUtils.buildSelectApdu(HceUtils.MC_AID),
-        "80CA01F000"
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.PPSE_AID, true),
+        HceUtils.buildSelectApdu(HceUtils.MC_AID, true),
+        HceUtils.buildCommandApdu("80CA01F000", true)
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService2.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService2.java
index 23664b9..f2c4835 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService2.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentService2.java
@@ -7,9 +7,9 @@
             new ComponentName("com.android.cts.verifier",
             PaymentService2.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu(HceUtils.PPSE_AID),
-        HceUtils.buildSelectApdu(HceUtils.MC_AID)
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.PPSE_AID, true),
+        HceUtils.buildSelectApdu(HceUtils.MC_AID, true)
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentServiceDynamicAids.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentServiceDynamicAids.java
new file mode 100644
index 0000000..047a667
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PaymentServiceDynamicAids.java
@@ -0,0 +1,32 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+
+public class PaymentServiceDynamicAids extends HceService {
+    static final String TAG = "PaymentService1";
+
+    static final ComponentName COMPONENT =
+            new ComponentName("com.android.cts.verifier",
+            PaymentServiceDynamicAids.class.getName());
+
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.PPSE_AID, true),
+        HceUtils.buildSelectApdu(HceUtils.VISA_AID, true),
+        HceUtils.buildCommandApdu("80CA01F000", true)
+    };
+
+    public static final String[] APDU_RESPOND_SEQUENCE = {
+        "FFFF9000",
+        "FF0F9000",
+        "FFDFFFAACB9000"
+    };
+
+    public PaymentServiceDynamicAids() {
+        initialize(APDU_COMMAND_SEQUENCE, APDU_RESPOND_SEQUENCE);
+    }
+
+    @Override
+    public ComponentName getComponent() {
+        return COMPONENT;
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixAccessService.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixAccessService.java
new file mode 100644
index 0000000..8cecb56
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixAccessService.java
@@ -0,0 +1,34 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+
+public class PrefixAccessService extends HceService {
+    static final String TAG = "PrefixAccessService";
+
+    static final ComponentName COMPONENT =
+            new ComponentName("com.android.cts.verifier",
+            PrefixAccessService.class.getName());
+
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.ACCESS_PREFIX_AID + "FFFF", true),
+        HceUtils.buildSelectApdu(HceUtils.ACCESS_PREFIX_AID + "FFAA", true),
+        HceUtils.buildSelectApdu(HceUtils.ACCESS_PREFIX_AID + "FFAABBCCDDEEFF", true),
+        HceUtils.buildCommandApdu("80CA010000010203", true)
+    };
+
+    public static final String[] APDU_RESPOND_SEQUENCE = {
+        "FAFE9000",
+        "FAFE25929000",
+        "FAFEAABB25929000",
+        "FAFEFFAACC25929000"
+    };
+
+    public PrefixAccessService() {
+        initialize(APDU_COMMAND_SEQUENCE, APDU_RESPOND_SEQUENCE);
+    }
+
+    @Override
+    public ComponentName getComponent() {
+        return COMPONENT;
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentEmulator2Activity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentEmulator2Activity.java
new file mode 100644
index 0000000..5ed6fe9
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentEmulator2Activity.java
@@ -0,0 +1,84 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.annotation.TargetApi;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+@TargetApi(19)
+public class PrefixPaymentEmulator2Activity extends BaseEmulatorActivity {
+    final static int STATE_IDLE = 0;
+    final static int STATE_SERVICE1_SETTING_UP = 1;
+    final static int STATE_SERVICE2_SETTING_UP = 2;
+    final static int STATE_MAKING_SERVICE2_DEFAULT = 3;
+
+    boolean mReceiverRegistered = false;
+    int mState = STATE_IDLE;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pass_fail_text);
+        setPassFailButtonClickListeners();
+        getPassButton().setEnabled(false);
+        mState = STATE_SERVICE2_SETTING_UP;
+        setupServices(this, PrefixPaymentService2.COMPONENT);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    void onServicesSetup(boolean result) {
+        if (mState == STATE_SERVICE2_SETTING_UP) {
+            mState = STATE_SERVICE1_SETTING_UP;
+            setupServices(this, PrefixPaymentService1.COMPONENT, PrefixPaymentService2.COMPONENT);
+            return;
+        }
+        // Verify HCE service 2 is the default
+        if (makePaymentDefault(PrefixPaymentService2.COMPONENT, R.string.nfc_hce_change_preinstalled_wallet)) {
+            mState = STATE_MAKING_SERVICE2_DEFAULT;
+        } else {
+            // Already default
+            NfcDialogs.createHceTapReaderDialog(this,getString(R.string.nfc_hce_payment_prefix_aids_help)).show();
+        }
+    }
+
+    @Override
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (success) {
+            NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_payment_prefix_aids_help)).show();
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        if (mReceiverRegistered) {
+            unregisterReceiver(mReceiver);
+        }
+    }
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
+                PrefixPaymentService2.APDU_COMMAND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
+                PrefixPaymentService2.APDU_RESPOND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_payment_prefix_aids_reader_2));
+        return readerIntent;
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(PrefixPaymentService2.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentEmulatorActivity.java
new file mode 100644
index 0000000..d3a4189
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentEmulatorActivity.java
@@ -0,0 +1,84 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.annotation.TargetApi;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.NfcDialogs;
+
+@TargetApi(19)
+public class PrefixPaymentEmulatorActivity extends BaseEmulatorActivity {
+    final static int STATE_IDLE = 0;
+    final static int STATE_SERVICE1_SETTING_UP = 1;
+    final static int STATE_SERVICE2_SETTING_UP = 2;
+    final static int STATE_MAKING_SERVICE1_DEFAULT = 3;
+
+    boolean mReceiverRegistered = false;
+    int mState = STATE_IDLE;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pass_fail_text);
+        setPassFailButtonClickListeners();
+        getPassButton().setEnabled(false);
+        mState = STATE_SERVICE1_SETTING_UP;
+        setupServices(this, PrefixPaymentService1.COMPONENT);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    void onServicesSetup(boolean result) {
+        if (mState == STATE_SERVICE1_SETTING_UP) {
+            mState = STATE_SERVICE2_SETTING_UP;
+            setupServices(this, PrefixPaymentService1.COMPONENT, PrefixPaymentService2.COMPONENT);
+            return;
+        }
+        // Verify HCE service 1 is the default
+        if (makePaymentDefault(PrefixPaymentService1.COMPONENT, R.string.nfc_hce_change_preinstalled_wallet)) {
+            mState = STATE_MAKING_SERVICE1_DEFAULT;
+        } else {
+            // Already default
+            NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_payment_prefix_aids_help)).show();
+        }
+    }
+
+    @Override
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (success) {
+            NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_payment_prefix_aids_help)).show();
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        if (mReceiverRegistered) {
+            unregisterReceiver(mReceiver);
+        }
+    }
+    public static Intent buildReaderIntent(Context context) {
+        Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
+                PrefixPaymentService1.APDU_COMMAND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
+                PrefixPaymentService1.APDU_RESPOND_SEQUENCE);
+        readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
+                context.getString(R.string.nfc_hce_payment_prefix_aids_reader));
+        return readerIntent;
+    }
+
+    @Override
+    void onApduSequenceComplete(ComponentName component, long duration) {
+        if (component.equals(PrefixPaymentService1.COMPONENT)) {
+            getPassButton().setEnabled(true);
+        }
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentService1.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentService1.java
new file mode 100644
index 0000000..be6acc2
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentService1.java
@@ -0,0 +1,32 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+
+public class PrefixPaymentService1 extends HceService {
+    static final String TAG = "PrefixPaymentService1";
+
+    static final ComponentName COMPONENT =
+            new ComponentName("com.android.cts.verifier",
+            PrefixPaymentService1.class.getName());
+
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.PPSE_AID, true),
+        HceUtils.buildSelectApdu(HceUtils.MC_AID, true),
+        HceUtils.buildCommandApdu("80CA01F000", true)
+    };
+
+    public static final String[] APDU_RESPOND_SEQUENCE = {
+        "F1239000",
+        "F4569000",
+        "F789FFAABB9000"
+    };
+
+    public PrefixPaymentService1() {
+        initialize(APDU_COMMAND_SEQUENCE, APDU_RESPOND_SEQUENCE);
+    }
+
+    @Override
+    public ComponentName getComponent() {
+        return COMPONENT;
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentService2.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentService2.java
new file mode 100644
index 0000000..9642025
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixPaymentService2.java
@@ -0,0 +1,36 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+
+public class PrefixPaymentService2 extends HceService {
+    static final String TAG = "PrefixPaymentService2";
+
+    static final ComponentName COMPONENT =
+            new ComponentName("com.android.cts.verifier",
+            PrefixPaymentService2.class.getName());
+
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.PPSE_AID, true),
+        HceUtils.buildSelectApdu(HceUtils.MC_AID, true),
+        HceUtils.buildCommandApdu("80CA02F000", true),
+        HceUtils.buildSelectApdu("F0000000FFFFFFFFFFFFFFFFFFFFFFFF", true),
+        HceUtils.buildSelectApdu("F000000000", true)
+    };
+
+    public static final String[] APDU_RESPOND_SEQUENCE = {
+        "FAAA9000",
+        "FBBB9000",
+        "F789FFCCDD9000",
+        "FFBAFEBECA",
+        "F0BABEFECA"
+    };
+
+    public PrefixPaymentService2() {
+        initialize(APDU_COMMAND_SEQUENCE, APDU_RESPOND_SEQUENCE);
+    }
+
+    @Override
+    public ComponentName getComponent() {
+        return COMPONENT;
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixTransportService1.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixTransportService1.java
new file mode 100644
index 0000000..5521440
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixTransportService1.java
@@ -0,0 +1,34 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+
+public class PrefixTransportService1 extends HceService {
+    static final String TAG = "PrefixTransportService1";
+
+    static final ComponentName COMPONENT =
+            new ComponentName("com.android.cts.verifier",
+            PrefixTransportService1.class.getName());
+
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_PREFIX_AID + "FFFF", true),
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_PREFIX_AID + "FFAA", true),
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_PREFIX_AID + "FFAABBCCDDEEFF", true),
+        HceUtils.buildCommandApdu("80CA01FFAA", true)
+    };
+
+    public static final String[] APDU_RESPOND_SEQUENCE = {
+        "25929000",
+        "FFEF25929000",
+        "FFDFFFAABB25929000",
+        "FFDFFFAACC25929000"
+    };
+
+    public PrefixTransportService1() {
+        initialize(APDU_COMMAND_SEQUENCE, APDU_RESPOND_SEQUENCE);
+    }
+
+    @Override
+    public ComponentName getComponent() {
+        return COMPONENT;
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixTransportService2.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixTransportService2.java
new file mode 100644
index 0000000..2235446
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/PrefixTransportService2.java
@@ -0,0 +1,34 @@
+package com.android.cts.verifier.nfc.hce;
+
+import android.content.ComponentName;
+
+public class PrefixTransportService2 extends HceService {
+    static final String TAG = "PrefixTransportService2";
+
+    static final ComponentName COMPONENT =
+            new ComponentName("com.android.cts.verifier",
+            PrefixTransportService2.class.getName());
+
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_PREFIX_AID + "FFFF", true),
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_PREFIX_AID + "FFAA", true),
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_PREFIX_AID + "FFAABBCCDDEEFF", true),
+        HceUtils.buildCommandApdu("80CA01FFBB", true)
+    };
+
+    public static final String[] APDU_RESPOND_SEQUENCE = {
+        "36039000",
+        "FFBB25929000",
+        "FFDFFFBBBB25929000",
+        "FFDFFFBBCC25929000"
+    };
+
+    public PrefixTransportService2() {
+        initialize(APDU_COMMAND_SEQUENCE, APDU_RESPOND_SEQUENCE);
+    }
+
+    @Override
+    public ComponentName getComponent() {
+        return COMPONENT;
+    }
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SimpleReaderActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SimpleReaderActivity.java
index 6c15811..638bc6f 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SimpleReaderActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SimpleReaderActivity.java
@@ -9,6 +9,7 @@
 import android.nfc.tech.IsoDep;
 import android.nfc.Tag;
 import android.os.Bundle;
+import android.os.Parcelable;
 import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
@@ -34,7 +35,7 @@
     public static final String EXTRA_LABEL = "label";
 
     NfcAdapter mAdapter;
-    String[] mApdus;
+    CommandApdu[] mApdus;
     String[] mResponses;
 
     TextView mTextView;
@@ -76,7 +77,15 @@
         mAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A |
                 NfcAdapter.FLAG_READER_NFC_BARCODE | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
         Intent intent = getIntent();
-        mApdus = intent.getStringArrayExtra(EXTRA_APDUS);
+        Parcelable[] apdus = intent.getParcelableArrayExtra(EXTRA_APDUS);
+        if (apdus != null) {
+	        mApdus = new CommandApdu[apdus.length];
+	        for (int i = 0; i < apdus.length; i++) {
+	            mApdus[i] = (CommandApdu) apdus[i];
+	        }
+        } else {
+            mApdus = null;
+        }
         mResponses = intent.getStringArrayExtra(EXTRA_RESPONSES);
     }
 
@@ -95,11 +104,11 @@
             int count = 0;
             boolean success = true;
             long startTime = System.currentTimeMillis();
-            for (String apdu: mApdus) {
+            for (CommandApdu apdu: mApdus) {
                 sb.append("Request APDU:\n");
-                sb.append(apdu + "\n\n");
+                sb.append(apdu.getApdu() + "\n\n");
                 long apduStartTime = System.currentTimeMillis();
-                byte[] response = isoDep.transceive(HceUtils.hexStringToBytes(apdu));
+                byte[] response = isoDep.transceive(HceUtils.hexStringToBytes(apdu.getApdu()));
                 long apduEndTime = System.currentTimeMillis();
                 sb.append("Response APDU (in " + Long.toString(apduEndTime - apduStartTime) +
                         " ms):\n");
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SinglePaymentEmulatorActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SinglePaymentEmulatorActivity.java
index 13b2fe8..0f1fba0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SinglePaymentEmulatorActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/SinglePaymentEmulatorActivity.java
@@ -1,19 +1,15 @@
 package com.android.cts.verifier.nfc.hce;
 
 import android.annotation.TargetApi;
-import android.app.AlertDialog;
 import android.content.ComponentName;
 import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
-import android.nfc.cardemulation.CardEmulation;
 import android.os.Bundle;
 import com.android.cts.verifier.R;
 import com.android.cts.verifier.nfc.NfcDialogs;
 
 @TargetApi(19)
-public class SinglePaymentEmulatorActivity extends BaseEmulatorActivity implements OnClickListener {
+public class SinglePaymentEmulatorActivity extends BaseEmulatorActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -31,18 +27,21 @@
     @Override
     void onServicesSetup(boolean result) {
         // Verify HCE service 1 is the default
-        if (!mCardEmulation.isDefaultServiceForCategory(
-                PaymentService1.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle("Note");
-            builder.setMessage(R.string.nfc_hce_change_preinstalled_wallet);
-            builder.setPositiveButton("OK", this);
-            builder.show();
+        if (makePaymentDefault(PaymentService1.COMPONENT,
+                R.string.nfc_hce_change_preinstalled_wallet)) {
+            // Wait for callback
         } else {
 	        NfcDialogs.createHceTapReaderDialog(this, null).show();
         }
     }
 
+    @Override
+    void onPaymentDefaultResult(ComponentName component, boolean success) {
+        if (success) {
+	        NfcDialogs.createHceTapReaderDialog(this, null).show();
+        }
+    }
+
     public static Intent buildReaderIntent(Context context) {
         Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
         readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
@@ -60,30 +59,4 @@
             getPassButton().setEnabled(true);
         }
     }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-        if (!mCardEmulation.isDefaultServiceForCategory(
-                PaymentService1.COMPONENT, CardEmulation.CATEGORY_PAYMENT)) {
-            // Popup dialog-box, fail test
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setTitle("Test failed.");
-            builder.setMessage("PaymentService1 is not the default service according " +
-                    "to CardEmulation.getDefaultServiceForCategory(), verify the make " +
-                    "default implementation is correct.");
-            builder.setPositiveButton("OK", null);
-            builder.show();
-        } else {
-            NfcDialogs.createHceTapReaderDialog(this, null).show();
-        }
-    }
-
-    @Override
-    public void onClick(DialogInterface dialog, int which) {
-        Intent changeDefault = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
-        changeDefault.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
-        changeDefault.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, PaymentService1.COMPONENT);
-        startActivityForResult(changeDefault, 0);
-    }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ThroughputService.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ThroughputService.java
index 8f826ff..b74f0b7 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ThroughputService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/ThroughputService.java
@@ -9,23 +9,23 @@
             new ComponentName("com.android.cts.verifier",
             ThroughputService.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu("F0010203040607FF"),
-        "80CA010000",
-        "80CA010100",
-        "80CA010200",
-        "80CA010300",
-        "80CA010400",
-        "80CA010500",
-        "80CA010600",
-        "80CA010700",
-        "80CA010800",
-        "80CA010900",
-        "80CA010A00",
-        "80CA010B00",
-        "80CA010C00",
-        "80CA010D00",
-        "80CA010E00",
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu("F0010203040607FF", true),
+        HceUtils.buildCommandApdu("80CA010100", true),
+        HceUtils.buildCommandApdu("80CA010200", true),
+        HceUtils.buildCommandApdu("80CA010300", true),
+        HceUtils.buildCommandApdu("80CA010400", true),
+        HceUtils.buildCommandApdu("80CA010500", true),
+        HceUtils.buildCommandApdu("80CA010600", true),
+        HceUtils.buildCommandApdu("80CA010700", true),
+        HceUtils.buildCommandApdu("80CA010800", true),
+        HceUtils.buildCommandApdu("80CA010900", true),
+        HceUtils.buildCommandApdu("80CA010A00", true),
+        HceUtils.buildCommandApdu("80CA010B00", true),
+        HceUtils.buildCommandApdu("80CA010C00", true),
+        HceUtils.buildCommandApdu("80CA010D00", true),
+        HceUtils.buildCommandApdu("80CA010E00", true),
+        HceUtils.buildCommandApdu("80CA010F00", true),
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService1.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService1.java
index c751e76..c8d8460 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService1.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService1.java
@@ -7,9 +7,9 @@
             new ComponentName("com.android.cts.verifier",
             TransportService1.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_AID),
-        "80CA01E000"
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_AID, true),
+        HceUtils.buildCommandApdu("80CA01E000", true)
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService2.java b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService2.java
index 0815b9c..322a076 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService2.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nfc/hce/TransportService2.java
@@ -7,9 +7,9 @@
             new ComponentName("com.android.cts.verifier",
             TransportService2.class.getName());
 
-    public static final String[] APDU_COMMAND_SEQUENCE = {
-        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_AID),
-        "80CA01E100"
+    public static final CommandApdu[] APDU_COMMAND_SEQUENCE = {
+        HceUtils.buildSelectApdu(HceUtils.TRANSPORT_AID, true),
+        HceUtils.buildCommandApdu("80CA01E100", true)
     };
 
     public static final String[] APDU_RESPOND_SEQUENCE = {