/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Threading.Tasks; using Tizen.System; namespace Tizen.Network.Nfc { /// /// A class for NFC management. It allows applications to use NFC service. /// /// 3 /// http://tizen.org/privilege/nfc static public class NfcManager { /// /// Whether NFC is supported. /// /// 3 static public bool IsSupported { get { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.IsSupported; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// NFC Activation state. /// /// 3 static public bool IsActivated { get { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.IsActivated; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// The Tag Filter type. /// /// 3 static public NfcTagFilterType TagFilterType { get { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported); if (!isNfcSupported || !isTagSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.TagFilterType; } catch (TypeInitializationException e) { throw e.InnerException; } } set { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported); if (!isNfcSupported || !isTagSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.TagFilterType = value; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// The Secure Element type. /// /// 3 /// http://tizen.org/privilege/nfc.cardemulation static public NfcSecureElementType SecureElementType { get { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported); if (!isNfcSupported || !isCeSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.SecureElementType; } catch (TypeInitializationException e) { throw e.InnerException; } } set { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported); if (!isNfcSupported || !isCeSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.SecureElementType = value; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// Enable or disable the system handling for tag and target discovered event. /// /// 3 /// http://tizen.org/privilege/nfc static public bool SystemHandlerEnabled { get { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.SystemHandlerEnabled; } catch (TypeInitializationException e) { throw e.InnerException; } } set { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.SystemHandlerEnabled = value; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// The cached Ndef Message. /// /// 3 static public NfcNdefMessage CachedNdefMessage { get { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.CachedNdefMessage; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// Gets Tag adapter object. /// /// 3 static public NfcTagAdapter GetTagAdapter() { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isTagSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported); if (!isNfcSupported || !isTagSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.TagAdapter; } catch (TypeInitializationException e) { throw e.InnerException; } } /// /// Gets P2p adapter object. /// /// 3 static public NfcP2pAdapter GetP2pAdapter() { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isP2pSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.p2p", out isP2pSupported); if (!isNfcSupported || !isP2pSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.P2pAdapter; } catch (TypeInitializationException e) { throw e.InnerException; } } /// /// Gets Card Emulation adepter object. /// /// 3 static public NfcCardEmulationAdapter GetCardEmulationAdapter() { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); bool isCeSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported); if (!isNfcSupported || !isCeSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.CardEmulationAdapter; } catch (TypeInitializationException e) { throw e.InnerException; } } /// /// Activates Nfc asynchronously. /// /// 3 /// A task indicates whether the Activate method is done or not. /// http://tizen.org/privilege/nfc.admin static public Task SetActivationAsync(bool activation) { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { return NfcManagerImpl.Instance.SetActivationAsync(activation); } catch (TypeInitializationException e) { throw e.InnerException; } } /// /// The Activation changed event. /// /// 3 static public event EventHandler ActivationChanged { add { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.ActivationChanged += value; } catch (TypeInitializationException e) { throw e.InnerException; } } remove { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.ActivationChanged -= value; } catch (TypeInitializationException e) { throw e.InnerException; } } } /// /// The Ndef discovered event. /// /// 3 static public event EventHandler NdefMessageDiscovered { add { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.NdefMessageDiscovered += value; } catch (TypeInitializationException e) { throw e.InnerException; } } remove { bool isNfcSupported = SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported); if (!isNfcSupported) { throw new NotSupportedException(); } try { NfcManagerImpl.Instance.NdefMessageDiscovered -= value; } catch (TypeInitializationException e) { throw e.InnerException; } } } } }