aboutsummaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorAyush Raj <ayush.raj@nxp.com>2019-07-31 14:01:33 +0530
committernxf35421 <sangeetha.agarwal@nxp.com>2019-08-14 15:32:35 +0530
commitbc4947e6ea49409287ecbc7751563c9401722ff4 (patch)
treef4d8770997b5583e6d7d70a4546aae115b1a8493 /src/com
parent77d14be33e7f00307c41170ae1abd7e30ffb430a (diff)
downloadandroid_vendor_nxp_opensource_packages_apps_Nfc-bc4947e6ea49409287ecbc7751563c9401722ff4.tar.gz
android_vendor_nxp_opensource_packages_apps_Nfc-bc4947e6ea49409287ecbc7751563c9401722ff4.tar.bz2
android_vendor_nxp_opensource_packages_apps_Nfc-bc4947e6ea49409287ecbc7751563c9401722ff4.zip
Nfc enable and disable API synchronized.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/nfc/NfcService.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 351babe3..f98272ae 100644
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -316,6 +316,12 @@ public class NfcService implements DeviceHostListener {
// Timeout to re-apply routing if a tag was present and we postponed it
private static final int APPLY_ROUTING_RETRY_TIMEOUT_MS = 5000;
+ // these states are for making enable and disable nfc atomic
+ private int NXP_NFC_STATE_OFF = 0;
+ private int NXP_NFC_STATE_TURNING_ON = 1;
+ private int NXP_NFC_STATE_ON = 2;
+ private int NXP_NFC_STATE_TURNING_OFF = 3;
+
// eSE handle
public static final int EE_HANDLE_0xF3 = 0x4C0;
@@ -385,6 +391,8 @@ public class NfcService implements DeviceHostListener {
// and the default AsyncTask thread so it is read unprotected from that
// thread
int mState; // one of NfcAdapter.STATE_ON, STATE_TURNING_ON, etc
+ int mNxpNfcState = NXP_NFC_STATE_OFF;
+
// fields below are final after onCreate()
Context mContext;
private DeviceHost mDeviceHost;
@@ -1020,6 +1028,9 @@ public class NfcService implements DeviceHostListener {
commitRouting();
/* WiredSe Init after ESE is discovered and initialised */
initWiredSe();
+ synchronized (NfcService.this) {
+ mNxpNfcState = NXP_NFC_STATE_ON;
+ }
return true;
}
@@ -1068,6 +1079,7 @@ public class NfcService implements DeviceHostListener {
synchronized (NfcService.this) {
mCurrentDiscoveryParameters = NfcDiscoveryParameters.getNfcOffParameters();
updateState(NfcAdapter.STATE_OFF);
+ mNxpNfcState = NXP_NFC_STATE_OFF;
}
releaseSoundPool();
return result;
@@ -1152,6 +1164,14 @@ public class NfcService implements DeviceHostListener {
final class NfcAdapterService extends INfcAdapter.Stub {
@Override
public boolean enable() throws RemoteException {
+ synchronized (NfcService.this) {
+ if (mNxpNfcState != NXP_NFC_STATE_OFF) {
+ Log.e(TAG, "mNxpNfcStateis not equal to NXP_NFC_STATE_OFF."
+ + " Enable NFC Rejected.");
+ return false;
+ }
+ mNxpNfcState = NXP_NFC_STATE_TURNING_ON;
+ }
NfcPermissions.enforceAdminPermissions(mContext);
saveNfcOnSetting(true);
@@ -1171,6 +1191,14 @@ public class NfcService implements DeviceHostListener {
}
@Override
public boolean disable(boolean saveState) throws RemoteException {
+ synchronized (NfcService.this) {
+ if (mNxpNfcState != NXP_NFC_STATE_ON) {
+ Log.e(TAG, "mNxpNfcStateis not equal to NXP_NFC_STATE_ON."
+ + " Disable NFC Rejected.");
+ return false;
+ }
+ mNxpNfcState = NXP_NFC_STATE_TURNING_OFF;
+ }
NfcPermissions.enforceAdminPermissions(mContext);
if (saveState) {