summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Yu <jackcwyu@google.com>2022-04-20 15:58:56 +0800
committerJack Yu <jackcwyu@google.com>2022-04-26 09:29:01 +0000
commit1e786df0602cd34335ba93c8e2a1517995fc6e84 (patch)
treea423cea5e16fee357de409ec614269b96dd6356a
parentb3446b876a8feae22ceb2ec74903656d63b36065 (diff)
downloadNfc-1e786df0602cd34335ba93c8e2a1517995fc6e84.tar.gz
Correct the default payment selection for multiple profiles
In multiple profiles condition, check the default payment selection in all profiles before assigning a new one. Bug: 221561126 Test: manual Change-Id: Iecb842f1345270e1bd72d3f258bc10b722f7c1e4
-rw-r--r--src/com/android/nfc/cardemulation/CardEmulationManager.java48
-rw-r--r--src/com/android/nfc/cardemulation/RegisteredServicesCache.java30
2 files changed, 61 insertions, 17 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);
}
diff --git a/src/com/android/nfc/cardemulation/RegisteredServicesCache.java b/src/com/android/nfc/cardemulation/RegisteredServicesCache.java
index 5cfa5462..313f16a4 100644
--- a/src/com/android/nfc/cardemulation/RegisteredServicesCache.java
+++ b/src/com/android/nfc/cardemulation/RegisteredServicesCache.java
@@ -91,7 +91,11 @@ public class RegisteredServicesCache {
final AtomicFile mDynamicSettingsFile;
public interface Callback {
- void onServicesUpdated(int userId, final List<ApduServiceInfo> services);
+ /**
+ * ServicesUpdated for specific userId.
+ */
+ void onServicesUpdated(int userId, List<ApduServiceInfo> services,
+ boolean validateInstalled);
};
static class DynamicSettings {
@@ -150,7 +154,11 @@ public class RegisteredServicesCache {
if (!replaced) {
int currentUser = ActivityManager.getCurrentUser();
if (currentUser == getProfileParentId(UserHandle.getUserId(uid))) {
- invalidateCache(UserHandle.getUserId(uid));
+ if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
+ invalidateCache(UserHandle.getUserId(uid), true);
+ } else {
+ invalidateCache(UserHandle.getUserId(uid), false);
+ }
} else {
// Cache will automatically be updated on user switch
}
@@ -186,7 +194,7 @@ public class RegisteredServicesCache {
synchronized (mLock) {
readDynamicSettingsLocked();
for (UserHandle uh : mUserHandles) {
- invalidateCache(uh.getIdentifier());
+ invalidateCache(uh.getIdentifier(), false);
}
}
}
@@ -317,7 +325,10 @@ public class RegisteredServicesCache {
return validServices;
}
- public void invalidateCache(int userId) {
+ /**
+ * invalidateCache for specific userId.
+ */
+ public void invalidateCache(int userId, boolean validateInstalled) {
final ArrayList<ApduServiceInfo> validServices = getInstalledServices(userId);
if (validServices == null) {
return;
@@ -371,7 +382,8 @@ public class RegisteredServicesCache {
writeDynamicSettingsLocked();
}
}
- mCallback.onServicesUpdated(userId, Collections.unmodifiableList(validServices));
+ mCallback.onServicesUpdated(userId, Collections.unmodifiableList(validServices),
+ validateInstalled);
dump(validServices);
}
@@ -539,7 +551,7 @@ public class RegisteredServicesCache {
newServices = new ArrayList<ApduServiceInfo>(services.services.values());
}
// Make callback without the lock held
- mCallback.onServicesUpdated(userId, newServices);
+ mCallback.onServicesUpdated(userId, newServices, true);
return true;
}
@@ -580,7 +592,7 @@ public class RegisteredServicesCache {
newServices = new ArrayList<ApduServiceInfo>(services.services.values());
}
// Make callback without the lock held
- mCallback.onServicesUpdated(userId, newServices);
+ mCallback.onServicesUpdated(userId, newServices, true);
return true;
}
@@ -633,7 +645,7 @@ public class RegisteredServicesCache {
}
if (success) {
// Make callback without the lock held
- mCallback.onServicesUpdated(userId, newServices);
+ mCallback.onServicesUpdated(userId, newServices, true);
}
return success;
}
@@ -690,7 +702,7 @@ public class RegisteredServicesCache {
}
}
if (success) {
- mCallback.onServicesUpdated(userId, newServices);
+ mCallback.onServicesUpdated(userId, newServices, true);
}
return success;
}