summaryrefslogtreecommitdiffstats
path: root/core/java/android/nfc/NfcAdapter.java
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2010-10-18 11:19:41 -0700
committerNick Pelly <npelly@google.com>2010-10-18 11:52:28 -0700
commitfdf9086e24f4720ee9fbc852b980041f126aa3c2 (patch)
treee3aad92aad1e63e3baa7a8c5fc36c0310d5ba688 /core/java/android/nfc/NfcAdapter.java
parente47150e933e6f610546f57183477f324566e521e (diff)
downloadframeworks_base-fdf9086e24f4720ee9fbc852b980041f126aa3c2.zip
frameworks_base-fdf9086e24f4720ee9fbc852b980041f126aa3c2.tar.gz
frameworks_base-fdf9086e24f4720ee9fbc852b980041f126aa3c2.tar.bz2
Prevent use of NFC api if device is not featurized for NFC.
Change-Id: I8724cb947223b7b60814d0be51e1122123ebb98a Signed-off-by: Nick Pelly <npelly@google.com>
Diffstat (limited to 'core/java/android/nfc/NfcAdapter.java')
-rw-r--r--core/java/android/nfc/NfcAdapter.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 6f718d3..d76ac41 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -15,7 +15,10 @@ import java.lang.UnsupportedOperationException;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.app.ActivityThread;
import android.content.Context;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageManager;
import android.nfc.INfcAdapter;
import android.os.IBinder;
import android.os.RemoteException;
@@ -152,6 +155,26 @@ public final class NfcAdapter {
}
/**
+ * Helper to check if this device has FEATURE_NFC, but without using
+ * a context.
+ * Equivalent to
+ * context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)
+ */
+ private static boolean hasNfcFeature() {
+ IPackageManager pm = ActivityThread.getPackageManager();
+ if (pm == null) {
+ Log.e(TAG, "Cannot get package manager, assuming no NFC feature");
+ return false;
+ }
+ try {
+ return pm.hasSystemFeature(PackageManager.FEATURE_NFC);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Package manager query failed, assuming no NFC feature", e);
+ return false;
+ }
+ }
+
+ /**
* Get a handle to the default NFC Adapter on this Android device.
* <p>
* Most Android devices will only have one NFC Adapter (NFC Controller).
@@ -165,9 +188,16 @@ public final class NfcAdapter {
}
sIsInitialized = true;
+ /* is this device meant to have NFC */
+ if (!hasNfcFeature()) {
+ Log.v(TAG, "this device does not have NFC support");
+ return null;
+ }
+
+ /* get a handle to NFC service */
IBinder b = ServiceManager.getService("nfc");
if (b == null) {
- Log.d(TAG, "NFC Service not available");
+ Log.e(TAG, "could not retrieve NFC service");
return null;
}