From 4dfa2fb12ed6b9a6e17d0485f0f33133acc2cd0f Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Wed, 15 Mar 2023 17:52:34 +0000 Subject: [PATCH 1/2] Revert^2 "nfc(api): Remove fg checks from API class" 12fed4b17adb0605998c7609d068ff652363589f Bug: 263565738 Test: Compiles Change-Id: Ia141063d564e47f1ca394e15316d72470f23e951 --- core/java/android/nfc/NfcAdapter.java | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 6dc80cf4c374c..611df0a4ea90c 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -26,8 +26,6 @@ import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.UserIdInt; import android.app.Activity; -import android.app.ActivityThread; -import android.app.OnActivityPausedListener; import android.app.PendingIntent; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -1570,17 +1568,11 @@ public final class NfcAdapter { if (activity == null || intent == null) { throw new NullPointerException(); } - if (!activity.isResumed()) { - throw new IllegalStateException("Foreground dispatch can only be enabled " + - "when your activity is resumed"); - } try { TechListParcel parcel = null; if (techLists != null && techLists.length > 0) { parcel = new TechListParcel(techLists); } - ActivityThread.currentActivityThread().registerOnActivityPausedListener(activity, - mForegroundDispatchListener); sService.setForegroundDispatch(intent, filters, parcel); } catch (RemoteException e) { attemptDeadServiceRecovery(e); @@ -1608,25 +1600,8 @@ public final class NfcAdapter { throw new UnsupportedOperationException(); } } - ActivityThread.currentActivityThread().unregisterOnActivityPausedListener(activity, - mForegroundDispatchListener); - disableForegroundDispatchInternal(activity, false); - } - - OnActivityPausedListener mForegroundDispatchListener = new OnActivityPausedListener() { - @Override - public void onPaused(Activity activity) { - disableForegroundDispatchInternal(activity, true); - } - }; - - void disableForegroundDispatchInternal(Activity activity, boolean force) { try { sService.setForegroundDispatch(null, null, null); - if (!force && !activity.isResumed()) { - throw new IllegalStateException("You must disable foreground dispatching " + - "while your activity is still resumed"); - } } catch (RemoteException e) { attemptDeadServiceRecovery(e); } From 7bf3becc98706029401a82b46b2bb37088667fbd Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 24 Feb 2023 10:43:45 -0800 Subject: [PATCH 2/2] nfc(api): Remove isResumed checks from API class Similar to aosp/2448864, checks for isResumed() is somewhat redundant since we enforce that only fg apps can use this API. Bug: 263565738 Test: atest CtsNfcTestCases Test: CtsVerifier tag tests Change-Id: Ib354cb2d8a81cd0a461ac3807daf8adee980c93e --- core/java/android/nfc/cardemulation/CardEmulation.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/java/android/nfc/cardemulation/CardEmulation.java b/core/java/android/nfc/cardemulation/CardEmulation.java index ac3344e91c062..4909b0830eebd 100644 --- a/core/java/android/nfc/cardemulation/CardEmulation.java +++ b/core/java/android/nfc/cardemulation/CardEmulation.java @@ -594,9 +594,6 @@ public final class CardEmulation { if (activity == null || service == null) { throw new NullPointerException("activity or service or category is null"); } - if (!activity.isResumed()) { - throw new IllegalArgumentException("Activity must be resumed."); - } try { return sService.setPreferredService(service); } catch (RemoteException e) { @@ -629,9 +626,6 @@ public final class CardEmulation { if (activity == null) { throw new NullPointerException("activity is null"); } - if (!activity.isResumed()) { - throw new IllegalArgumentException("Activity must be resumed."); - } try { return sService.unsetPreferredService(); } catch (RemoteException e) {