From 1360c555a4e060be30a7a6a7916449441c1bf646 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Mon, 7 Jan 2013 16:34:20 -0800 Subject: [PATCH] Don't IPC for every onPause() in NfcActivityManager. The NfcService now contains additional code to make sure that the registered NDEF callback corresponds to the package running in the foreground. This allows us to stop calling the NfcService on every onPause() to register the NDEF callback, as NfcService itself will now detect that the app is no longer in the foreground, and won't call the callback. Bug: 5199662 Change-Id: Ibd0d21f8c7b76346238305a6684967263cb7d7e0 --- core/java/android/nfc/NfcActivityManager.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/java/android/nfc/NfcActivityManager.java b/core/java/android/nfc/NfcActivityManager.java index 53b41d5f42c2f..7c3123f449cfd 100644 --- a/core/java/android/nfc/NfcActivityManager.java +++ b/core/java/android/nfc/NfcActivityManager.java @@ -197,7 +197,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub isResumed = state.resumed; } if (isResumed) { - requestNfcServiceCallback(true); + requestNfcServiceCallback(); } } @@ -211,7 +211,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub isResumed = state.resumed; } if (isResumed) { - requestNfcServiceCallback(true); + requestNfcServiceCallback(); } } @@ -223,7 +223,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub isResumed = state.resumed; } if (isResumed) { - requestNfcServiceCallback(true); + requestNfcServiceCallback(); } } @@ -236,7 +236,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub isResumed = state.resumed; } if (isResumed) { - requestNfcServiceCallback(true); + requestNfcServiceCallback(); } } @@ -249,18 +249,17 @@ public final class NfcActivityManager extends INdefPushCallback.Stub isResumed = state.resumed; } if (isResumed) { - requestNfcServiceCallback(true); + requestNfcServiceCallback(); } } /** * Request or unrequest NFC service callbacks for NDEF push. * Makes IPC call - do not hold lock. - * TODO: Do not do IPC on every onPause/onResume */ - void requestNfcServiceCallback(boolean request) { + void requestNfcServiceCallback() { try { - NfcAdapter.sService.setNdefPushCallback(request ? this : null); + NfcAdapter.sService.setNdefPushCallback(this); } catch (RemoteException e) { mAdapter.attemptDeadServiceRecovery(e); } @@ -355,7 +354,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub if (state == null) return; state.resumed = true; } - requestNfcServiceCallback(true); + requestNfcServiceCallback(); } /** Callback from Activity life-cycle, on main thread */ @@ -367,7 +366,6 @@ public final class NfcActivityManager extends INdefPushCallback.Stub if (state == null) return; state.resumed = false; } - requestNfcServiceCallback(false); } /** Callback from Activity life-cycle, on main thread */