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

Commit 60d125b9 authored by Roshan Pius's avatar Roshan Pius
Browse files

Extending setControllerAlwaysOn feature with trasnparent and Card Emulation mode support

Bug: 331563246
Test: Manual
Flag: NA
nfcOemExtension.setControllerAlwaysOn(INIT_MODE_TRANSPARENT)
nfcOemExtension.setControllerAlwaysOn(INIT_MODE_EE)

Change-Id: I3fc290ebc0b75eca45512eeeb890f99ed0cb77b7
parent 85fb8b68
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -60,8 +60,13 @@ package android.nfc {
    method @FlaggedApi("android.nfc.nfc_oem_extension") @NonNull public java.util.List<java.lang.String> getActiveNfceeList();
    method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void maybeTriggerFirmwareUpdate();
    method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcOemExtension.Callback);
    method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void setControllerAlwaysOn(int);
    method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void synchronizeScreenState();
    method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void unregisterCallback(@NonNull android.nfc.NfcOemExtension.Callback);
    field @FlaggedApi("android.nfc.nfc_oem_extension") public static final int DISABLE = 0; // 0x0
    field @FlaggedApi("android.nfc.nfc_oem_extension") public static final int ENABLE_DEFAULT = 1; // 0x1
    field @FlaggedApi("android.nfc.nfc_oem_extension") public static final int ENABLE_EE = 3; // 0x3
    field @FlaggedApi("android.nfc.nfc_oem_extension") public static final int ENABLE_TRANSPARENT = 2; // 0x2
    field public static final int HCE_ACTIVATE = 1; // 0x1
    field public static final int HCE_DATA_TRANSFERRED = 2; // 0x2
    field public static final int HCE_DEACTIVATE = 3; // 0x3
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ interface INfcAdapter
    boolean setNfcSecure(boolean enable);
    NfcAntennaInfo getNfcAntennaInfo();

    boolean setControllerAlwaysOn(boolean value);
    void setControllerAlwaysOn(int mode);
    boolean isControllerAlwaysOn();
    boolean isControllerAlwaysOnSupported();
    void registerControllerAlwaysOnListener(in INfcControllerAlwaysOnListener listener);
+21 −3
Original line number Diff line number Diff line
@@ -559,6 +559,18 @@ public final class NfcAdapter {
    @Retention(RetentionPolicy.SOURCE)
    public @interface TagIntentAppPreferenceResult {}

    /**
     * Mode Type for {@link NfcOemExtension#setControllerAlwaysOn(int)}.
     * @hide
     */
    public static final int CONTROLLER_ALWAYS_ON_MODE_DEFAULT = 1;

    /**
     * Mode Type for {@link NfcOemExtension#setControllerAlwaysOn(int)}.
     * @hide
     */
    public static final int CONTROLLER_ALWAYS_ON_DISABLE = 0;

    // Guarded by sLock
    static boolean sIsInitialized = false;
    static boolean sHasNfcFeature;
@@ -2325,7 +2337,8 @@ public final class NfcAdapter {
     * FEATURE_NFC_HOST_CARD_EMULATION, FEATURE_NFC_HOST_CARD_EMULATION_NFCF,
     * FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC and FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE
     * are unavailable
     * @return void
     * @return true if feature is supported by the device and operation has bee initiated,
     * false if the feature is not supported by the device.
     * @hide
     */
    @SystemApi
@@ -2334,8 +2347,13 @@ public final class NfcAdapter {
        if (!sHasNfcFeature && !sHasCeFeature) {
            throw new UnsupportedOperationException();
        }
        return callServiceReturn(() ->  sService.setControllerAlwaysOn(value), false);

        int mode = value ? CONTROLLER_ALWAYS_ON_MODE_DEFAULT : CONTROLLER_ALWAYS_ON_DISABLE;
        try {
            callService(() -> sService.setControllerAlwaysOn(mode));
        } catch (UnsupportedOperationException e) {
            return false;
        }
        return true;
    }

    /**
+78 −0
Original line number Diff line number Diff line
@@ -69,6 +69,58 @@ public final class NfcOemExtension {
    private boolean mRfFieldActivated = false;
    private boolean mRfDiscoveryStarted = false;

    /**
     * Mode Type for {@link #setControllerAlwaysOn(int)}.
     * Enables the controller in default mode when NFC is disabled (existing API behavior).
     * works same as {@link NfcAdapter#setControllerAlwaysOn(boolean)}.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
    public static final int ENABLE_DEFAULT = NfcAdapter.CONTROLLER_ALWAYS_ON_MODE_DEFAULT;

    /**
     * Mode Type for {@link #setControllerAlwaysOn(int)}.
     * Enables the controller in transparent mode when NFC is disabled.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
    public static final int ENABLE_TRANSPARENT = 2;

    /**
     * Mode Type for {@link #setControllerAlwaysOn(int)}.
     * Enables the controller and initializes and enables the EE subsystem when NFC is disabled.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
    public static final int ENABLE_EE = 3;

    /**
     * Mode Type for {@link #setControllerAlwaysOn(int)}.
     * Disable the Controller Always On Mode.
     * works same as {@link NfcAdapter#setControllerAlwaysOn(boolean)}.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
    public static final int DISABLE = NfcAdapter.CONTROLLER_ALWAYS_ON_DISABLE;

    /**
     * Possible controller modes for {@link #setControllerAlwaysOn(int)}.
     *
     * @hide
     */
    @IntDef(prefix = { "" }, value = {
        ENABLE_DEFAULT,
        ENABLE_TRANSPARENT,
        ENABLE_EE,
        DISABLE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ControllerMode{}

    /**
     * Event that Host Card Emulation is activated.
     */
@@ -382,6 +434,32 @@ public final class NfcOemExtension {
            NfcAdapter.sService.fetchActiveNfceeList(), new ArrayList<String>());
    }

    /**
     * Sets NFC controller always on feature.
     * <p>This API is for the NFCC internal state management. It allows to discriminate
     * the controller function from the NFC function by keeping the NFC controller on without
     * any NFC RF enabled if necessary.
     * <p>This call is asynchronous, register listener {@link NfcAdapter.ControllerAlwaysOnListener}
     * by {@link NfcAdapter#registerControllerAlwaysOnListener} to find out when the operation is
     * complete.
     * @param mode one of {@link ControllerMode} modes
     * @throws UnsupportedOperationException if
     *   <li> if FEATURE_NFC, FEATURE_NFC_HOST_CARD_EMULATION, FEATURE_NFC_HOST_CARD_EMULATION_NFCF,
     *   FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC and FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE
     *   are unavailable </li>
     *   <li> if the feature is unavailable @see NfcAdapter#isNfcControllerAlwaysOnSupported() </li>
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
    @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON)
    public void setControllerAlwaysOn(@ControllerMode int mode) {
        if (!NfcAdapter.sHasNfcFeature && !NfcAdapter.sHasCeFeature) {
            throw new UnsupportedOperationException();
        }
        NfcAdapter.callService(() -> NfcAdapter.sService.setControllerAlwaysOn(mode));
    }

    private final class NfcOemExtensionCallback extends INfcOemExtensionCallback.Stub {

        @Override