diff options
| author | Jack Yu <jackcwyu@google.com> | 2019-09-06 20:43:54 +0800 |
|---|---|---|
| committer | Jack Yu <jackcwyu@google.com> | 2019-12-12 20:08:18 +0800 |
| commit | 2dbf394181f4e5f907f1d1aaf48369cd3249c49f (patch) | |
| tree | e8e64dcdcc4a7ae5b41d2cea9051c18ecd73e451 /core/java/android | |
| parent | be64b53449fbe521650669f38e7d7342a5c7ecad (diff) | |
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
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/nfc/INfcCardEmulation.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 27 | ||||
| -rw-r--r-- | core/java/android/nfc/cardemulation/CardEmulation.java | 104 |
3 files changed, 130 insertions, 2 deletions
diff --git a/core/java/android/nfc/INfcCardEmulation.aidl b/core/java/android/nfc/INfcCardEmulation.aidl index dd2c0d4f9ee5..848b6d52c47f 100644 --- a/core/java/android/nfc/INfcCardEmulation.aidl +++ b/core/java/android/nfc/INfcCardEmulation.aidl @@ -39,4 +39,5 @@ interface INfcCardEmulation boolean setPreferredService(in ComponentName service); boolean unsetPreferredService(); boolean supportsAidPrefixRegistration(); + ApduServiceInfo getPreferredPaymentService(int userHandle); } diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index bc698f97738a..7ab984fc9275 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -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 @@ -164,6 +164,18 @@ public final class NfcAdapter { "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 diff --git a/core/java/android/nfc/cardemulation/CardEmulation.java b/core/java/android/nfc/cardemulation/CardEmulation.java index aa93611062f5..f1c74a6331c4 100644 --- a/core/java/android/nfc/cardemulation/CardEmulation.java +++ b/core/java/android/nfc/cardemulation/CardEmulation.java @@ -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; @@ -657,6 +658,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 */ public boolean setDefaultServiceForCategory(ComponentName service, String category) { |
