protected override async void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; // Clear the messages rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage, true); if (!ApplicationData.Current.RoamingSettings.Values.ContainsKey("DenyIfPhoneLocked")) { ApplicationData.Current.RoamingSettings.Values["DenyIfPhoneLocked"] = false; } if (!ApplicationData.Current.RoamingSettings.Values.ContainsKey("LaunchAboveLock")) { ApplicationData.Current.RoamingSettings.Values["LaunchAboveLock"] = false; } chkDenyIfPhoneLocked.IsChecked = (bool)ApplicationData.Current.RoamingSettings.Values["DenyIfPhoneLocked"]; chkLaunchAboveLock.IsChecked = (bool)ApplicationData.Current.RoamingSettings.Values["LaunchAboveLock"]; isHceSupported = await CheckHceSupport(); if (!isHceSupported) { btnRegisterBgTask.IsEnabled = false; btnAddCard.IsEnabled = false; } else { lstCards.ItemsSource = await SmartCardEmulator.GetAppletIdGroupRegistrationsAsync(); } Window.Current.VisibilityChanged += Window_VisibilityChanged; }
public static async Task <bool> CheckHceSupport() { // Check if the SmartCardEmulator API exists on this currently running SKU of Windows if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardEmulator")) { LogMessage("This SKU of Windows does not support NFC card emulation, only phones/mobile devices support NFC card emulation", NotifyType.ErrorMessage); return(false); } // Check if any NFC emulation is supported on this device var sce = await SmartCardEmulator.GetDefaultAsync(); if (sce == null) { LogMessage("NFC card emulation is not supported on this device, probably the device does not have NFC at all", NotifyType.ErrorMessage); return(false); } // Check if the NFC emulation support on this device includes HCE if (!sce.IsHostCardEmulationSupported()) { LogMessage("This device's NFC does not support HCE-mode", NotifyType.ErrorMessage); return(false); } return(true); }
private async void btnUnregisterCard_Click(object sender, RoutedEventArgs e) { // Clear the messages rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage, true); var reg = (SmartCardAppletIdGroupRegistration)lstCards.SelectedItem; if (reg == null) { LogMessage("No card selected, must select from listbox", NotifyType.ErrorMessage); return; } // Unregister the card await SmartCardEmulator.UnregisterAppletIdGroupAsync(reg); if (reg.AppletIdGroup.SmartCardEmulationCategory == SmartCardEmulationCategory.Payment && reg.AppletIdGroup.SmartCardEmulationType == SmartCardEmulationType.Host) { // Delete the data file for the card await(await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("ReadRecordResponse-" + reg.Id.ToString("B") + ".dat")).DeleteAsync(); } // Refresh the listbox lstCards.ItemsSource = await SmartCardEmulator.GetAppletIdGroupRegistrationsAsync(); LogMessage("AID group successfully unregistered"); }
private async void Window_VisibilityChanged(object sender, VisibilityChangedEventArgs e) { // Since a registration can change from ForegroundOverride to Disabled when the device // is locked, update the registrations when the app window becomes visible if (e.Visible && isHceSupported) { // Clear the messages rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage, true); lstCards.ItemsSource = await SmartCardEmulator.GetAppletIdGroupRegistrationsAsync(); } }
private async void btnForegroundOverrideCard_Click(object sender, RoutedEventArgs e) { // Clear the messages rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage, true); var reg = (SmartCardAppletIdGroupRegistration)lstCards.SelectedItem; if (reg == null) { LogMessage("No card selected, must select from listbox", NotifyType.ErrorMessage); return; } await NfcUtils.SetCardActivationPolicy(reg, SmartCardAppletIdGroupActivationPolicy.ForegroundOverride); // Refresh the listbox lstCards.ItemsSource = await SmartCardEmulator.GetAppletIdGroupRegistrationsAsync(); }
public static async Task <SmartCardAppletIdGroupRegistration> RegisterAidGroup(string displayName, IList <IBuffer> appletIds, SmartCardEmulationCategory?emulationCategory, SmartCardEmulationType emulationType, bool automaticEnablement) { try { var cardAidGroup = new SmartCardAppletIdGroup(displayName, appletIds, (SmartCardEmulationCategory)emulationCategory, emulationType); cardAidGroup.AutomaticEnablement = automaticEnablement; var reg = await SmartCardEmulator.RegisterAppletIdGroupAsync(cardAidGroup); LogMessage("AID group successfully registered", NotifyType.StatusMessage); return(reg); } catch (Exception ex) { LogMessage("Failed to register AID group: " + ex.ToString(), NotifyType.StatusMessage); throw; } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; if (!ApplicationData.Current.RoamingSettings.Values.ContainsKey("DenyIfPhoneLocked")) { ApplicationData.Current.RoamingSettings.Values["DenyIfPhoneLocked"] = false; } if (!ApplicationData.Current.RoamingSettings.Values.ContainsKey("LaunchAboveLock")) { ApplicationData.Current.RoamingSettings.Values["LaunchAboveLock"] = false; } chkDenyIfPhoneLocked.IsChecked = (bool)ApplicationData.Current.RoamingSettings.Values["DenyIfPhoneLocked"]; chkLaunchAboveLock.IsChecked = (bool)ApplicationData.Current.RoamingSettings.Values["LaunchAboveLock"]; lstCards.ItemsSource = await SmartCardEmulator.GetAppletIdGroupRegistrationsAsync(); }
public static async Task <SmartCardAppletIdGroupRegistration> GetAidGroupById(Guid id) { try { // Find registration var reg = (from r in await SmartCardEmulator.GetAppletIdGroupRegistrationsAsync() where r.Id == id select r).SingleOrDefault(); if (reg == null) { LogMessage("No matching AID group found for specified ID", NotifyType.ErrorMessage); } return(reg); } catch (Exception ex) { LogMessage("Failed to get AID group by ID: " + ex.ToString(), NotifyType.StatusMessage); throw; } }
private async void btnRegisterSamplePaymentCard_Click(object sender, RoutedEventArgs e) { // Clear the messages rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage, true); // First check if the device supports NFC/HCE at all if (!(await NfcUtils.CheckHceSupport())) { // HCE not supported return; } // Next check if NFC card emualtion is turned on in the settings control panel if ((await SmartCardEmulator.GetDefaultAsync()).EnablementPolicy == SmartCardEmulatorEnablementPolicy.Never) { ShowDialog("Your NFC tap+pay setting is turned off, you will be taken to the NFC control panel to turn it on"); // This URI will navigate the user to the NFC tap+pay control panel NfcUtils.LaunchNfcPaymentsSettingsPage(); return; } this.Frame.Navigate(typeof(SetCardDataScenario)); }