diff options
| author | Omer Ozer <omerozer@google.com> | 2022-09-28 19:56:14 +0000 |
|---|---|---|
| committer | aoleary <seanm187@gmail.com> | 2025-10-07 19:02:48 +0000 |
| commit | dc4197d81617e6d417c5376683b516e5253e39df (patch) | |
| tree | 41fe2e541c3b3a840d60e3b5562d89e72d90ef21 /src/com/android/nfc/cardemulation/CardEmulationManager.java | |
| parent | ab1f4fd8c6db320475a46f5646ea9473eb7433e4 (diff) | |
CardEmulationManager will now filter for preinstalled apps so that only
pre-installed apps could be the default payment provider for the device
initially.
Test: Manual test
Bug: 212610736
(cherry picked from commit 93a78fc1a525a3d8d60e33caf446307044241770)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:ee659be677b0eb162912c42871f41ac9f59c4ef0)
Merged-In: Id062cdd685b066bab44dc48bfa57cc97ccc02b35
Change-Id: Id062cdd685b066bab44dc48bfa57cc97ccc02b35
Diffstat (limited to 'src/com/android/nfc/cardemulation/CardEmulationManager.java')
| -rw-r--r-- | src/com/android/nfc/cardemulation/CardEmulationManager.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/com/android/nfc/cardemulation/CardEmulationManager.java b/src/com/android/nfc/cardemulation/CardEmulationManager.java index d43f89a7..94e0af54 100644 --- a/src/com/android/nfc/cardemulation/CardEmulationManager.java +++ b/src/com/android/nfc/cardemulation/CardEmulationManager.java @@ -17,6 +17,9 @@ package com.android.nfc.cardemulation; import android.content.ComponentName; import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.nfc.INfcCardEmulation; import android.nfc.INfcFCardEmulation; import android.nfc.NfcAdapter; @@ -318,14 +321,23 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, + userIdDefaultPaymentService); } } - if (defaultPaymentService == null) { // A payment service may have been removed, leaving only one; // in that case, automatically set that app as default. int numPaymentServices = 0; ComponentName lastFoundPaymentService = null; + PackageManager pm; + try { + pm = mContext.createPackageContextAsUser("android", /*flags=*/0, + new UserHandle(userId)).getPackageManager(); + } catch (NameNotFoundException e) { + Log.e(TAG, "Could not create user package context"); + return; + } + for (ApduServiceInfo service : services) { - if (service.hasCategory(CardEmulation.CATEGORY_PAYMENT)) { + if (service.hasCategory(CardEmulation.CATEGORY_PAYMENT) + && wasServicePreInstalled(pm, service.getComponent())) { numPaymentServices++; lastFoundPaymentService = service.getComponent(); } @@ -347,6 +359,22 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, } } + boolean wasServicePreInstalled(PackageManager packageManager, ComponentName service) { + try { + ApplicationInfo ai = packageManager + .getApplicationInfo(service.getPackageName(), /*flags=*/0); + if ((ApplicationInfo.FLAG_SYSTEM & ai.flags) != 0) { + if (DBG) Log.d(TAG, "Service was pre-installed on the device"); + return true; + } + } catch (NameNotFoundException e) { + Log.e(TAG, "Service is not currently installed on the device."); + return false; + } + if (DBG) Log.d(TAG, "Service was not pre-installed on the device"); + return false; + } + ComponentName getDefaultServiceForCategory(int userId, String category, boolean validateInstalled) { if (!CardEmulation.CATEGORY_PAYMENT.equals(category)) { |
