2 * Copyright (c) 2018 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
19 namespace Tizen.Security.DevicePolicyManager
22 /// The EmailPolicy provides methods to manage email policies.
24 /// <since_tizen> 6 </since_tizen>
25 /// <remarks>The EmailPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the EmailPolicy.</remarks>
26 [Obsolete("Deprecated since API level 11.")]
27 public class EmailPolicy : DevicePolicy, IDisposable
30 /// The PopImap email policy name. This represents <see cref="EmailPolicy.IsPopImapAllowed"/>.
32 /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
33 /// <since_tizen> 6 </since_tizen>
34 [Obsolete("Deprecated since API level 11.")]
35 public static readonly string PopImapEmailPolicyName = "PopImapEmail";
37 private readonly string _popImapPolicyName = "popimap_email";
38 private int _popImapCallbackId;
39 private bool _disposed = false;
41 private Interop.DevicePolicyManager.PolicyChangedCallback _popImapPolicyChangedCallback;
42 private EventHandler<PolicyChangedEventArgs> _popImapPolicyChanged;
44 internal EmailPolicy(DevicePolicyManager dpm) : base(dpm)
49 /// A Destructor of EmailPolicy.
51 [Obsolete("Deprecated since API level 11.")]
58 /// Gets whether the access to POP or IMAP email is allowed or not.
60 /// <value>true if the POP or IMAP email is allowed, false otherwise. The default value is true.</value>
61 /// <since_tizen> 6 </since_tizen>
62 [Obsolete("Deprecated since API level 11.")]
63 public bool IsPopImapAllowed
68 int ret = Interop.DevicePolicyManager.RestrictionGetPopimapEmailState(_dpm.GetHandle(), out state);
69 if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
71 Log.Error(Globals.LogTag, "Failed to get popimap email policy " + ret);
80 /// Releases any unmanaged resources used by this object.
82 [Obsolete("Deprecated since API level 11.")]
86 GC.SuppressFinalize(this);
90 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
92 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
93 [Obsolete("Deprecated since API level 11.")]
94 protected virtual void Dispose(bool disposing)
100 // to be used if there are any other disposable objects
103 if (_popImapCallbackId != 0)
107 RemovePopImapPolicyChangedCallback();
111 Log.Error(Globals.LogTag, e.ToString());
120 /// The PopImapPolicyChanged event is raised when the popimap-email policy is changed.
122 /// <remarks>This event will be removed automatically when EmailPolicy is destroyed.</remarks>
123 /// <since_tizen> 6 </since_tizen>
124 [Obsolete("Deprecated since API level 11.")]
125 public event EventHandler<PolicyChangedEventArgs> PopImapPolicyChanged
129 if (_popImapPolicyChanged == null)
131 AddPopImapPolicyChangedCallback();
134 _popImapPolicyChanged += value;
139 _popImapPolicyChanged -= value;
140 if (_popImapPolicyChanged == null)
142 RemovePopImapPolicyChangedCallback();
147 private void AddPopImapPolicyChangedCallback()
149 if (_popImapPolicyChangedCallback == null)
151 _popImapPolicyChangedCallback = (string name, string state, IntPtr userData) =>
153 _popImapPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(PopImapEmailPolicyName, state));
157 int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _popImapPolicyName, _popImapPolicyChangedCallback, IntPtr.Zero, out _popImapCallbackId);
158 if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
160 Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _popImapPolicyName + ", ret : " + ret);
161 throw DevicePolicyManagerErrorFactory.CreateException(ret);
165 private void RemovePopImapPolicyChangedCallback()
167 int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _popImapCallbackId);
168 if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
170 Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _popImapPolicyName + ", ret : " + ret);
171 throw DevicePolicyManagerErrorFactory.CreateException(ret);
174 _popImapPolicyChangedCallback = null;
175 _popImapCallbackId = 0;