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

Commit c3178e5f authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Change XML-grammar for (Off)HostApduServices.

AIDs can now carry a category attribute. Clarified that
"OffHostApduService" is not bound to by Android, and may
be extended by offering service interfaces that are not
defined in the platform.

Change-Id: Idd0a3990beb927e8d81366013f53386fb46e3f9f
parent 434249ef
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ package android {
    field public static final int canRetrieveWindowContent = 16843653; // 0x1010385
    field public static final int candidatesTextStyleSpans = 16843312; // 0x1010230
    field public static final deprecated int capitalize = 16843113; // 0x1010169
    field public static final int category = 16843749; // 0x10103e5
    field public static final int centerBright = 16842956; // 0x10100cc
    field public static final int centerColor = 16843275; // 0x101020b
    field public static final int centerDark = 16842952; // 0x10100c8
@@ -793,7 +794,6 @@ package android {
    field public static final int path = 16842794; // 0x101002a
    field public static final int pathPattern = 16842796; // 0x101002c
    field public static final int pathPrefix = 16842795; // 0x101002b
    field public static final int paymentService = 16843749; // 0x10103e5
    field public static final int permission = 16842758; // 0x1010006
    field public static final int permissionFlags = 16843719; // 0x10103c7
    field public static final int permissionGroup = 16842762; // 0x101000a
@@ -14758,13 +14758,11 @@ package android.nfc.cardemulation {
    field public static final java.lang.String SERVICE_META_DATA = "android.nfc.HostApduService";
  }
  public abstract class SeApduService extends android.app.Service {
    ctor public SeApduService();
    method public abstract void onAidSelected(byte[]);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public abstract void onHciTransactionEvent(byte[], byte[]);
    field public static final java.lang.String SERVICE_INTERFACE = "android.nfc.SeApduService";
    field public static final java.lang.String SERVICE_META_DATA = "android.nfc.SeApduService";
  public abstract class OffHostApduService extends android.app.Service {
    ctor public OffHostApduService();
    method public abstract android.os.IBinder onBind(android.content.Intent);
    field public static final java.lang.String SERVICE_INTERFACE = "android.nfc.OffHostApduService";
    field public static final java.lang.String SERVICE_META_DATA = "android.nfc.OffHostApduService";
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import android.util.Log;
 *     <meta-data android:name="android.nfc.HostApduService" android:resource="@xml/apduservice.xml"/>
 * &lt;/service&gt;</pre>
 * <p>For more details refer to {@link #SERVICE_META_DATA},
 * <code>&lt;{@link android.R.styleable#ApduService apdu-service}&gt;</code> and
 * <code>&lt;{@link android.R.styleable#HostApduService host-apdu-service}&gt;</code> and
 * <code>&lt;{@link android.R.styleable#AidFilter aid-filter}&gt;</code>.
 * <p class="note">The Android platform currently only supports a single
 * logical channel.
+67 −0
Original line number Diff line number Diff line
package android.nfc.cardemulation;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

/**
 * <p>A convenience class that can be extended to implement
 * a service that registers ISO7814-4 AIDs that reside off-host,
 * for example on an embedded secure element or UICC.
 *
 * <p>This registration will allow the service to be included
 * as an option for handling these AIDs on non-host execution
 * environments. The Operating System will take care of correctly
 * routing the AIDs, based on which service the user has selected
 * to be the handler for an AID.
 *
 * <p>The service may define additional actions outside of the
 * Android namespace that provide further interaction with
 * the off-host execution environment.
 *
 * <p>To tell the platform which ISO7816 application ID (AIDs)
 * are present and handled by the app containing this service,
 * a {@link #SERVICE_META_DATA} entry must be included in the declaration
 * of the service. An example of such a service declaration is shown below:
 * <pre> &lt;service android:name=".MyOffHostApduService"&gt;
 *     &lt;intent-filter&gt;
 *         &lt;action android:name="android.nfc.OffHostApduService"/&gt;
 *     &lt;/intent-filter&gt;
 *     &lt;meta-data android:name="android.nfc.OffHostApduService" android:resource="@xml/apduservice.xml"/&gt;
 * &lt;/service&gt;</pre>
 * <p>For more details refer to {@link #SERVICE_META_DATA},
 * <code>&lt;{@link android.R.styleable#OffHostApduService offhost-apdu-service}&gt;</code> and
 * <code>&lt;{@link android.R.styleable#AidFilter aid-filter}&gt;</code>.
 */
public abstract class OffHostApduService extends Service {
    /**
     * The {@link Intent} that must be declared as handled by the service.
     */
    @SdkConstant(SdkConstantType.SERVICE_ACTION)
    public static final String SERVICE_INTERFACE =
            "android.nfc.OffHostApduService";

    /**
     * The name of the meta-data element that contains
     * more information about this service.
     */
    public static final String SERVICE_META_DATA = "android.nfc.OffHostApduService";

    /**
     * The Android platform itself will not bind to this service,
     * but merely uses its declaration to keep track of what AIDs
     * the service is interested in. This information is then used
     * to present the user with a list of applications that can handle
     * an AID, as well as correctly route those AIDs either to the host (in case
     * the user preferred a {@link HostApduService}), or to an off-host
     * execution environment (in case the user preferred a {@link OffHostApduService}.
     *
     * Implementers may define additional actions outside of the
     * Android namespace that allow further interactions with
     * the off-host execution environment. Such implementations
     * would need to override this method.
     */
    public abstract IBinder onBind(Intent intent);
}
 No newline at end of file
+0 −111
Original line number Diff line number Diff line
package android.nfc.cardemulation;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;

/**
 * <p>A convenience class that can be extended to implement
 * a service that registers and deals with events for
 * ISO7814-4 AIDs that reside on an embedded secure element
 * or UICC.
 *
 * <p>To tell the platform which ISO7816 application ID (AIDs)
 * are present on the Secure Element and handled by this service,
 * a {@link #SERVICE_META_DATA} entry must be included in the declaration
 * of the service. An example of such a service declaration is shown below:
 * <pre> &lt;service android:name=".MySeApduService"&gt;
 *     &lt;intent-filter&gt;
 *         &lt;action android:name="android.nfc.SeApduService"/&gt;
 *     &lt;/intent-filter&gt;
 *     &lt;meta-data android:name="android.nfc.SeApduService" android:resource="@xml/apduservice.xml"/&gt;
 * &lt;/service&gt;</pre>
 * <p>For more details refer to {@link #SERVICE_META_DATA},
 * <code>&lt;{@link android.R.styleable#ApduService apdu-service}&gt;</code> and
 * <code>&lt;{@link android.R.styleable#AidFilter aid-filter}&gt;</code>.
 */
public abstract class SeApduService extends Service {
    /**
     * The {@link Intent} that must be declared as handled by the service.
     */
    @SdkConstant(SdkConstantType.SERVICE_ACTION)
    public static final String SERVICE_INTERFACE =
            "android.nfc.SeApduService";

    /**
     * The name of the meta-data element that contains
     * more information about this service.
     */
    public static final String SERVICE_META_DATA = "android.nfc.SeApduService";

    /**
     * @hide
     */
    public static final int MSG_AID_SELECTED = 0;

    /**
     * @hide
     */
    public static final int MSG_HCI_TRANSACTION_EVT = 1;

    /**
     * @hide
     */
    public static final String KEY_AID = "aid";

    /**
     * @hide
     */
    public static final String KEY_PARAMETERS = "parameters";

    final Messenger mMessenger = new Messenger(new MsgHandler());

    final class MsgHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_AID_SELECTED: {
                    Bundle dataBundle = msg.getData();
                    byte[] aid = dataBundle.getByteArray(KEY_AID);
                    onAidSelected(aid);
                    break;
                }
                case MSG_HCI_TRANSACTION_EVT: {
                    Bundle dataBundle = msg.getData();
                    byte[] aid = dataBundle.getByteArray(KEY_AID);
                    byte[] parameters = dataBundle.getByteArray(KEY_PARAMETERS);
                    onHciTransactionEvent(aid, parameters);
                    break;
                }
            }
        }
    };

    @Override
    public final IBinder onBind(Intent intent) {
        return mMessenger.getBinder();
    }

    /**
     * This method is called when an AID that has been registered
     * in the manifest of this service has been selected on a
     * eSE/UICC.
     * @param aid The AID that has been selected
     */
    public abstract void onAidSelected(byte[] aid);

    /**
     * This method is called when a HCI transaction event has
     * been received for an AID that has been registered
     * in the manifest of this service.
     * @param aid The AID of the application that generated the event
     * @param parameters Parameters according to ETSI-TS 102 622
     */
    public abstract void onHciTransactionEvent(byte[] aid, byte[] parameters);
}
 No newline at end of file
+23 −16
Original line number Diff line number Diff line
@@ -2578,29 +2578,36 @@
        <attr name="vendor" format="string"/>
    </declare-styleable>

    <!-- Use <code>apdu-service</code> as the root tag of the XML resource that
         describes an {@link android.nfc.cardemulation.HostApduService} or
         {@link android.nfc.cardemulation.SeApduService} service, which is referenced
         from its SERVICE_META_DATA entry. -->
    <declare-styleable name="ApduService">
        <!-- Set to true to let the NFC subsystem know that this service implements
             a payment instrument. That will allow this service to be enumerated in
             a list of payment services, where the user can pick his preferred payment
             service. The preferred service will be bound to persistently, to make sure
             it can immediately process APDUs without service startup delay. This is vital
             for existing payment infrastructure that has very strict timing requirements. -->
        <attr name="paymentService" format="boolean" />
        <!-- Short description of the functionality the serivce implements.-->
    <!-- Use <code>host-apdu-service</code> as the root tag of the XML resource that
         describes an {@link android.nfc.cardemulation.HostApduService} service, which
         is referenced from its {@link android.nfc.cardemulation.HostApduService#SERVICE_META_DATA}
         entry. -->
    <declare-styleable name="HostApduService">
        <!-- Short description of the functionality the service implements. This attribute
             is mandatory.-->
        <attr name="description" />
    </declare-styleable>

    <!-- Use <code>offhost-apdu-service</code> as the root tag of the XML resource that
         describes an {@link android.nfc.cardemulation.OffHostApduService}
         service, which is referenced from its
         {@link android.nfc.cardemulation.OffHostApduService#SERVICE_META_DATA} entry. -->
    <declare-styleable name="OffHostApduService">
        <!-- Short description of the functionality the service implements. This attribute
             is mandatory.-->
        <attr name="description" />
    </declare-styleable>

    <!-- Specify one or more <code>aid-filter</code> elements inside a <code>apdu-service</code>
    <!-- Specify one or more <code>aid-filter</code> elements inside a
         <code>host-apdu-service</code> or <code>offhost-apdu-service</code>
         element to list the ISO7816 Application ID (AIDs) your service can handle.-->
    <declare-styleable name="AidFilter">
        <!-- The ISO7816 Application ID -->
        <!-- The ISO7816 Application ID. This attribute is mandatory. -->
        <attr name="name" />
        <!-- Short description of what the AID implements.-->
        <!-- Short description of what the AID implements. This attribute is mandatory.-->
        <attr name="description" />
        <!-- Category. This attribute is optional.-->
        <attr name="category" format="string" />
    </declare-styleable>

    <declare-styleable name="ActionMenuItemView">
Loading