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

Commit 2dbf3941 authored by Jack Yu's avatar Jack Yu
Browse files

Provide APIs to get preferred payment service information

Provide APIs to get current preferred payment service information:
1. AID list
2. RouteDestination
3. Description
APIs would be guarded by a new permission.

Bug:139790381
Test: Build pass
Change-Id: I1a4fff5fee58f6e5d6727319cff9ad90e55fc767
parent be64b534
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ package android {
    field public static final String MOUNT_FORMAT_FILESYSTEMS = "android.permission.MOUNT_FORMAT_FILESYSTEMS";
    field public static final String MOUNT_UNMOUNT_FILESYSTEMS = "android.permission.MOUNT_UNMOUNT_FILESYSTEMS";
    field public static final String NFC = "android.permission.NFC";
    field public static final String NFC_PREFERRED_PAYMENT_INFO = "android.permission.NFC_PREFERRED_PAYMENT_INFO";
    field public static final String NFC_TRANSACTION_EVENT = "android.permission.NFC_TRANSACTION_EVENT";
    field public static final String PACKAGE_USAGE_STATS = "android.permission.PACKAGE_USAGE_STATS";
    field @Deprecated public static final String PERSISTENT_ACTIVITY = "android.permission.PERSISTENT_ACTIVITY";
@@ -30707,6 +30708,7 @@ package android.nfc {
    method @Deprecated public void setOnNdefPushCompleteCallback(android.nfc.NfcAdapter.OnNdefPushCompleteCallback, android.app.Activity, android.app.Activity...);
    field public static final String ACTION_ADAPTER_STATE_CHANGED = "android.nfc.action.ADAPTER_STATE_CHANGED";
    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";
    field public static final String ACTION_TECH_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
    field @RequiresPermission(android.Manifest.permission.NFC_TRANSACTION_EVENT) public static final String ACTION_TRANSACTION_DETECTED = "android.nfc.action.TRANSACTION_DETECTED";
@@ -30715,6 +30717,7 @@ package android.nfc {
    field public static final String EXTRA_DATA = "android.nfc.extra.DATA";
    field public static final String EXTRA_ID = "android.nfc.extra.ID";
    field public static final String EXTRA_NDEF_MESSAGES = "android.nfc.extra.NDEF_MESSAGES";
    field public static final String EXTRA_PREFERRED_PAYMENT_CHANGED_REASON = "android.nfc.extra.PREFERRED_PAYMENT_CHANGED_REASON";
    field public static final String EXTRA_READER_PRESENCE_CHECK_DELAY = "presence";
    field public static final String EXTRA_SECURE_ELEMENT_NAME = "android.nfc.extra.SECURE_ELEMENT_NAME";
    field public static final String EXTRA_TAG = "android.nfc.extra.TAG";
@@ -30725,6 +30728,9 @@ package android.nfc {
    field public static final int FLAG_READER_NFC_V = 8; // 0x8
    field public static final int FLAG_READER_NO_PLATFORM_SOUNDS = 256; // 0x100
    field public static final int FLAG_READER_SKIP_NDEF_CHECK = 128; // 0x80
    field public static final int PREFERRED_PAYMENT_CHANGED = 2; // 0x2
    field public static final int PREFERRED_PAYMENT_LOADED = 1; // 0x1
    field public static final int PREFERRED_PAYMENT_UPDATED = 3; // 0x3
    field public static final int STATE_OFF = 1; // 0x1
    field public static final int STATE_ON = 3; // 0x3
    field public static final int STATE_TURNING_OFF = 4; // 0x4
@@ -30780,8 +30786,11 @@ package android.nfc.cardemulation {
  public final class CardEmulation {
    method public boolean categoryAllowsForegroundPreference(String);
    method @Nullable @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO) public java.util.List<java.lang.String> getAidsForPreferredPaymentService();
    method public java.util.List<java.lang.String> getAidsForService(android.content.ComponentName, String);
    method @Nullable @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO) public String getDescriptionForPreferredPaymentService();
    method public static android.nfc.cardemulation.CardEmulation getInstance(android.nfc.NfcAdapter);
    method @Nullable @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO) public String getRouteDestinationForPreferredPaymentService();
    method public int getSelectionModeForCategory(String);
    method public boolean isDefaultServiceForAid(android.content.ComponentName, String);
    method public boolean isDefaultServiceForCategory(android.content.ComponentName, String);
+1 −0
Original line number Diff line number Diff line
@@ -39,4 +39,5 @@ interface INfcCardEmulation
    boolean setPreferredService(in ComponentName service);
    boolean unsetPreferredService();
    boolean supportsAidPrefixRegistration();
    ApduServiceInfo getPreferredPaymentService(int userHandle);
}
+25 −2
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ public final class NfcAdapter {
    public static final String ACTION_TAG_DISCOVERED = "android.nfc.action.TAG_DISCOVERED";

    /**
     * Broadcast Action: Intent to notify an application that an transaction event has occurred
     * Broadcast Action: Intent to notify an application that a transaction event has occurred
     * on the Secure Element.
     *
     * <p>This intent will only be sent if the application has requested permission for
@@ -163,6 +163,18 @@ public final class NfcAdapter {
    public static final String ACTION_TRANSACTION_DETECTED =
            "android.nfc.action.TRANSACTION_DETECTED";

    /**
     * Broadcast Action: Intent to notify if the preferred payment service changed.
     *
     * <p>This intent will only be sent to the application has requested permission for
     * {@link android.Manifest.permission#NFC_PREFERRED_PAYMENT_INFO} and if the application
     * has the necessary access to Secure Element which witnessed the particular event.
     */
    @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_PREFERRED_PAYMENT_CHANGED =
            "android.nfc.action.PREFERRED_PAYMENT_CHANGED";

    /**
     * Broadcast to only the activity that handles ACTION_TAG_DISCOVERED
     * @hide
@@ -231,6 +243,17 @@ public final class NfcAdapter {
     */
    public static final String EXTRA_SECURE_ELEMENT_NAME = "android.nfc.extra.SECURE_ELEMENT_NAME";

    /**
     * Mandatory String extra field in {@link #ACTION_PREFERRED_PAYMENT_CHANGED}
     * Indicates the condition when trigger this event.
     */
    public static final String EXTRA_PREFERRED_PAYMENT_CHANGED_REASON =
            "android.nfc.extra.PREFERRED_PAYMENT_CHANGED_REASON";

    public static final int PREFERRED_PAYMENT_LOADED = 1;
    public static final int PREFERRED_PAYMENT_CHANGED = 2;
    public static final int PREFERRED_PAYMENT_UPDATED = 3;

    public static final int STATE_OFF = 1;
    public static final int STATE_TURNING_ON = 2;
    public static final int STATE_ON = 3;
@@ -1410,7 +1433,7 @@ public final class NfcAdapter {
    /**
     * Enable foreground dispatch to the given Activity.
     *
     * <p>This will give give priority to the foreground activity when
     * <p>This will give priority to the foreground activity when
     * dispatching a discovered {@link Tag} to an application.
     *
     * <p>If any IntentFilters are provided to this method they are used to match dispatch Intents
+104 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.nfc.cardemulation;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -656,6 +657,109 @@ public final class CardEmulation {
        }
    }

    /**
     * Retrieves the registered AIDs for the preferred payment service.
     *
     * @return The list of AIDs registered for this category, or null if it couldn't be found.
     */
    @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
    @Nullable
    public List<String> getAidsForPreferredPaymentService() {
        try {
            ApduServiceInfo serviceInfo = sService.getPreferredPaymentService(mContext.getUserId());
            return (serviceInfo != null ? serviceInfo.getAids() : null);
        } catch (RemoteException e) {
            recoverService();
            if (sService == null) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return null;
            }
            try {
                ApduServiceInfo serviceInfo =
                        sService.getPreferredPaymentService(mContext.getUserId());
                return (serviceInfo != null ? serviceInfo.getAids() : null);
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return null;
            }
        }
    }

    /**
     * Retrieves the route destination for the preferred payment service.
     *
     * @return The route destination secure element name of the preferred payment service.
     *         HCE payment: "Host"
     *         OffHost payment: prefix SIM or prefix eSE string.
     *                          "OffHost" if the payment service does not specify secure element
     *                          name.
     */
    @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
    @Nullable
    public String getRouteDestinationForPreferredPaymentService() {
        try {
            ApduServiceInfo serviceInfo = sService.getPreferredPaymentService(mContext.getUserId());
            if (serviceInfo != null) {
                if (!serviceInfo.isOnHost()) {
                    return serviceInfo.getOffHostSecureElement() == null ?
                            "OffHost" : serviceInfo.getOffHostSecureElement();
                }
                return "Host";
            }
            return null;
        } catch (RemoteException e) {
            recoverService();
            if (sService == null) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return null;
            }
            try {
                ApduServiceInfo serviceInfo =
                        sService.getPreferredPaymentService(mContext.getUserId());
                if (serviceInfo != null) {
                    if (!serviceInfo.isOnHost()) {
                        return serviceInfo.getOffHostSecureElement() == null ?
                                "Offhost" : serviceInfo.getOffHostSecureElement();
                    }
                    return "Host";
                }
                return null;

            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return null;
            }
        }
    }

    /**
     * Returns a user-visible description of the preferred payment service.
     *
     * @return the preferred payment service description
     */
    @RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
    @Nullable
    public String getDescriptionForPreferredPaymentService() {
        try {
            ApduServiceInfo serviceInfo = sService.getPreferredPaymentService(mContext.getUserId());
            return (serviceInfo != null ? serviceInfo.getDescription() : null);
        } catch (RemoteException e) {
            recoverService();
            if (sService == null) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return null;
            }
            try {
                ApduServiceInfo serviceInfo =
                        sService.getPreferredPaymentService(mContext.getUserId());
                return (serviceInfo != null ? serviceInfo.getDescription() : null);
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return null;
            }
        }
    }

    /**
     * @hide
     */
+9 −0
Original line number Diff line number Diff line
@@ -306,6 +306,7 @@
    <protected-broadcast android:name="android.net.nsd.STATE_CHANGED" />

    <protected-broadcast android:name="android.nfc.action.ADAPTER_STATE_CHANGED" />
    <protected-broadcast android:name="android.nfc.action.PREFERRED_PAYMENT_CHANGED" />
    <protected-broadcast android:name="android.nfc.action.TRANSACTION_DETECTED" />
    <protected-broadcast android:name="com.android.nfc.action.LLCP_UP" />
    <protected-broadcast android:name="com.android.nfc.action.LLCP_DOWN" />
@@ -1769,6 +1770,14 @@
    <permission android:name="android.permission.NFC_TRANSACTION_EVENT"
      android:protectionLevel="normal" />

    <!-- Allows applications to receive NFC preferred payment service information.
         <p>Protection level: normal
    -->
    <permission android:name="android.permission.NFC_PREFERRED_PAYMENT_INFO"
        android:description="@string/permdesc_preferredPaymentInfo"
        android:label="@string/permlab_preferredPaymentInfo"
        android:protectionLevel="normal" />

    <!-- @deprecated This permission used to allow too broad access to sensitive methods and all its
         uses have been replaced by a more appropriate permission. Most uses have been replaced with
         a NETWORK_STACK or NETWORK_SETTINGS check. Please look up the documentation of the
Loading