Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1360c555 authored by Martijn Coenen's avatar Martijn Coenen
Browse files

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
parent 0aa212e3
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -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 */