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

Commit f440009c authored by Brad Lassey's avatar Brad Lassey
Browse files

Implement NFC Event Listener API

Bug: 359208634
Test: New CTS tests
Flag: android.nfc.nfc_event_listener
Change-Id: I8d421e51a60421ee1b6b7ba93e0f6401b79137b7
parent 0ef98b7d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -232,6 +232,8 @@ package android.nfc.cardemulation {
    method public final void notifyUnhandled();
    method public final android.os.IBinder onBind(android.content.Intent);
    method public abstract void onDeactivated(int);
    method @FlaggedApi("android.nfc.nfc_event_listener") public void onObserveModeStateChanged(boolean);
    method @FlaggedApi("android.nfc.nfc_event_listener") public void onPreferredServiceChanged(boolean);
    method public abstract byte[] processCommandApdu(byte[], android.os.Bundle);
    method @FlaggedApi("android.nfc.nfc_read_polling_loop") public void processPollingFrames(@NonNull java.util.List<android.nfc.cardemulation.PollingFrame>);
    method public final void sendResponseApdu(byte[]);
+43 −1
Original line number Diff line number Diff line
@@ -239,6 +239,16 @@ public abstract class HostApduService extends Service {
     */
    public static final int MSG_POLLING_LOOP = 4;

    /**
     * @hide
     */
    public static final int MSG_OBSERVE_MODE_CHANGE = 5;

    /**
     * @hide
     */
    public static final int MSG_PREFERRED_SERVICE_CHANGED = 6;

    /**
     * @hide
     */
@@ -333,6 +343,16 @@ public abstract class HostApduService extends Service {
                        processPollingFrames(pollingFrames);
                    }
                    break;
                case MSG_OBSERVE_MODE_CHANGE:
                    if (android.nfc.Flags.nfcEventListener()) {
                        onObserveModeStateChanged(msg.arg1 == 1);
                    }
                    break;
                case MSG_PREFERRED_SERVICE_CHANGED:
                    if (android.nfc.Flags.nfcEventListener()) {
                        onPreferredServiceChanged(msg.arg1 == 1);
                    }
                    break;
                default:
                super.handleMessage(msg);
            }
@@ -441,4 +461,26 @@ public abstract class HostApduService extends Service {
     * @param reason Either {@link #DEACTIVATION_LINK_LOSS} or {@link #DEACTIVATION_DESELECTED}
     */
    public abstract void onDeactivated(int reason);


    /**
     * This method is called when this service is the preferred Nfc service and
     * Observe mode has been enabled or disabled.
     *
     * @param isEnabled true if observe mode has been enabled, false if it has been disabled
     */
    @FlaggedApi(android.nfc.Flags.FLAG_NFC_EVENT_LISTENER)
    public void onObserveModeStateChanged(boolean isEnabled) {

    }

    /**
     * This method is called when this service gains or loses preferred Nfc service status.
     *
     * @param isPreferred true is this service has become the preferred Nfc service,
     * false if it is no longer the preferred service
     */
    @FlaggedApi(android.nfc.Flags.FLAG_NFC_EVENT_LISTENER)
    public void onPreferredServiceChanged(boolean isPreferred) {
    }
}
+8 −0
Original line number Diff line number Diff line
package: "android.nfc"
container: "system"

flag {
    name: "nfc_event_listener"
    is_exported: true
    namespace: "nfc"
    description: "Enable NFC Event listener APIs"
    bug: "356447790"
}

flag {
    name: "enable_nfc_mainline"
    is_exported: true