summaryrefslogtreecommitdiff
path: root/src/com/android/nfc/cardemulation/CardEmulationManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/nfc/cardemulation/CardEmulationManager.java')
-rw-r--r--src/com/android/nfc/cardemulation/CardEmulationManager.java48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/com/android/nfc/cardemulation/CardEmulationManager.java b/src/com/android/nfc/cardemulation/CardEmulationManager.java
index 872ceb84..75c08c42 100644
--- a/src/com/android/nfc/cardemulation/CardEmulationManager.java
+++ b/src/com/android/nfc/cardemulation/CardEmulationManager.java
@@ -30,6 +30,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
+import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
@@ -240,9 +241,10 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback,
}
@Override
- public void onServicesUpdated(int userId, List<ApduServiceInfo> services) {
- // Verify defaults are still sane
- verifyDefaults(userId, services);
+ public void onServicesUpdated(int userId, List<ApduServiceInfo> services,
+ boolean validateInstalled) {
+ // Verify defaults are still the same
+ verifyDefaults(userId, services, validateInstalled);
// Update the AID cache
mAidCache.onServicesUpdated(userId, services);
// Update the preferred services list
@@ -259,10 +261,40 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback,
mEnabledNfcFServices.onServicesUpdated();
}
- void verifyDefaults(int userId, List<ApduServiceInfo> services) {
- ComponentName defaultPaymentService =
- getDefaultServiceForCategory(userId, CardEmulation.CATEGORY_PAYMENT, true);
- if (DBG) Log.d(TAG, "Current default: " + defaultPaymentService + " for user:" + userId);
+ void verifyDefaults(int userId, List<ApduServiceInfo> services, boolean validateInstalled) {
+ UserManager um = mContext.createContextAsUser(
+ UserHandle.of(userId), /*flags=*/0).getSystemService(UserManager.class);
+ List<UserHandle> luh = um.getEnabledProfiles();
+
+ ComponentName defaultPaymentService = null;
+ int numDefaultPaymentServices = 0;
+ int userIdDefaultPaymentService = userId;
+
+ for (UserHandle uh : luh) {
+ ComponentName paymentService = getDefaultServiceForCategory(uh.getIdentifier(),
+ CardEmulation.CATEGORY_PAYMENT,
+ validateInstalled && (uh.getIdentifier() == userId));
+ if (DBG) Log.d(TAG, "default: " + paymentService + " for user:" + uh);
+ if (paymentService != null) {
+ numDefaultPaymentServices++;
+ defaultPaymentService = paymentService;
+ userIdDefaultPaymentService = uh.getIdentifier();
+ }
+ }
+ if (numDefaultPaymentServices > 1) {
+ Log.e(TAG, "Current default is not aligned across multiple users");
+ // leave default unset
+ for (UserHandle uh : luh) {
+ setDefaultServiceForCategoryChecked(uh.getIdentifier(), null,
+ CardEmulation.CATEGORY_PAYMENT);
+ }
+ } else {
+ if (DBG) {
+ Log.d(TAG, "Current default: " + defaultPaymentService + " for user:"
+ + userIdDefaultPaymentService);
+ }
+ }
+
if (defaultPaymentService == null) {
// A payment service may have been removed, leaving only one;
// in that case, automatically set that app as default.
@@ -341,7 +373,7 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback,
// calls to our APIs referencing that service to fail.
// Hence, update the cache in case we don't know about the service.
if (DBG) Log.d(TAG, "Didn't find passed in service, invalidating cache.");
- mServiceCache.invalidateCache(userId);
+ mServiceCache.invalidateCache(userId, true);
}
return mServiceCache.hasService(userId, service);
}