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

Commit 3e99e2b4 authored by Brad Lassey's avatar Brad Lassey
Browse files

Add the ability to mark a polling loop filter to automatically transact

Bug: b/322542058
Test: Tested with new CTS test
Change-Id: Ibb623d51ac4758ab89873317afe80a4b9b7a8b0d
parent a08e7682
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -506,6 +506,7 @@ package android {
    field public static final int autoSizeTextType = 16844085; // 0x1010535
    field public static final int autoStart = 16843445; // 0x10102b5
    field @Deprecated public static final int autoText = 16843114; // 0x101016a
    field @FlaggedApi("android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP") public static final int autoTransact;
    field public static final int autoUrlDetect = 16843404; // 0x101028c
    field public static final int autoVerify = 16844014; // 0x10104ee
    field public static final int autofillHints = 16844118; // 0x1010556
+2 −0
Original line number Diff line number Diff line
@@ -10168,6 +10168,7 @@ package android.nfc.cardemulation {
  @FlaggedApi("android.nfc.enable_nfc_mainline") public final class ApduServiceInfo implements android.os.Parcelable {
    ctor @FlaggedApi("android.nfc.enable_nfc_mainline") public ApduServiceInfo(@NonNull android.content.pm.PackageManager, @NonNull android.content.pm.ResolveInfo, boolean) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
    method @FlaggedApi("android.nfc.nfc_read_polling_loop") public void addPollingLoopFilter(@NonNull String);
    method @FlaggedApi("android.nfc.nfc_read_polling_loop") public void addPollingLoopFilterToAutoTransact(@NonNull String);
    method @FlaggedApi("android.nfc.enable_nfc_mainline") public int describeContents();
    method @FlaggedApi("android.nfc.enable_nfc_mainline") public void dump(@NonNull android.os.ParcelFileDescriptor, @NonNull java.io.PrintWriter, @NonNull String[]);
    method @FlaggedApi("android.nfc.enable_nfc_mainline") public void dumpDebug(@NonNull android.util.proto.ProtoOutputStream);
@@ -10181,6 +10182,7 @@ package android.nfc.cardemulation {
    method @FlaggedApi("android.nfc.nfc_read_polling_loop") @NonNull public java.util.List<java.lang.String> getPollingLoopFilters();
    method @FlaggedApi("android.nfc.enable_nfc_mainline") @NonNull public java.util.List<java.lang.String> getPrefixAids();
    method @FlaggedApi("android.nfc.enable_nfc_mainline") @NonNull public String getSettingsActivityName();
    method @FlaggedApi("android.nfc.nfc_read_polling_loop") public boolean getShouldAutoTransact(@NonNull String);
    method @FlaggedApi("android.nfc.enable_nfc_mainline") @NonNull public java.util.List<java.lang.String> getSubsetAids();
    method @FlaggedApi("android.nfc.enable_nfc_mainline") public int getUid();
    method @FlaggedApi("android.nfc.enable_nfc_mainline") public boolean hasCategory(@NonNull String);
+5 −0
Original line number Diff line number Diff line
@@ -4375,9 +4375,14 @@
    <!-- Specify one or more <code>polling-loop-filter</code> elements inside a
         <code>host-apdu-service</code> to indicate polling loop frames that
         your service can handle. -->
    <!-- @FlaggedApi("android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP") -->
    <declare-styleable name="PollingLoopFilter">
        <!-- The polling loop frame. This attribute is mandatory. -->
        <attr name="name" />
        <!-- Whether or not the system should automatically start a transaction when this polling
         loop filter matches. If not set, default value is false. -->
        <!-- @FlaggedApi("android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP") -->
        <attr name="autoTransact" format="boolean"/>
    </declare-styleable>
    <!-- Use <code>host-nfcf-service</code> as the root tag of the XML resource that
+2 −0
Original line number Diff line number Diff line
@@ -145,6 +145,8 @@
    <public name="fragmentSuffix"/>
    <!-- @FlaggedApi("com.android.text.flags.use_bounds_for_width") -->
    <public name="useBoundsForWidth"/>
    <!-- @FlaggedApi("android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP") -->
    <public name="autoTransact"/>
  </staging-public-group>

  <staging-public-group type="id" first-id="0x01bc0000">
+34 −0
Original line number Diff line number Diff line
@@ -105,6 +105,8 @@ public final class ApduServiceInfo implements Parcelable {

    private final ArrayList<String> mPollingLoopFilters;

    private final Map<String, Boolean> mAutoTransact;

    /**
     * Whether this service should only be started when the device is unlocked.
     */
@@ -173,6 +175,7 @@ public final class ApduServiceInfo implements Parcelable {
        this.mStaticAidGroups = new HashMap<String, AidGroup>();
        this.mDynamicAidGroups = new HashMap<String, AidGroup>();
        this.mPollingLoopFilters = new ArrayList<String>();
        this.mAutoTransact = new HashMap<String, Boolean>();
        this.mOffHostName = offHost;
        this.mStaticOffHostName = staticOffHost;
        this.mOnHost = onHost;
@@ -287,6 +290,7 @@ public final class ApduServiceInfo implements Parcelable {
            mStaticAidGroups = new HashMap<String, AidGroup>();
            mDynamicAidGroups = new HashMap<String, AidGroup>();
            mPollingLoopFilters = new ArrayList<String>();
            mAutoTransact = new HashMap<String, Boolean>();
            mOnHost = onHost;

            final int depth = parser.getDepth();
@@ -377,6 +381,10 @@ public final class ApduServiceInfo implements Parcelable {
                            a.getString(com.android.internal.R.styleable.PollingLoopFilter_name)
                            .toUpperCase(Locale.ROOT);
                    mPollingLoopFilters.add(plf);
                    boolean autoTransact = a.getBoolean(
                            com.android.internal.R.styleable.PollingLoopFilter_autoTransact,
                            false);
                    mAutoTransact.put(plf, autoTransact);
                    a.recycle();
                }
            }
@@ -443,6 +451,17 @@ public final class ApduServiceInfo implements Parcelable {
        return mPollingLoopFilters;
    }

    /**
     * Returns whether this service would like to automatically transact for a given plf.
     *
     * @param plf the polling loop filter to query.
     * @return {@code true} indicating to auto transact, {@code false} indicating to not.
     */
    @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP)
    public boolean getShouldAutoTransact(@NonNull String plf) {
        return mAutoTransact.getOrDefault(plf.toUpperCase(Locale.ROOT), false);
    }

    /**
     * Returns a consolidated list of AIDs with prefixes from the AID groups
     * registered by this service. Note that if a service has both
@@ -629,6 +648,21 @@ public final class ApduServiceInfo implements Parcelable {
        mPollingLoopFilters.add(pollingLoopFilter.toUpperCase(Locale.ROOT));
    }

    /**
     * Add a Polling Loop Filter. Custom NFC polling frames that match this filter will cause the
     * device to exit observe mode, just as if
     * {@link android.nfc.NfcAdapter#setTransactionAllowed(boolean)} had been called with true,
     * allowing transactions to proceed. The matching frame will also be delivered to
     * {@link HostApduService#processPollingFrames(List)}.
     *
     * @param pollingLoopFilter this polling loop filter to add.
     */
    @FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP)
    public void addPollingLoopFilterToAutoTransact(@NonNull String pollingLoopFilter) {
        mPollingLoopFilters.add(pollingLoopFilter.toUpperCase(Locale.ROOT));
        mAutoTransact.put(pollingLoopFilter.toUpperCase(Locale.ROOT), true);
    }

    /**
     * Remove a Polling Loop Filter. Custom NFC polling frames that match this filter will no
     * longer be delivered to {@link HostApduService#processPollingFrames(List)}.