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

Commit baca13fa authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "[framework] Change proto and tech route to int value." into main

parents 6696482e 2d05ad4a
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -220,14 +220,15 @@ package android.nfc.cardemulation {
    field @Deprecated public static final String ACTION_CHANGE_DEFAULT = "android.nfc.cardemulation.action.ACTION_CHANGE_DEFAULT";
    field public static final String CATEGORY_OTHER = "other";
    field public static final String CATEGORY_PAYMENT = "payment";
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final String DH = "DH";
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final String ESE = "ESE";
    field public static final String EXTRA_CATEGORY = "category";
    field public static final String EXTRA_SERVICE_COMPONENT = "component";
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_DH = 0; // 0x0
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE = 1; // 0x1
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_UICC = 2; // 0x2
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_UNSET = -1; // 0xffffffff
    field public static final int SELECTION_MODE_ALWAYS_ASK = 1; // 0x1
    field public static final int SELECTION_MODE_ASK_IF_CONFLICT = 2; // 0x2
    field public static final int SELECTION_MODE_PREFER_DEFAULT = 0; // 0x0
    field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final String UICC = "UICC";
  }

  public abstract class HostApduService extends android.app.Service {
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ package android.nfc.cardemulation {
  public final class CardEmulation {
    method @FlaggedApi("android.permission.flags.wallet_role_enabled") @Nullable @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO) public static android.content.ComponentName getPreferredPaymentService(@NonNull android.content.Context);
    method @FlaggedApi("android.nfc.enable_nfc_mainline") @NonNull public java.util.List<android.nfc.cardemulation.ApduServiceInfo> getServices(@NonNull String, int);
    method @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public void overrideRoutingTable(@NonNull android.app.Activity, @Nullable String, @Nullable String);
    method @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public void overrideRoutingTable(@NonNull android.app.Activity, int, int);
    method @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public void recoverRoutingTable(@NonNull android.app.Activity);
  }

+46 −24
Original line number Diff line number Diff line
@@ -18,12 +18,12 @@ package android.nfc.cardemulation;

import android.Manifest;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.StringDef;
import android.annotation.SystemApi;
import android.annotation.UserHandleAware;
import android.annotation.UserIdInt;
@@ -155,17 +155,23 @@ public final class CardEmulation {
     * Route to Device Host (DH).
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final String DH = "DH";
    public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_DH = 0;
    /**
     * Route to eSE.
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final String ESE = "ESE";
    public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE = 1;
    /**
     * Route to UICC.
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final String UICC = "UICC";
    public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_UICC = 2;

    /**
     * Route unset.
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_UNSET = -1;

    static boolean sIsInitialized = false;
    static HashMap<Context, CardEmulation> sCardEmus = new HashMap<Context, CardEmulation>();
@@ -734,7 +740,7 @@ public final class CardEmulation {
     *
     * @return the preferred payment service description
     */
    @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
    @RequiresPermission(Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
    @Nullable
    public CharSequence getDescriptionForPreferredPaymentService() {
        ApduServiceInfo serviceInfo = callServiceReturn(() ->
@@ -884,10 +890,12 @@ public final class CardEmulation {
    }

    /** @hide */
    @StringDef({
        DH,
        ESE,
        UICC
    @IntDef(prefix = "PROTOCOL_AND_TECHNOLOGY_ROUTE_",
            value = {
                    PROTOCOL_AND_TECHNOLOGY_ROUTE_DH,
                    PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE,
                    PROTOCOL_AND_TECHNOLOGY_ROUTE_UICC,
                    PROTOCOL_AND_TECHNOLOGY_ROUTE_UNSET
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ProtocolAndTechnologyRoute {}
@@ -896,29 +904,32 @@ public final class CardEmulation {
      * Setting NFC controller routing table, which includes Protocol Route and Technology Route,
      * while this Activity is in the foreground.
      *
      * The parameter set to null can be used to keep current values for that entry. Either
      * The parameter set to {@link #PROTOCOL_AND_TECHNOLOGY_ROUTE_UNSET}
      * can be used to keep current values for that entry. Either
      * Protocol Route or Technology Route should be override when calling this API, otherwise
      * throw {@link IllegalArgumentException}.
      * <p>
      * Example usage in an Activity that requires to set proto route to "ESE" and keep tech route:
      * <pre>
      * protected void onResume() {
      *     mNfcAdapter.overrideRoutingTable(this , "ESE" , null);
      *     mNfcAdapter.overrideRoutingTable(
      *         this, {@link #PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE}, null);
      * }</pre>
      * </p>
      * Also activities must call {@link #recoverRoutingTable(Activity)}
      * when it goes to the background. Only the package of the
      * currently preferred service (the service set as preferred by the current foreground
      * application via {@link CardEmulation#setPreferredService(Activity, ComponentName)} or the
      * current Default Wallet Role Holder {@link android.app.role.RoleManager#ROLE_WALLET}),
      * current Default Wallet Role Holder {@link RoleManager#ROLE_WALLET}),
      * otherwise a call to this method will fail and throw {@link SecurityException}.
      * @param activity The Activity that requests NFC controller routing table to be changed.
      * @param protocol ISO-DEP route destination, which can be "DH" or "UICC" or "ESE".
      * @param technology Tech-A, Tech-B and Tech-F route destination, which can be "DH" or "UICC"
      * or "ESE".
      * @param protocol ISO-DEP route destination, where the possible inputs are defined
      *                 in {@link ProtocolAndTechnologyRoute}.
      * @param technology Tech-A, Tech-B and Tech-F route destination, where the possible inputs
      *                   are defined in {@link ProtocolAndTechnologyRoute}
      * @throws SecurityException if the caller is not the preferred NFC service
      * @throws IllegalArgumentException if the activity is not resumed or the caller is not in the
      * foreground, or both protocol route and technology route are null.
      * foreground.
      * <p>
      * This is a high risk API and only included to support mainline effort
      * @hide
@@ -926,25 +937,36 @@ public final class CardEmulation {
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public void overrideRoutingTable(
            @NonNull Activity activity, @ProtocolAndTechnologyRoute @Nullable String protocol,
            @ProtocolAndTechnologyRoute @Nullable String technology) {
            @NonNull Activity activity, @ProtocolAndTechnologyRoute int protocol,
            @ProtocolAndTechnologyRoute int technology) {
        if (!activity.isResumed()) {
            throw new IllegalArgumentException("Activity must be resumed.");
        }
        if (protocol == null && technology == null) {
            throw new IllegalArgumentException(("Both Protocol and Technology are null."));
        }
        String protocolRoute = switch (protocol) {
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_DH -> "DH";
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE -> "ESE";
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_UICC -> "UICC";
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_UNSET -> null;
            default -> throw new IllegalStateException("Unexpected value: " + protocol);
        };
        String technologyRoute = switch (technology) {
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_DH -> "DH";
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE -> "ESE";
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_UICC -> "UICC";
            case PROTOCOL_AND_TECHNOLOGY_ROUTE_UNSET -> null;
            default -> throw new IllegalStateException("Unexpected value: " + protocol);
        };
        callService(() ->
                sService.overrideRoutingTable(
                    mContext.getUser().getIdentifier(),
                    protocol,
                    technology,
                    protocolRoute,
                    technologyRoute,
                    mContext.getPackageName()));
    }

    /**
     * Restore the NFC controller routing table,
     * which was changed by {@link #overrideRoutingTable(Activity, String, String)}
     * which was changed by {@link #overrideRoutingTable(Activity, int, int)}
     *
     * @param activity The Activity that requested NFC controller routing table to be changed.
     * @throws IllegalArgumentException if the caller is not in the foreground.