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 /// <privilege>http://tizen.org/privilege/nfc</privilege>
28 static public class NfcManager
31 /// Whether NFC is supported.
33 static public bool IsSupported
37 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
41 throw new NotSupportedException();
46 return NfcManagerImpl.Instance.IsSupported;
48 catch (TypeInitializationException e)
50 throw e.InnerException;
56 /// NFC Activation state.
58 static public bool IsActivated
62 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
66 throw new NotSupportedException();
71 return NfcManagerImpl.Instance.IsActivated;
73 catch (TypeInitializationException e)
75 throw e.InnerException;
81 /// The Tag Filter type.
83 static public NfcTagFilterType TagFilterType
87 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
88 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
90 if (!isNfcSupported || !isTagSupported)
92 throw new NotSupportedException();
97 return NfcManagerImpl.Instance.TagFilterType;
99 catch (TypeInitializationException e)
101 throw e.InnerException;
106 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
107 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
109 if (!isNfcSupported || !isTagSupported)
111 throw new NotSupportedException();
116 NfcManagerImpl.Instance.TagFilterType = value;
118 catch (TypeInitializationException e)
120 throw e.InnerException;
126 /// The Secure Element type.
128 static public NfcSecureElementType SecureElementType
132 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
133 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
135 if (!isNfcSupported || !isCeSupported)
137 throw new NotSupportedException();
142 return NfcManagerImpl.Instance.SecureElementType;
144 catch (TypeInitializationException e)
146 throw e.InnerException;
151 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
152 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
154 if (!isNfcSupported || !isCeSupported)
156 throw new NotSupportedException();
161 NfcManagerImpl.Instance.SecureElementType = value;
163 catch (TypeInitializationException e)
165 throw e.InnerException;
171 /// Enable or disable the system handling for tag and target discovered event.
173 static public bool SystemHandlerEnabled
177 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
181 throw new NotSupportedException();
186 return NfcManagerImpl.Instance.SystemHandlerEnabled;
188 catch (TypeInitializationException e)
190 throw e.InnerException;
195 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
199 throw new NotSupportedException();
204 NfcManagerImpl.Instance.SystemHandlerEnabled = value;
206 catch (TypeInitializationException e)
208 throw e.InnerException;
214 /// The cached Ndef Message.
216 static public NfcNdefMessage CachedNdefMessage
220 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
224 throw new NotSupportedException();
229 return NfcManagerImpl.Instance.CachedNdefMessage;
231 catch (TypeInitializationException e)
233 throw e.InnerException;
239 /// Gets Tag adapter object.
241 static public NfcTagAdapter GetTagAdapter()
243 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
244 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
246 if (!isNfcSupported || !isTagSupported)
248 throw new NotSupportedException();
253 return NfcManagerImpl.Instance.TagAdapter;
255 catch (TypeInitializationException e)
257 throw e.InnerException;
262 /// Gets P2p adapter object.
264 static public NfcP2pAdapter GetP2pAdapter()
266 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
267 bool isP2pSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.p2p", out isP2pSupported);
269 if (!isNfcSupported || !isP2pSupported)
271 throw new NotSupportedException();
276 return NfcManagerImpl.Instance.P2pAdapter;
278 catch (TypeInitializationException e)
280 throw e.InnerException;
285 /// Gets Card Emulation adepter object.
287 static public NfcCardEmulationAdapter GetCardEmulationAdapter()
289 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
290 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
292 if (!isNfcSupported || !isCeSupported)
294 throw new NotSupportedException();
299 return NfcManagerImpl.Instance.CardEmulationAdapter;
301 catch (TypeInitializationException e)
303 throw e.InnerException;
308 /// Activates Nfc asynchronously.
310 /// <returns>A task indicates whether the Activate method is done or not.</returns>
311 static public Task SetActivateAsync(bool activation)
313 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
317 throw new NotSupportedException();
322 return NfcManagerImpl.Instance.SetActivateAsync(activation);
324 catch (TypeInitializationException e)
326 throw e.InnerException;
331 /// The Activation changed event.
333 static public event EventHandler<ActivationChangedEventArgs> ActivationChanged
337 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
341 throw new NotSupportedException();
346 NfcManagerImpl.Instance.ActivationChanged += value;
348 catch (TypeInitializationException e)
350 throw e.InnerException;
355 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
359 throw new NotSupportedException();
364 NfcManagerImpl.Instance.ActivationChanged -= value;
366 catch (TypeInitializationException e)
368 throw e.InnerException;
374 /// The Ndef discovered event.
376 static public event EventHandler<NdefMessageDiscoveredEventArgs> NdefMessageDiscovered
380 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
384 throw new NotSupportedException();
389 NfcManagerImpl.Instance.NdefMessageDiscovered += value;
391 catch (TypeInitializationException e)
393 throw e.InnerException;
398 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
402 throw new NotSupportedException();
407 NfcManagerImpl.Instance.NdefMessageDiscovered -= value;
409 catch (TypeInitializationException e)
411 throw e.InnerException;