Use waitForService() istead of getService()
SystemManager.waitForService() is a system interface Bug: 244264995 Test: read a tag, on/off Change-Id: Ifcde87f4021238b4ebc67466f2d9b2e363586707
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user