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

Commit 37262db5 authored by Bob Wang's avatar Bob Wang Committed by Automerger Merge Worker
Browse files

Merge "[framework] Expose override/recover routingTable as systemApi." into...

Merge "[framework] Expose override/recover routingTable as systemApi." into main am: ea598ed3 am: ffa96c35

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3199744



Change-Id: I1b8555bf4831c108ee84a93801e0babdb8e8da97
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents c2176e5a ffa96c35
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -220,11 +220,14 @@ 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 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 {
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ 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 recoverRoutingTable(@NonNull android.app.Activity);
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -48,6 +48,6 @@ interface INfcCardEmulation
    boolean setServiceEnabledForCategoryOther(int userHandle, in ComponentName app, boolean status);
    boolean isDefaultPaymentRegistered();

    boolean overrideRoutingTable(int userHandle, String protocol, String technology);
    boolean recoverRoutingTable(int userHandle);
    void overrideRoutingTable(int userHandle, String protocol, String technology, in String pkg);
    void recoverRoutingTable(int userHandle);
}
+59 −18
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ 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;
@@ -43,6 +44,8 @@ import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashMap;
import java.util.HexFormat;
import java.util.List;
@@ -148,6 +151,21 @@ public final class CardEmulation {
     *    that service will be invoked directly.
     */
    public static final int SELECTION_MODE_ASK_IF_CONFLICT = 2;
    /**
     * Route to Device Host (DH).
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final String DH = "DH";
    /**
     * Route to eSE.
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final String ESE = "ESE";
    /**
     * Route to UICC.
     */
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public static final String UICC = "UICC";

    static boolean sIsInitialized = false;
    static HashMap<Context, CardEmulation> sCardEmus = new HashMap<Context, CardEmulation>();
@@ -865,11 +883,22 @@ public final class CardEmulation {
                sService.setServiceEnabledForCategoryOther(userId, service, status), false);
    }

    /** @hide */
    @StringDef({
        DH,
        ESE,
        UICC
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ProtocolAndTechnologyRoute {}

     /**
      * 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.
      * The parameter set to null 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>
@@ -877,26 +906,39 @@ public final class CardEmulation {
      *     mNfcAdapter.overrideRoutingTable(this , "ESE" , null);
      * }</pre>
      * </p>
      * Also activities must call this method when it goes to the background,
      * with all parameters set to null.
      * 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}),
      * 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 route destination, which can be "DH" or "UICC" or "ESE".
      * @return true if operation is successful and false otherwise
      *
      * @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.
      * <p>
      * This is a high risk API and only included to support mainline effort
      * @hide
      */
    public boolean overrideRoutingTable(Activity activity, String protocol, String technology) {
        if (activity == null) {
            throw new NullPointerException("activity or service or category is null");
        }
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public void overrideRoutingTable(
            @NonNull Activity activity, @ProtocolAndTechnologyRoute @Nullable String protocol,
            @ProtocolAndTechnologyRoute @Nullable String technology) {
        if (!activity.isResumed()) {
            throw new IllegalArgumentException("Activity must be resumed.");
        }
        return callServiceReturn(() ->
        if (protocol == null && technology == null) {
            throw new IllegalArgumentException(("Both Protocol and Technology are null."));
        }
        callService(() ->
                sService.overrideRoutingTable(
                    mContext.getUser().getIdentifier(), protocol, technology), false);
                    mContext.getUser().getIdentifier(),
                    protocol,
                    technology,
                    mContext.getPackageName()));
    }

    /**
@@ -904,20 +946,19 @@ public final class CardEmulation {
     * which was changed by {@link #overrideRoutingTable(Activity, String, String)}
     *
     * @param activity The Activity that requested NFC controller routing table to be changed.
     * @return true if operation is successful and false otherwise
     * @throws IllegalArgumentException if the caller is not in the foreground.
     *
     * @hide
     */
    public boolean recoverRoutingTable(Activity activity) {
        if (activity == null) {
            throw new NullPointerException("activity is null");
        }
    @SystemApi
    @FlaggedApi(Flags.FLAG_NFC_OVERRIDE_RECOVER_ROUTING_TABLE)
    public void recoverRoutingTable(@NonNull Activity activity) {
        if (!activity.isResumed()) {
            throw new IllegalArgumentException("Activity must be resumed.");
        }
        return callServiceReturn(() ->
        callService(() ->
                sService.recoverRoutingTable(
                    mContext.getUser().getIdentifier()), false);
                    mContext.getUser().getIdentifier()));
    }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -133,3 +133,11 @@ flag {
    description: "Add Settings.ACTION_MANAGE_OTHER_NFC_SERVICES_SETTINGS"
    bug: "358129872"
}

flag {
    name: "nfc_override_recover_routing_table"
    is_exported: true
    namespace: "nfc"
    description: "Enable override and recover routing table"
    bug: "329043523"
}