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);
46 return NfcManagerImpl.Instance.IsSupported;
48 catch (TypeInitializationException)
56 /// NFC Activation state.
58 static public bool IsActivated
62 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
71 return NfcManagerImpl.Instance.IsActivated;
73 catch (TypeInitializationException)
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 return NfcTagFilterType.AllDisable;
97 return NfcManagerImpl.Instance.TagFilterType;
99 catch (TypeInitializationException)
101 return NfcTagFilterType.AllDisable;
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)
116 NfcManagerImpl.Instance.TagFilterType = value;
118 catch (TypeInitializationException)
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 return NfcSecureElementType.Disable;
142 return NfcManagerImpl.Instance.SecureElementType;
144 catch (TypeInitializationException)
146 return NfcSecureElementType.Disable;
153 NfcManagerImpl.Instance.SecureElementType = value;
155 catch (TypeInitializationException)
162 /// Enable or disable the system handling for tag and target discovered event.
164 static public bool SystemHandlerEnabled
168 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
177 return NfcManagerImpl.Instance.SystemHandlerEnabled;
179 catch (TypeInitializationException)
186 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
195 NfcManagerImpl.Instance.SystemHandlerEnabled = value;
197 catch (TypeInitializationException)
205 /// The cached Ndef Message.
207 static public NfcNdefMessage CachedNdefMessage
211 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
220 return NfcManagerImpl.Instance.CachedNdefMessage;
222 catch (TypeInitializationException)
230 /// Gets Tag adapter object.
232 static public NfcTagAdapter GetTagAdapter()
234 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
235 bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
237 if (!isNfcSupported || !isTagSupported)
239 throw new NotSupportedException();
244 return NfcManagerImpl.Instance.TagAdapter;
246 catch (TypeInitializationException e)
248 throw e.InnerException;
253 /// Gets P2p adapter object.
255 static public NfcP2pAdapter GetP2pAdapter()
257 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
258 bool isP2pSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.p2p", out isP2pSupported);
260 if (!isNfcSupported || !isP2pSupported)
262 throw new NotSupportedException();
267 return NfcManagerImpl.Instance.P2pAdapter;
269 catch (TypeInitializationException e)
271 throw e.InnerException;
276 /// Gets Card Emulation adepter object.
278 static public NfcCardEmulationAdapter GetCardEmulationAdapter()
280 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
281 bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
283 if (!isNfcSupported || !isCeSupported)
285 throw new NotSupportedException();
290 return NfcManagerImpl.Instance.CardEmulationAdapter;
292 catch (TypeInitializationException e)
294 throw e.InnerException;
299 /// Activates Nfc asynchronously.
301 /// <returns>A task indicates whether the Activate method is done or not.</returns>
302 static public Task SetActivateAsync(bool activation)
304 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
308 throw new NotSupportedException();
313 return NfcManagerImpl.Instance.SetActivateAsync(activation);
315 catch (TypeInitializationException e)
317 throw e.InnerException;
322 /// The Activation changed event.
324 static public event EventHandler<ActivationChangedEventArgs> ActivationChanged
328 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
332 throw new NotSupportedException();
337 NfcManagerImpl.Instance.ActivationChanged += value;
339 catch (TypeInitializationException e)
341 throw e.InnerException;
346 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
350 throw new NotSupportedException();
355 NfcManagerImpl.Instance.ActivationChanged -= value;
357 catch (TypeInitializationException e)
359 throw e.InnerException;
365 /// The Ndef discovered event.
367 static public event EventHandler<NdefMessageDiscoveredEventArgs> NdefMessageDiscovered
371 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
375 throw new NotSupportedException();
380 NfcManagerImpl.Instance.NdefMessageDiscovered += value;
382 catch (TypeInitializationException e)
384 throw e.InnerException;
389 bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
393 throw new NotSupportedException();
398 NfcManagerImpl.Instance.NdefMessageDiscovered -= value;
400 catch (TypeInitializationException e)
402 throw e.InnerException;