forked from microsoft/Windows-universal-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimCard.xaml.cs
141 lines (125 loc) · 5.22 KB
/
SimCard.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Networking.NetworkOperators;
using Windows.Networking.Connectivity;
using SDKTemplate;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace MobileBroadband
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class SimCard : Page
{
MainPage rootPage = MainPage.Current;
MobileBroadbandUiccApp currentUiccApp = null;
public SimCard()
{
this.InitializeComponent();
}
private async void btnGetUICC_Click(object sender, RoutedEventArgs e)
{
try
{
var modem = MobileBroadbandModem.GetDefault();
MobileBroadbandModemConfiguration modemCfg = await modem.GetCurrentConfigurationAsync();
MobileBroadbandUicc uicc = modemCfg.Uicc;
if (uicc != null)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("SIM Card ICCID:" + uicc.SimIccId);
MobileBroadbandUiccAppsResult appsResult = await uicc.GetUiccAppsAsync();
System.Collections.ObjectModel.ObservableCollection<object> AppList = new System.Collections.ObjectModel.ObservableCollection<object>();
foreach (var uiccApp in appsResult.UiccApps)
{
ListBoxItem item = new ListBoxItem();
item.Name = uiccApp.Kind.ToString();
item.Content = uiccApp;
AppList.Add(item);
}
listUiccApps.ItemsSource = AppList;
if (AppList.Count > 0)
{
listUiccApps.SelectedIndex = 0;
}
else
{
sb.AppendLine("No UICC app found.");
}
txtUICCInformation.Text = sb.ToString();
}
}
catch (Exception ex)
{
rootPage.NotifyUser("Error:" + ex.Message, NotifyType.ErrorMessage);
}
}
private void listUiccApps_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (null != listUiccApps.SelectedItem)
{
ListBoxItem item = listUiccApps.SelectedItem as ListBoxItem;
currentUiccApp = (MobileBroadbandUiccApp)item.Content;
btnGetRecord.IsEnabled = true;
byte[] appIdByteBuffer = currentUiccApp.Id.ToArray();
StringBuilder sb = new StringBuilder();
sb.AppendLine("AppId:");
foreach(var v in appIdByteBuffer)
{
sb.Append(v.ToString("X") + ", ");
}
txtUICCAppId.Text = sb.ToString();
}
else
{
btnGetRecord.IsEnabled = false;
}
labelRecordInformation.Text = "";
}
private async void btnGetRecord_Click(object sender, RoutedEventArgs e)
{
List<uint> iccidFilePath = new List<uint>{ 0x3F00, 0x2FE2}; // The wellknown file path for IccId
MobileBroadbandUiccAppRecordDetailsResult recordDetails = await currentUiccApp.GetRecordDetailsAsync(iccidFilePath);
StringBuilder sb = new StringBuilder();
sb.AppendLine("Record Details");
sb.AppendLine("Record Type:" + recordDetails.Kind.ToString());
sb.AppendLine("Record Size:" + recordDetails.RecordSize.ToString());
sb.AppendLine("Read result:");
MobileBroadbandUiccAppReadRecordResult readRecord = await currentUiccApp.ReadRecordAsync(iccidFilePath, 1);
sb.AppendLine(readRecord.Status.ToString());
if (readRecord.Status == MobileBroadbandUiccAppOperationStatus.Success)
{
sb.AppendLine("IccId record content:");
byte[] iccidByteArray = readRecord.Data.ToArray();
foreach (var v in iccidByteArray)
{
sb.Append(v.ToString("X") + ", ");
}
}
labelRecordInformation.Text = sb.ToString();
}
}
}