Merge "Revert "nfc(api): Remove fg checks from API class"" am: fb519f3324 am: 7230f4cbbc
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2470700 Change-Id: Icfa008f132633a6a876a5c02404f5a343bd6c171 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -26,6 +26,8 @@ import android.annotation.SdkConstant.SdkConstantType;
|
|||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityThread;
|
||||||
|
import android.app.OnActivityPausedListener;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -1575,11 +1577,17 @@ public final class NfcAdapter {
|
|||||||
if (activity == null || intent == null) {
|
if (activity == null || intent == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
if (!activity.isResumed()) {
|
||||||
|
throw new IllegalStateException("Foreground dispatch can only be enabled " +
|
||||||
|
"when your activity is resumed");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
TechListParcel parcel = null;
|
TechListParcel parcel = null;
|
||||||
if (techLists != null && techLists.length > 0) {
|
if (techLists != null && techLists.length > 0) {
|
||||||
parcel = new TechListParcel(techLists);
|
parcel = new TechListParcel(techLists);
|
||||||
}
|
}
|
||||||
|
ActivityThread.currentActivityThread().registerOnActivityPausedListener(activity,
|
||||||
|
mForegroundDispatchListener);
|
||||||
sService.setForegroundDispatch(intent, filters, parcel);
|
sService.setForegroundDispatch(intent, filters, parcel);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
attemptDeadServiceRecovery(e);
|
attemptDeadServiceRecovery(e);
|
||||||
@@ -1607,8 +1615,25 @@ public final class NfcAdapter {
|
|||||||
throw new UnsupportedOperationException();
|
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 {
|
try {
|
||||||
sService.setForegroundDispatch(null, null, null);
|
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) {
|
} catch (RemoteException e) {
|
||||||
attemptDeadServiceRecovery(e);
|
attemptDeadServiceRecovery(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user