Skip to content

Commit a5193b2

Browse files
author
Nick Pelly
committed
Fix NPE on devices that don't have NFC.
We should return null instead of NPE. Bug: 5622939 Change-Id: I802f4a99ea9f5e73453d5ea30da4e1d9fa279b9c
1 parent 7dc81e0 commit a5193b2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

core/java/android/nfc/NfcAdapter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ public static NfcAdapter getDefaultAdapter(Context context) {
360360
/* use getSystemService() instead of just instantiating to take
361361
* advantage of the context's cached NfcManager & NfcAdapter */
362362
NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
363+
if (manager == null) {
364+
// NFC not available
365+
return null;
366+
}
363367
return manager.getDefaultAdapter();
364368
}
365369

0 commit comments

Comments
 (0)