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

Commit a8c470fb authored by Alisher Alikhodjaev's avatar Alisher Alikhodjaev
Browse files

Use waitForService() istead of getService()

SystemManager.waitForService() is a system interface

Bug: 244264995
Test: read a tag, on/off
Change-Id: Ifcde87f4021238b4ebc67466f2d9b2e363586707
parent ecdc6a3e
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -565,8 +565,7 @@ public final class NfcAdapter {
            return sNullContextNfcAdapter;
        }
        if (!sIsInitialized) {
            PackageManager pm;
            pm = context.getPackageManager();
            PackageManager pm = context.getPackageManager();
            sHasNfcFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC);
            sHasBeamFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM);
            boolean hasHceFeature =
@@ -617,8 +616,12 @@ public final class NfcAdapter {

    /** get handle to NFC service interface */
    private static INfcAdapter getServiceInterface() {
        if (!sHasNfcFeature) {
            /* NFC is not supported */
            return null;
        }
        /* get a handle to NFC service */
        IBinder b = ServiceManager.getService("nfc");
        IBinder b = ServiceManager.waitForService("nfc");
        if (b == null) {
            return null;
        }
@@ -648,6 +651,15 @@ public final class NfcAdapter {
                    "context not associated with any application (using a mock context?)");
        }

        synchronized (NfcAdapter.class) {
            if (!sIsInitialized) {
                PackageManager pm = context.getPackageManager();
                sHasNfcFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC);
            }
            if (!sHasNfcFeature) {
                return null;
            }
        }
        if (getServiceInterface() == null) {
            // NFC is not available
            return null;