1367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly/* 2367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Copyright (C) 2011 The Android Open Source Project 3367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 4367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Licensed under the Apache License, Version 2.0 (the "License"); 5367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * you may not use this file except in compliance with the License. 6367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * You may obtain a copy of the License at 7367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 8367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * http://www.apache.org/licenses/LICENSE-2.0 9367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 10367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Unless required by applicable law or agreed to in writing, software 11367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * distributed under the License is distributed on an "AS IS" BASIS, 12367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * See the License for the specific language governing permissions and 14367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * limitations under the License. 15367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 16367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 17367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pellypackage com.android.nfc_extras; 18367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 19678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pellyimport java.util.HashMap; 20678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly 21bb951c893973691554f49d2e725985125f866b27Jeff Hamiltonimport android.content.Context; 22367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pellyimport android.nfc.INfcAdapterExtras; 23367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pellyimport android.nfc.NfcAdapter; 24367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pellyimport android.os.RemoteException; 25367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pellyimport android.util.Log; 26367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 27367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly/** 28367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Provides additional methods on an {@link NfcAdapter} for Card Emulation 29367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * and management of {@link NfcExecutionEnvironment}'s. 30367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 31367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * There is a 1-1 relationship between an {@link NfcAdapterExtras} object and 32367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * a {@link NfcAdapter} object. 33367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 34367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pellypublic final class NfcAdapterExtras { 35367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly private static final String TAG = "NfcAdapterExtras"; 36367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 37367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 38367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Broadcast Action: an RF field ON has been detected. 39367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 40367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note">This is an unreliable signal, and will be removed. 41367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note"> 42367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission 43367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * to receive. 44367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 45367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public static final String ACTION_RF_FIELD_ON_DETECTED = 46367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly "com.android.nfc_extras.action.RF_FIELD_ON_DETECTED"; 47367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 48367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 49367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Broadcast Action: an RF field OFF has been detected. 50367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 51367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note">This is an unreliable signal, and will be removed. 52367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note"> 53367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission 54367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * to receive. 55367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 56367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public static final String ACTION_RF_FIELD_OFF_DETECTED = 57367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly "com.android.nfc_extras.action.RF_FIELD_OFF_DETECTED"; 58367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 59cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly // protected by NfcAdapterExtras.class, and final after first construction, 60cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly // except for attemptDeadServiceRecovery() when NFC crashes - we accept a 61cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly // best effort recovery 62367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly private static INfcAdapterExtras sService; 63bb951c893973691554f49d2e725985125f866b27Jeff Hamilton private static final CardEmulationRoute ROUTE_OFF = 64bb951c893973691554f49d2e725985125f866b27Jeff Hamilton new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null); 65bb951c893973691554f49d2e725985125f866b27Jeff Hamilton 66678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly // contents protected by NfcAdapterExtras.class 67678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly private static final HashMap<NfcAdapter, NfcAdapterExtras> sNfcExtras = new HashMap(); 68678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly 69bb951c893973691554f49d2e725985125f866b27Jeff Hamilton private final NfcExecutionEnvironment mEmbeddedEe; 70bb951c893973691554f49d2e725985125f866b27Jeff Hamilton private final CardEmulationRoute mRouteOnWhenScreenOn; 71bb951c893973691554f49d2e725985125f866b27Jeff Hamilton 72678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly private final NfcAdapter mAdapter; 73bb951c893973691554f49d2e725985125f866b27Jeff Hamilton final String mPackageName; 74367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 75cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly /** get service handles */ 76678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly private static void initService(NfcAdapter adapter) { 77678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly final INfcAdapterExtras service = adapter.getNfcAdapterExtrasInterface(); 7815bc894aae9192e26c35e0af22b5dbd2a5c30028Robert Tsai if (service != null) { 7915bc894aae9192e26c35e0af22b5dbd2a5c30028Robert Tsai // Leave stale rather than receive a null value. 8015bc894aae9192e26c35e0af22b5dbd2a5c30028Robert Tsai sService = service; 8115bc894aae9192e26c35e0af22b5dbd2a5c30028Robert Tsai } 82cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly } 83cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly 84367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 85367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Get the {@link NfcAdapterExtras} for the given {@link NfcAdapter}. 86367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 87367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note"> 88367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission. 89367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 90367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * @param adapter a {@link NfcAdapter}, must not be null 91367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * @return the {@link NfcAdapterExtras} object for the given {@link NfcAdapter} 92367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 93367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public static NfcAdapterExtras get(NfcAdapter adapter) { 94bb951c893973691554f49d2e725985125f866b27Jeff Hamilton Context context = adapter.getContext(); 95bb951c893973691554f49d2e725985125f866b27Jeff Hamilton if (context == null) { 96bb951c893973691554f49d2e725985125f866b27Jeff Hamilton throw new UnsupportedOperationException( 97bb951c893973691554f49d2e725985125f866b27Jeff Hamilton "You must pass a context to your NfcAdapter to use the NFC extras APIs"); 98bb951c893973691554f49d2e725985125f866b27Jeff Hamilton } 99bb951c893973691554f49d2e725985125f866b27Jeff Hamilton 100bb951c893973691554f49d2e725985125f866b27Jeff Hamilton synchronized (NfcAdapterExtras.class) { 101bb951c893973691554f49d2e725985125f866b27Jeff Hamilton if (sService == null) { 102678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly initService(adapter); 103367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 104678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly NfcAdapterExtras extras = sNfcExtras.get(adapter); 105678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly if (extras == null) { 106678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly extras = new NfcAdapterExtras(adapter); 107678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly sNfcExtras.put(adapter, extras); 108678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly } 109678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly return extras; 110367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 111367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 112367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 113678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly private NfcAdapterExtras(NfcAdapter adapter) { 114678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly mAdapter = adapter; 115678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly mPackageName = adapter.getContext().getPackageName(); 116bb951c893973691554f49d2e725985125f866b27Jeff Hamilton mEmbeddedEe = new NfcExecutionEnvironment(this); 117bb951c893973691554f49d2e725985125f866b27Jeff Hamilton mRouteOnWhenScreenOn = new CardEmulationRoute(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, 118bb951c893973691554f49d2e725985125f866b27Jeff Hamilton mEmbeddedEe); 119bb951c893973691554f49d2e725985125f866b27Jeff Hamilton } 120367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 121367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 122367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Immutable data class that describes a card emulation route. 123367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 124367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public final static class CardEmulationRoute { 125367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 126367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Card Emulation is turned off on this NfcAdapter. 127367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p>This is the default routing state after boot. 128367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 129367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public static final int ROUTE_OFF = 1; 130367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 131367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 132367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Card Emulation is routed to {@link #nfcEe} only when the screen is on, 133367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * otherwise it is turned off. 134367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 135367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public static final int ROUTE_ON_WHEN_SCREEN_ON = 2; 136367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 137367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 138367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * A route such as {@link #ROUTE_OFF} or {@link #ROUTE_ON_WHEN_SCREEN_ON}. 139367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 140367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public final int route; 141367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 142367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 143367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * The {@link NFcExecutionEnvironment} that is Card Emulation is routed to. 144367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p>null if {@link #route} is {@link #ROUTE_OFF}, otherwise not null. 145367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 146367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public final NfcExecutionEnvironment nfcEe; 147367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 148367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public CardEmulationRoute(int route, NfcExecutionEnvironment nfcEe) { 149367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly if (route == ROUTE_OFF && nfcEe != null) { 150367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly throw new IllegalArgumentException("must not specifiy a NFC-EE with ROUTE_OFF"); 151367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } else if (route != ROUTE_OFF && nfcEe == null) { 152367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly throw new IllegalArgumentException("must specifiy a NFC-EE for this route"); 153367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 154367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly this.route = route; 155367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly this.nfcEe = nfcEe; 156367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 157367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 158367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 159367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 160cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly * NFC service dead - attempt best effort recovery 161cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly */ 162cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly void attemptDeadServiceRecovery(Exception e) { 163cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly Log.e(TAG, "NFC Adapter Extras dead - attempting to recover"); 164678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly mAdapter.attemptDeadServiceRecovery(e); 165678a7025ddb250de2a26cabc51402ff4e67752a8Nick Pelly initService(mAdapter); 166cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly } 167cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly 168cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly INfcAdapterExtras getService() { 169cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly return sService; 170cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly } 171cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly 172cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly /** 173367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Get the routing state of this NFC EE. 174367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 175367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note"> 176367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission. 177367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 178367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public CardEmulationRoute getCardEmulationRoute() { 179367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly try { 180bb951c893973691554f49d2e725985125f866b27Jeff Hamilton int route = sService.getCardEmulationRoute(mPackageName); 181367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly return route == CardEmulationRoute.ROUTE_OFF ? 182bb951c893973691554f49d2e725985125f866b27Jeff Hamilton ROUTE_OFF : 183bb951c893973691554f49d2e725985125f866b27Jeff Hamilton mRouteOnWhenScreenOn; 184367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } catch (RemoteException e) { 185cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly attemptDeadServiceRecovery(e); 186bb951c893973691554f49d2e725985125f866b27Jeff Hamilton return ROUTE_OFF; 187367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 188367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 189367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 190367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 191367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Set the routing state of this NFC EE. 192367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 193367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p>This routing state is not persisted across reboot. 194367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 195367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note"> 196367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission. 197367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 198bb951c893973691554f49d2e725985125f866b27Jeff Hamilton * @param route a {@link CardEmulationRoute} 199367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 200367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public void setCardEmulationRoute(CardEmulationRoute route) { 201367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly try { 202bb951c893973691554f49d2e725985125f866b27Jeff Hamilton sService.setCardEmulationRoute(mPackageName, route.route); 203367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } catch (RemoteException e) { 204cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly attemptDeadServiceRecovery(e); 205367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 206367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 207367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly 208367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly /** 209367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Get the {@link NfcExecutionEnvironment} that is embedded with the 210bb951c893973691554f49d2e725985125f866b27Jeff Hamilton * {@link NfcAdapter}. 211367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 212367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * <p class="note"> 213367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission. 214367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * 215367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly * @return a {@link NfcExecutionEnvironment}, or null if there is no embedded NFC-EE 216367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly */ 217367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly public NfcExecutionEnvironment getEmbeddedExecutionEnvironment() { 218bb951c893973691554f49d2e725985125f866b27Jeff Hamilton return mEmbeddedEe; 219367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly } 220ab8f48c2ee524f67e5c3cab5846119e6c8a645b5Jason parks 22117523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly /** 22217523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly * Authenticate the client application. 22317523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly * 22417523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly * Some implementations of NFC Adapter Extras may require applications 22517523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly * to authenticate with a token, before using other methods. 22617523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly * 227bb951c893973691554f49d2e725985125f866b27Jeff Hamilton * @param token a implementation specific token 228bb951c893973691554f49d2e725985125f866b27Jeff Hamilton * @throws java.lang.SecurityException if authentication failed 22917523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly */ 23017523abb45b7f77f35af53e895d74be13f2314e0Nick Pelly public void authenticate(byte[] token) { 231ab8f48c2ee524f67e5c3cab5846119e6c8a645b5Jason parks try { 232bb951c893973691554f49d2e725985125f866b27Jeff Hamilton sService.authenticate(mPackageName, token); 233ab8f48c2ee524f67e5c3cab5846119e6c8a645b5Jason parks } catch (RemoteException e) { 234cc9ee72bd42bb40b1852f907f58305adde12ecc2Nick Pelly attemptDeadServiceRecovery(e); 235ab8f48c2ee524f67e5c3cab5846119e6c8a645b5Jason parks } 236ab8f48c2ee524f67e5c3cab5846119e6c8a645b5Jason parks } 237f74df47fc9aee3a274db006db5024892972a0c8amike wakerly 238f74df47fc9aee3a274db006db5024892972a0c8amike wakerly /** 239f74df47fc9aee3a274db006db5024892972a0c8amike wakerly * Returns the name of this adapter's driver. 240f74df47fc9aee3a274db006db5024892972a0c8amike wakerly * 241f74df47fc9aee3a274db006db5024892972a0c8amike wakerly * <p>Different NFC adapters may use different drivers. This value is 242f74df47fc9aee3a274db006db5024892972a0c8amike wakerly * informational and should not be parsed. 243f74df47fc9aee3a274db006db5024892972a0c8amike wakerly * 244f74df47fc9aee3a274db006db5024892972a0c8amike wakerly * @return the driver name, or empty string if unknown 245f74df47fc9aee3a274db006db5024892972a0c8amike wakerly */ 246f74df47fc9aee3a274db006db5024892972a0c8amike wakerly public String getDriverName() { 247f74df47fc9aee3a274db006db5024892972a0c8amike wakerly try { 248f74df47fc9aee3a274db006db5024892972a0c8amike wakerly return sService.getDriverName(mPackageName); 249f74df47fc9aee3a274db006db5024892972a0c8amike wakerly } catch (RemoteException e) { 250f74df47fc9aee3a274db006db5024892972a0c8amike wakerly attemptDeadServiceRecovery(e); 251f74df47fc9aee3a274db006db5024892972a0c8amike wakerly return ""; 252f74df47fc9aee3a274db006db5024892972a0c8amike wakerly } 253f74df47fc9aee3a274db006db5024892972a0c8amike wakerly } 254367f41f8f61126c2ab34a34cc676756a9fc23ac2Nick Pelly} 255