summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-08-24 19:30:32 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-08-24 19:30:32 +0000
commit9583aec2abf876d231d400ce22f6d470320b2af7 (patch)
tree383e615bef708b603e2d794848444f7d7d1a1e71
parent50c93d48f0878610efec49b714cc1f90699d5078 (diff)
parente39b954415741e1dd365ec700f8c139d2eab6b29 (diff)
Merge "nfc(api): Restore behavior from Android T (follow-up)" into main am: 34b915e141 am: e39b954415
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2721505 Change-Id: I2703eff45ea12a7bc2309a11108604623f69b95b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--core/java/android/nfc/NfcAdapter.java30
1 files changed, 19 insertions, 11 deletions
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 36199e522520..a9eb672c4e4d 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -600,6 +600,17 @@ public final class NfcAdapter {
return offHostSE;
}
+ private static void retrieveServiceRegisterer() {
+ if (sServiceRegisterer == null) {
+ NfcServiceManager manager = NfcFrameworkInitializer.getNfcServiceManager();
+ if (manager == null) {
+ Log.e(TAG, "NfcServiceManager is null");
+ throw new UnsupportedOperationException();
+ }
+ sServiceRegisterer = manager.getNfcManagerServiceRegisterer();
+ }
+ }
+
/**
* Returns the NfcAdapter for application context,
* or throws if NFC is not available.
@@ -627,12 +638,7 @@ public final class NfcAdapter {
Log.v(TAG, "this device does not have NFC support");
throw new UnsupportedOperationException();
}
- NfcServiceManager manager = NfcFrameworkInitializer.getNfcServiceManager();
- if (manager == null) {
- Log.e(TAG, "NfcServiceManager is null");
- throw new UnsupportedOperationException();
- }
- sServiceRegisterer = manager.getNfcManagerServiceRegisterer();
+ retrieveServiceRegisterer();
sService = getServiceInterface();
if (sService == null) {
Log.e(TAG, "could not retrieve NFC service");
@@ -706,11 +712,13 @@ public final class NfcAdapter {
throw new IllegalArgumentException(
"context not associated with any application (using a mock context?)");
}
-
- if (sIsInitialized && sServiceRegisterer.tryGet() == null) {
- synchronized (NfcAdapter.class) {
- /* Stale sService pointer */
- if (sIsInitialized) sIsInitialized = false;
+ retrieveServiceRegisterer();
+ if (sServiceRegisterer.tryGet() == null) {
+ if (sIsInitialized) {
+ synchronized (NfcAdapter.class) {
+ /* Stale sService pointer */
+ if (sIsInitialized) sIsInitialized = false;
+ }
}
return null;
}