From 1a6bcf3cca90fedfbad33c1cdd6d05af5774fc01 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Thu, 25 Oct 2012 20:49:48 -0700 Subject: Serialize applying card emulation route. Instead of immediately applying the routing, serialze the request with any outstanding commands (including NFC enable/disable). This prevents race conditions when NFC is being disabled and the card emu routing gets changed at the same time. Wait until the AsyncTask is complete, to make sure that the routing is applied (if possible) by the time the call returns. Bug: 7418238 Change-Id: I7d92533179c02f4b6b01a86967737e64532317a1 --- src/com/android/nfc/NfcService.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 551469d..d63f84f 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -1403,7 +1403,16 @@ public class NfcService implements DeviceHostListener { public void setCardEmulationRoute(String pkg, int route) throws RemoteException { NfcService.this.enforceNfceeAdminPerm(pkg); mEeRoutingState = route; - applyRouting(true); + ApplyRoutingTask applyRoutingTask = new ApplyRoutingTask(); + applyRoutingTask.execute(); + try { + // Block until route is set + applyRoutingTask.get(); + } catch (ExecutionException e) { + Log.e(TAG, "failed to set card emulation mode"); + } catch (InterruptedException e) { + Log.e(TAG, "failed to set card emulation mode"); + } } @Override -- cgit v1.1