2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Threading.Tasks;
22 namespace Tizen.Network.Nfc
25 /// A class for NFC management. It allows applications to use NFC service.
27 /// <since_tizen> 3 </since_tizen>
28 /// <privilege>http://tizen.org/privilege/nfc</privilege>
29 static public class NfcManager
32 /// Whether NFC is supported.
34 /// <since_tizen> 3 </since_tizen>
35 static public bool IsSupported
39 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
43 throw new NotSupportedException();
48 return NfcManagerImpl.Instance.IsSupported;
50 catch (TypeInitializationException e)
52 throw e.InnerException;
58 /// NFC Activation state.
60 /// <since_tizen> 3 </since_tizen>
61 static public bool IsActivated
65 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
69 throw new NotSupportedException();
74 return NfcManagerImpl.Instance.IsActivated;
76 catch (TypeInitializationException e)
78 throw e.InnerException;
84 /// The Tag Filter type.
86 /// <since_tizen> 3 </since_tizen>
87 static public NfcTagFilterType TagFilterType
91 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
92 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
94 if (!isNfcSupported || !isTagSupported)
96 throw new NotSupportedException();
101 return NfcManagerImpl.Instance.TagFilterType;
103 catch (TypeInitializationException e)
105 throw e.InnerException;
110 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
111 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
113 if (!isNfcSupported || !isTagSupported)
115 throw new NotSupportedException();
120 NfcManagerImpl.Instance.TagFilterType = value;
122 catch (TypeInitializationException e)
124 throw e.InnerException;
130 /// The Secure Element type.
132 /// <since_tizen> 3 </since_tizen>
133 /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
134 static public NfcSecureElementType SecureElementType
138 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
139 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
141 if (!isNfcSupported || !isCeSupported)
143 throw new NotSupportedException();
148 return NfcManagerImpl.Instance.SecureElementType;
150 catch (TypeInitializationException e)
152 throw e.InnerException;
157 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
158 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
160 if (!isNfcSupported || !isCeSupported)
162 throw new NotSupportedException();
167 NfcManagerImpl.Instance.SecureElementType = value;
169 catch (TypeInitializationException e)
171 throw e.InnerException;
177 /// Enable or disable the system handling for tag and target discovered event.
179 /// <since_tizen> 3 </since_tizen>
180 /// <privilege>http://tizen.org/privilege/nfc</privilege>
181 static public bool SystemHandlerEnabled
185 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
189 throw new NotSupportedException();
194 return NfcManagerImpl.Instance.SystemHandlerEnabled;
196 catch (TypeInitializationException e)
198 throw e.InnerException;
203 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
207 throw new NotSupportedException();
212 NfcManagerImpl.Instance.SystemHandlerEnabled = value;
214 catch (TypeInitializationException e)
216 throw e.InnerException;
222 /// The cached Ndef Message.
224 /// <since_tizen> 3 </since_tizen>
225 static public NfcNdefMessage CachedNdefMessage
229 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
233 throw new NotSupportedException();
238 return NfcManagerImpl.Instance.CachedNdefMessage;
240 catch (TypeInitializationException e)
242 throw e.InnerException;
248 /// Gets Tag adapter object.
250 /// <since_tizen> 3 </since_tizen>
251 static public NfcTagAdapter GetTagAdapter()
253 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
254 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
256 if (!isNfcSupported || !isTagSupported)
258 throw new NotSupportedException();
263 return NfcManagerImpl.Instance.TagAdapter;
265 catch (TypeInitializationException e)
267 throw e.InnerException;
272 /// Gets P2p adapter object.
274 /// <since_tizen> 3 </since_tizen>
275 static public NfcP2pAdapter GetP2pAdapter()
277 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
278 bool isP2pSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.p2p", out isP2pSupported);
280 if (!isNfcSupported || !isP2pSupported)
282 throw new NotSupportedException();
287 return NfcManagerImpl.Instance.P2pAdapter;
289 catch (TypeInitializationException e)
291 throw e.InnerException;
296 /// Gets Card Emulation adepter object.
298 /// <since_tizen> 3 </since_tizen>
299 static public NfcCardEmulationAdapter GetCardEmulationAdapter()
301 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
302 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
304 if (!isNfcSupported || !isCeSupported)
306 throw new NotSupportedException();
311 return NfcManagerImpl.Instance.CardEmulationAdapter;
313 catch (TypeInitializationException e)
315 throw e.InnerException;
320 /// Activates Nfc asynchronously.
322 /// <since_tizen> 3 </since_tizen>
323 /// <returns>A task indicates whether the Activate method is done or not.</returns>
324 /// <privilege>http://tizen.org/privilege/nfc.admin</privilege>
325 static public Task SetActivationAsync(bool activation)
327 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
331 throw new NotSupportedException();
336 return NfcManagerImpl.Instance.SetActivationAsync(activation);
338 catch (TypeInitializationException e)
340 throw e.InnerException;
345 /// The Activation changed event.
347 /// <since_tizen> 3 </since_tizen>
348 static public event EventHandler<ActivationChangedEventArgs> ActivationChanged
352 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
356 throw new NotSupportedException();
361 NfcManagerImpl.Instance.ActivationChanged += value;
363 catch (TypeInitializationException e)
365 throw e.InnerException;
370 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
374 throw new NotSupportedException();
379 NfcManagerImpl.Instance.ActivationChanged -= value;
381 catch (TypeInitializationException e)
383 throw e.InnerException;
389 /// The Ndef discovered event.
391 /// <since_tizen> 3 </since_tizen>
392 static public event EventHandler<NdefMessageDiscoveredEventArgs> NdefMessageDiscovered
396 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
400 throw new NotSupportedException();
405 NfcManagerImpl.Instance.NdefMessageDiscovered += value;
407 catch (TypeInitializationException e)
409 throw e.InnerException;
414 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
418 throw new NotSupportedException();
423 NfcManagerImpl.Instance.NdefMessageDiscovered -= value;
425 catch (TypeInitializationException e)
427 throw e.InnerException;