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

Commit cee040eb authored by Nick Pelly's avatar Nick Pelly Committed by Android (Google) Code Review
Browse files

Merge "Throw a nicer error message when using an invalid context to create Nfc"

parents afb1a9e2 b04cce0e
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -357,8 +357,11 @@ public final class NfcAdapter {
            throw new IllegalArgumentException("context cannot be null");
        }
        context = context.getApplicationContext();
        /* use getSystemService() instead of just instantiating to take
         * advantage of the context's cached NfcManager & NfcAdapter */
        if (context == null) {
            throw new IllegalArgumentException(
                    "context not associated with any application (using a mock context?)");
        }
        /* use getSystemService() for consistency */
        NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
        if (manager == null) {
            // NFC not available
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ public final class NfcManager {
    public NfcManager(Context context) {
        NfcAdapter adapter;
        context = context.getApplicationContext();
        if (context == null) {
            throw new IllegalArgumentException(
                    "context not associated with any application (using a mock context?)");
        }
        try {
            adapter = NfcAdapter.getNfcAdapter(context);
        } catch (UnsupportedOperationException e) {