summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author James Willcox <jwillcox@google.com> 2024-01-19 22:51:25 +0000
committer James Willcox <jwillcox@google.com> 2024-01-22 22:32:41 +0000
commit7a57a3b07bc4f594ddd98b4085173db0138d3d31 (patch)
tree57d7e4e57e0d89a2c7c30dabf1944c43d5a70b67
parente8c4c3b0473637584e1cc55020f8aa3f323972d4 (diff)
Use a static getter to fetch the preferred payment setting
We need to use this from the system server before the NFC service has started. This makes getting an instance of `CardEmulation` difficult, so instead make it into a static method and access the setting directly instead of via the service. Bug: 321098555 Test: manual,NFC CTS tests Change-Id: I92e7cfeb595a13b8d544b4a3169601748fef7101
-rw-r--r--nfc/api/system-current.txt2
-rw-r--r--nfc/java/android/nfc/cardemulation/CardEmulation.java35
2 files changed, 18 insertions, 19 deletions
diff --git a/nfc/api/system-current.txt b/nfc/api/system-current.txt
index 40672a1adc15..1e6b401b3741 100644
--- a/nfc/api/system-current.txt
+++ b/nfc/api/system-current.txt
@@ -45,7 +45,7 @@ package android.nfc {
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 android.nfc.cardemulation.ApduServiceInfo getPreferredPaymentService();
+ 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);
}
diff --git a/nfc/java/android/nfc/cardemulation/CardEmulation.java b/nfc/java/android/nfc/cardemulation/CardEmulation.java
index 81eab71fe080..22320f254f46 100644
--- a/nfc/java/android/nfc/cardemulation/CardEmulation.java
+++ b/nfc/java/android/nfc/cardemulation/CardEmulation.java
@@ -16,6 +16,7 @@
package android.nfc.cardemulation;
+import android.Manifest;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -23,6 +24,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
+import android.annotation.UserHandleAware;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.content.ComponentName;
@@ -1090,31 +1092,28 @@ public final class CardEmulation {
}
/**
- * Returns the {@link Settings.Secure#NFC_PAYMENT_DEFAULT_COMPONENT} for the given user.
+ * Returns the value of {@link Settings.Secure#NFC_PAYMENT_DEFAULT_COMPONENT}.
+ *
+ * @param context A context
+ * @return A ComponentName for the setting value, or null.
*
* @hide
*/
@SystemApi
+ @UserHandleAware
@RequiresPermission(android.Manifest.permission.NFC_PREFERRED_PAYMENT_INFO)
+ @SuppressWarnings("AndroidFrameworkClientSidePermissionCheck")
@FlaggedApi(android.permission.flags.Flags.FLAG_WALLET_ROLE_ENABLED)
@Nullable
- public ApduServiceInfo getPreferredPaymentService() {
- try {
- return sService.getPreferredPaymentService(mContext.getUser().getIdentifier());
- } catch (RemoteException e) {
- // Try one more time
- recoverService();
- if (sService == null) {
- Log.e(TAG, "Failed to recover CardEmulationService.");
- return null;
- }
- try {
- return sService.getPreferredPaymentService(mContext.getUser().getIdentifier());
- } catch (RemoteException ee) {
- Log.e(TAG, "Failed to reach CardEmulationService.");
- return null;
- }
+ public static ComponentName getPreferredPaymentService(@NonNull Context context) {
+ context.checkCallingOrSelfPermission(Manifest.permission.NFC_PREFERRED_PAYMENT_INFO);
+ String defaultPaymentComponent = Settings.Secure.getString(context.getContentResolver(),
+ Constants.SETTINGS_SECURE_NFC_PAYMENT_DEFAULT_COMPONENT);
+
+ if (defaultPaymentComponent == null) {
+ return null;
}
- }
+ return ComponentName.unflattenFromString(defaultPaymentComponent);
+ }
}