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

Commit e504d3d4 authored by George Chang's avatar George Chang
Browse files

Update isTagIntentAllowed and isTagIntentAppPreferenceSupported

Add new API isTagIntentAllowed and expose isTagIntentAppPreferenceSupported
as public API.

Flag: android.nfc.nfc_check_tag_intent_preference
Bug: 335916336
Test: m framework-nfc.stubs.source.system-update-current-api
Test: m framework-nfc.stubs.source-update-current-api
Test: atest android.nfc.cts.NfcAdapterTest#testIsTagIntentAllowed
Test: atest android.nfc.cts.NfcAdapterTest#testIsTagIntentAppPreferenceSupported
Test: atest android.nfc.cts.NfcAdapterTest#testIsTagIntentAllowedWhenNotSupported
Change-Id: I502c31ec8ba876d9a0c35a8d5447343d27ef678d
parent 6e7ebccd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -81,11 +81,14 @@ package android.nfc {
    method @FlaggedApi("android.nfc.enable_nfc_reader_option") public boolean isReaderOptionSupported();
    method public boolean isSecureNfcEnabled();
    method public boolean isSecureNfcSupported();
    method @FlaggedApi("android.nfc.nfc_check_tag_intent_preference") public boolean isTagIntentAllowed();
    method @FlaggedApi("android.nfc.nfc_check_tag_intent_preference") public boolean isTagIntentAppPreferenceSupported();
    method @FlaggedApi("android.nfc.enable_nfc_charging") public boolean isWlcEnabled();
    method @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public void resetDiscoveryTechnology(@NonNull android.app.Activity);
    method @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public void setDiscoveryTechnology(@NonNull android.app.Activity, int, int);
    method @FlaggedApi("android.nfc.nfc_observe_mode") public boolean setObserveModeEnabled(boolean);
    field public static final String ACTION_ADAPTER_STATE_CHANGED = "android.nfc.action.ADAPTER_STATE_CHANGED";
    field @FlaggedApi("android.nfc.nfc_check_tag_intent_preference") public static final String ACTION_CHANGE_TAG_INTENT_PREFERENCE = "android.nfc.action.CHANGE_TAG_INTENT_PREFERENCE";
    field public static final String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
    field @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO) public static final String ACTION_PREFERRED_PAYMENT_CHANGED = "android.nfc.action.PREFERRED_PAYMENT_CHANGED";
    field public static final String ACTION_TAG_DISCOVERED = "android.nfc.action.TAG_DISCOVERED";
+0 −1
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ package android.nfc {
    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();
    method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public boolean isControllerAlwaysOnSupported();
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean isTagIntentAppPreferenceSupported();
    method @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void registerControllerAlwaysOnListener(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcAdapter.ControllerAlwaysOnListener);
    method @FlaggedApi("android.nfc.nfc_vendor_cmd") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void registerNfcVendorNciCallback(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcAdapter.NfcVendorNciCallback);
    method @FlaggedApi("android.nfc.enable_nfc_charging") public void registerWlcStateListener(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcAdapter.WlcStateListener);
+1 −0
Original line number Diff line number Diff line
@@ -121,4 +121,5 @@ interface INfcAdapter
    List<Entry> getRoutingTableEntryList();
    void indicateDataMigration(boolean inProgress, String pkg);
    int commitRouting();
    boolean isTagIntentAllowed(in String pkg, in int Userid);
}
+45 −6
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;

import java.io.IOException;
@@ -2505,22 +2506,22 @@ public final class NfcAdapter {
    }

    /**
     * Checks if the device supports Tag application preference.
     * Checks if the device supports Tag Intent App Preference functionality.
     *
     * When supported, {@link #ACTION_NDEF_DISCOVERED}, {@link #ACTION_TECH_DISCOVERED} or
     * {@link #ACTION_TAG_DISCOVERED} will not be dispatched to an Activity if
     * {@link isTagIntentAllowed} returns {@code false}.
     *
     * @return {@code true} if the device supports Tag application preference, {@code false}
     * otherwise
     * @throws UnsupportedOperationException if FEATURE_NFC is unavailable
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
    @FlaggedApi(Flags.FLAG_NFC_CHECK_TAG_INTENT_PREFERENCE)
    public boolean isTagIntentAppPreferenceSupported() {
        if (!sHasNfcFeature) {
            throw new UnsupportedOperationException();
        }
        return callServiceReturn(() ->  sService.isTagIntentAppPreferenceSupported(), false);

    }

   /**
@@ -2895,4 +2896,42 @@ public final class NfcAdapter {
        }
        return mNfcOemExtension;
    }

    /**
     * Activity action: Bring up the settings page that allows the user to enable or disable tag
     * intent reception for apps.
     *
     * <p>This will direct user to the settings page shows a list that asks users whether
     * they want to allow or disallow the package to start an activity when a tag is discovered.
     *
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    @FlaggedApi(Flags.FLAG_NFC_CHECK_TAG_INTENT_PREFERENCE)
    public static final String ACTION_CHANGE_TAG_INTENT_PREFERENCE =
            "android.nfc.action.CHANGE_TAG_INTENT_PREFERENCE";

    /**
     * Checks whether the user has disabled the calling app from receiving NFC tag intents.
     *
     * <p>This method checks whether the caller package name is either not present in the user
     * disabled list or is explicitly allowed by the user.
     *
     * @return {@code true} if an app is either not present in the list or is added to the list
     * with the flag set to {@code true}. Otherwise, it returns {@code false}.
     * It also returns {@code true} if {@link isTagIntentAppPreferenceSupported} returns
     * {@code false}.
     *
     * @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
     */
    @FlaggedApi(Flags.FLAG_NFC_CHECK_TAG_INTENT_PREFERENCE)
    public boolean isTagIntentAllowed() {
        if (!sHasNfcFeature) {
            throw new UnsupportedOperationException();
        }
        if (!isTagIntentAppPreferenceSupported()) {
            return true;
        }
        return callServiceReturn(() ->  sService.isTagIntentAllowed(mContext.getPackageName(),
                UserHandle.myUserId()), false);
    }
}