diff options
author | 2024-08-15 19:59:39 +0000 | |
---|---|---|
committer | 2024-08-15 19:59:39 +0000 | |
commit | ea598ed3fed2960a23765eab561dc218c8557a95 (patch) | |
tree | 067bf867ff700183d5551cc396dde14fe9abacd5 | |
parent | 48961ad76621641121ab51ae96991ffbb0228842 (diff) | |
parent | 3ee301360c333362ded4de1c44a0bef8d848c770 (diff) |
Merge "[framework] Expose override/recover routingTable as systemApi." into main
-rw-r--r-- | nfc/api/current.txt | 3 | ||||
-rw-r--r-- | nfc/api/system-current.txt | 2 | ||||
-rw-r--r-- | nfc/java/android/nfc/INfcCardEmulation.aidl | 4 | ||||
-rw-r--r-- | nfc/java/android/nfc/cardemulation/CardEmulation.java | 77 | ||||
-rw-r--r-- | nfc/java/android/nfc/flags.aconfig | 8 |
5 files changed, 74 insertions, 20 deletions
diff --git a/nfc/api/current.txt b/nfc/api/current.txt index b0d1f71e749f..447e980adaee 100644 --- a/nfc/api/current.txt +++ b/nfc/api/current.txt @@ -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 { diff --git a/nfc/api/system-current.txt b/nfc/api/system-current.txt index ae63e1939c00..2ff9829ddfd7 100644 --- a/nfc/api/system-current.txt +++ b/nfc/api/system-current.txt @@ -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); } } diff --git a/nfc/java/android/nfc/INfcCardEmulation.aidl b/nfc/java/android/nfc/INfcCardEmulation.aidl index cb97f23e813c..79f1275ec629 100644 --- a/nfc/java/android/nfc/INfcCardEmulation.aidl +++ b/nfc/java/android/nfc/INfcCardEmulation.aidl @@ -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); } diff --git a/nfc/java/android/nfc/cardemulation/CardEmulation.java b/nfc/java/android/nfc/cardemulation/CardEmulation.java index e0438ce9258c..03372b206f48 100644 --- a/nfc/java/android/nfc/cardemulation/CardEmulation.java +++ b/nfc/java/android/nfc/cardemulation/CardEmulation.java @@ -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())); } /** diff --git a/nfc/java/android/nfc/flags.aconfig b/nfc/java/android/nfc/flags.aconfig index 4d70d4acb42e..468147fc6f33 100644 --- a/nfc/java/android/nfc/flags.aconfig +++ b/nfc/java/android/nfc/flags.aconfig @@ -132,3 +132,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" +} |