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

Commit 80fb6d81 authored by Alisher Alikhodjaev's avatar Alisher Alikhodjaev Committed by Automerger Merge Worker
Browse files

Merge "Add separate checks for Tag Reading and Card Emulation is enabled."...

Merge "Add separate checks for Tag Reading and Card Emulation is enabled." into main am: 24c9102d am: 3aab8fa6 am: 36a0ba80 am: 8a9bd6ff am: 6579cbc9

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2699596



Change-Id: I2d84ca5cf2e9c667d7464327a4071a2c0994a192
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 361b0770 6579cbc9
Loading
Loading
Loading
Loading
+47 −19
Original line number Diff line number Diff line
@@ -642,6 +642,7 @@ public final class NfcAdapter {
                try {
                    sTagService = sService.getNfcTagInterface();
                } catch (RemoteException e) {
                    sTagService = null;
                    Log.e(TAG, "could not retrieve NFC Tag service");
                    throw new UnsupportedOperationException();
                }
@@ -650,12 +651,14 @@ public final class NfcAdapter {
                try {
                    sNfcFCardEmulationService = sService.getNfcFCardEmulationInterface();
                } catch (RemoteException e) {
                    sNfcFCardEmulationService = null;
                    Log.e(TAG, "could not retrieve NFC-F card emulation service");
                    throw new UnsupportedOperationException();
                }
                try {
                    sCardEmulationService = sService.getNfcCardEmulationInterface();
                } catch (RemoteException e) {
                    sCardEmulationService = null;
                    Log.e(TAG, "could not retrieve card emulation service");
                    throw new UnsupportedOperationException();
                }
@@ -839,30 +842,54 @@ public final class NfcAdapter {
        // assigning to sService is not thread-safe, but this is best-effort code
        // and on a well-behaved system should never happen
        sService = service;
        if (sHasNfcFeature) {
            try {
                sTagService = service.getNfcTagInterface();
            } catch (RemoteException ee) {
                sTagService = null;
                Log.e(TAG, "could not retrieve NFC tag service during service recovery");
                // nothing more can be done now, sService is still stale, we'll hit
                // this recovery path again later
                return;
            }
        }

        if (sHasCeFeature) {
            try {
                sCardEmulationService = service.getNfcCardEmulationInterface();
            } catch (RemoteException ee) {
            Log.e(TAG, "could not retrieve NFC card emulation service during service recovery");
                sCardEmulationService = null;
                Log.e(TAG,
                        "could not retrieve NFC card emulation service during service recovery");
            }

            try {
                sNfcFCardEmulationService = service.getNfcFCardEmulationInterface();
            } catch (RemoteException ee) {
            Log.e(TAG, "could not retrieve NFC-F card emulation service during service recovery");
                sNfcFCardEmulationService = null;
                Log.e(TAG,
                        "could not retrieve NFC-F card emulation service during service recovery");
            }
        }

        return;
    }

    private boolean isCardEmulationEnabled() {
        if (sHasCeFeature) {
            return (sCardEmulationService != null || sNfcFCardEmulationService != null);
        }
        return false;
    }

    private boolean isTagReadingEnabled() {
        if (sHasNfcFeature) {
            return sTagService != null;
        }
        return false;
    }


    /**
     * Return true if this NFC Adapter has any features enabled.
     *
@@ -876,8 +903,9 @@ public final class NfcAdapter {
     * @return true if this NFC Adapter has any features enabled
     */
    public boolean isEnabled() {
        boolean serviceState = false;
        try {
            return sService.getState() == STATE_ON;
            serviceState = sService.getState() == STATE_ON;
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            // Try one more time
@@ -886,12 +914,12 @@ public final class NfcAdapter {
                return false;
            }
            try {
                return sService.getState() == STATE_ON;
                serviceState = sService.getState() == STATE_ON;
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to recover NFC Service.");
            }
            return false;
        }
        return serviceState && (isTagReadingEnabled() || isCardEmulationEnabled());
    }

    /**