Skip to content
Browse files

Make sure NFC stack is initialized before attempting SE reset.

This fixes a regression at about GRJ46 where phones that had NFC
turned off would fail to perform SE reset on first boot of GRJ46
and later. This would prevent NFC from being turned on, and caused
NFC service to eat battery.

Change-Id: I4714f06e8a3c92a5974851dd1be90b797e3058ac
Bug: 4504474
  • Loading branch information...
1 parent b8318ad commit aa122139d77645149c09c9815fd45e7b87ce7170 Nick Pelly committed May 31, 2011
Showing with 49 additions and 25 deletions.
  1. +49 −25 src/com/android/nfc/NfcService.java
View
74 src/com/android/nfc/NfcService.java
@@ -378,32 +378,8 @@ public boolean disable() throws RemoteException {
if (DBG) Log.d(TAG, "Disabling NFC. previous=" + previouslyEnabled);
if (previouslyEnabled) {
- /* tear down the my tag server */
- mNdefPushServer.stop();
-
- // Stop watchdog if tag present
- // A convenient way to stop the watchdog properly consists of
- // disconnecting the tag. The polling loop shall be stopped before
- // to avoid the tag being discovered again.
- mIsDiscoveryOn = false;
- applyRouting();
- maybeDisconnectTarget();
-
- isSuccess = mManager.deinitialize();
- if (DBG) Log.d(TAG, "NFC success of deinitialize = " + isSuccess);
- if (isSuccess) {
- mIsNfcEnabled = false;
- // Clear out any old dispatch overrides and NDEF push message
- synchronized (this) {
- mDispatchOverrideFilters = null;
- mDispatchOverrideIntent = null;
- }
- mNdefPushClient.setForegroundMessage(null);
- }
+ isSuccess = _disable(previouslyEnabled);
}
-
- updateNfcOnSetting(previouslyEnabled);
-
return isSuccess;
}
@@ -1957,6 +1933,7 @@ private boolean _enable(boolean oldEnabledState) {
mNdefPushServer.start();
} else {
+ Log.w(TAG, "Error enabling NFC");
mIsNfcEnabled = false;
}
@@ -1965,6 +1942,37 @@ private boolean _enable(boolean oldEnabledState) {
return isSuccess;
}
+ private boolean _disable(boolean oldEnabledState) {
+ boolean isSuccess;
+
+ /* tear down the my tag server */
+ mNdefPushServer.stop();
+
+ // Stop watchdog if tag present
+ // A convenient way to stop the watchdog properly consists of
+ // disconnecting the tag. The polling loop shall be stopped before
+ // to avoid the tag being discovered again.
+ mIsDiscoveryOn = false;
+ applyRouting();
+ maybeDisconnectTarget();
+
+ isSuccess = mManager.deinitialize();
+ if (DBG) Log.d(TAG, "NFC success of deinitialize = " + isSuccess);
+ if (isSuccess) {
+ mIsNfcEnabled = false;
+ // Clear out any old dispatch overrides and NDEF push message
+ synchronized (this) {
+ mDispatchOverrideFilters = null;
+ mDispatchOverrideIntent = null;
+ }
+ mNdefPushClient.setForegroundMessage(null);
+ }
+
+ updateNfcOnSetting(oldEnabledState);
+
+ return isSuccess;
+ }
+
/** apply NFC discovery and EE routing */
private synchronized void applyRouting() {
if (mIsNfcEnabled && mOpenEe == null) {
@@ -2047,10 +2055,22 @@ private synchronized void executeSeReset() {
if (apdus == null) {
return;
}
+
+ boolean tempEnable = !mIsNfcEnabled;
+ if (tempEnable) {
+ if (!_enable(false)) {
+ Log.w(TAG, "Could not enable NFC to reset EE!");
+ return;
+ }
+ }
+
Log.i(TAG, "Executing SE Reset Script");
int handle = mSecureElement.doOpenSecureElementConnection();
if (handle == 0) {
Log.e(TAG, "Could not open the secure element!");
+ if (tempEnable) {
+ _disable(true);
+ }
return;
}
@@ -2059,6 +2079,10 @@ private synchronized void executeSeReset() {
}
mSecureElement.doDisconnect(handle);
+
+ if (tempEnable) {
+ _disable(true);
+ }
}
private List<byte[]> readSeResetApdus() {

0 comments on commit aa12213

Please sign in to comment.
Something went wrong with that request. Please try again.