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

Commit 8e970db8 authored by Alisher Alikhodjaev's avatar Alisher Alikhodjaev Committed by Gerrit Code Review
Browse files

Merge "implementation of NFC Reader option" into main

parents 709b9568 65025baa
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -29084,6 +29084,8 @@ package android.nfc {
    method @Nullable public android.nfc.NfcAntennaInfo getNfcAntennaInfo();
    method public boolean ignore(android.nfc.Tag, int, android.nfc.NfcAdapter.OnTagRemovedListener, android.os.Handler);
    method public boolean isEnabled();
    method @FlaggedApi("android.nfc.enable_nfc_reader_option") public boolean isReaderOptionEnabled();
    method @FlaggedApi("android.nfc.enable_nfc_reader_option") public boolean isReaderOptionSupported();
    method public boolean isSecureNfcEnabled();
    method public boolean isSecureNfcSupported();
    field public static final String ACTION_ADAPTER_STATE_CHANGED = "android.nfc.action.ADAPTER_STATE_CHANGED";
+1 −0
Original line number Diff line number Diff line
@@ -10216,6 +10216,7 @@ package android.nfc {
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean disable();
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean disable(boolean);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enable();
    method @FlaggedApi("android.nfc.enable_nfc_reader_option") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enableReaderOption(boolean);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean enableSecureNfc(boolean);
    method @NonNull @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public java.util.Map<java.lang.String,java.lang.Boolean> getTagIntentAppPreferenceForUser(int);
    method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOn();
+5 −0
Original line number Diff line number Diff line
@@ -79,4 +79,9 @@ interface INfcAdapter
    Map getTagIntentAppPreferenceForUser(int userId);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)")
    int setTagIntentAppPreferenceForUser(int userId, String pkg, boolean allow);

    boolean isReaderOptionEnabled();
    boolean isReaderOptionSupported();
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)")
    boolean enableReaderOption(boolean enable);
}
+92 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.nfc;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1825,6 +1826,97 @@ public final class NfcAdapter {
        }
    }

    /**
     * Sets NFC Reader option feature.
     * <p>This API is for the Settings application.
     * @return True if successful
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_ENABLE_NFC_READER_OPTION)
    @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
    public boolean enableReaderOption(boolean enable) {
        if (!sHasNfcFeature) {
            throw new UnsupportedOperationException();
        }
        try {
            return sService.enableReaderOption(enable);
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            // Try one more time
            if (sService == null) {
                Log.e(TAG, "Failed to recover NFC Service.");
                return false;
            }
            try {
                return sService.enableReaderOption(enable);
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover NFC Service.");
            }
            return false;
        }
    }

    /**
     * Checks if the device supports NFC Reader option functionality.
     *
     * @return True if device supports NFC Reader option, false otherwise
     * @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
     */
    @FlaggedApi(Flags.FLAG_ENABLE_NFC_READER_OPTION)
    public boolean isReaderOptionSupported() {
        if (!sHasNfcFeature) {
            throw new UnsupportedOperationException();
        }
        try {
            return sService.isReaderOptionSupported();
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            // Try one more time
            if (sService == null) {
                Log.e(TAG, "Failed to recover NFC Service.");
                return false;
            }
            try {
                return sService.isReaderOptionSupported();
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover NFC Service.");
            }
            return false;
        }
    }

    /**
     * Checks NFC Reader option feature is enabled.
     *
     * @return True if NFC Reader option  is enabled, false otherwise
     * @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
     * @throws UnsupportedOperationException if device doesn't support
     *         NFC Reader option functionality. {@link #isReaderOptionSupported}
     */
    @FlaggedApi(Flags.FLAG_ENABLE_NFC_READER_OPTION)
    public boolean isReaderOptionEnabled() {
        if (!sHasNfcFeature) {
            throw new UnsupportedOperationException();
        }
        try {
            return sService.isReaderOptionEnabled();
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            // Try one more time
            if (sService == null) {
                Log.e(TAG, "Failed to recover NFC Service.");
                return false;
            }
            try {
                return sService.isReaderOptionEnabled();
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover NFC Service.");
            }
            return false;
        }
    }

    /**
     * Enable NDEF Push feature.
     * <p>This API is for the Settings application.
+7 −0
Original line number Diff line number Diff line
@@ -6,3 +6,10 @@ flag {
    description: "Flag for NFC mainline changes"
    bug: "292140387"
}

flag {
    name: "enable_nfc_reader_option"
    namespace: "nfc"
    description: "Flag for NFC reader option API changes"
    bug: "291187960"
}