--- /dev/null
+/*
+ * Copyright (c) 2018 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.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class DevicePolicyManager
+ {
+ internal enum ErrorCode
+ {
+ None = Tizen.Internals.Errors.ErrorCode.None,
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+ TimeOut = Tizen.Internals.Errors.ErrorCode.TimedOut,
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+ ConnectionRefused = Tizen.Internals.Errors.ErrorCode.ConnectionRefused,
+ OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory
+ }
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void PolicyChangedCallback(string name, string state, IntPtr userData);
+ // void (* dpm_policy_changed_cb)(const char* name, const char* state, void* user_data);
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_add_policy_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int AddPolicyChangedCallback(IntPtr handle, string name, PolicyChangedCallback callback, IntPtr userData, out int callbackId);
+ // int dpm_add_policy_changed_cb(device_policy_manager_h handle, const char* name, dpm_policy_changed_cb callback, void* user_data, int* id)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_remove_policy_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RemovePolicyChangedCallback(IntPtr handle, int callbackId);
+ // int dpm_remove_policy_changed_cb(device_policy_manager_h handle, int id)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_manager_create", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern IntPtr CreateHandle();
+ // device_policy_manager_h dpm_manager_create(void)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_manager_destroy", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int DestroyHandle(IntPtr handle);
+ // int dpm_manager_destroy(device_policy_manager_h handle)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_expires", CallingConvention = CallingConvention.Cdecl), ]
+ internal static extern int PasswordGetExpires(IntPtr handle, out int value);
+ // int dpm_password_get_expires(device_policy_manager_h handle, int* value)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_history", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int PasswordGetHistory(IntPtr handle, out int value);
+ // int dpm_password_get_history(device_policy_manager_h handle, int* value)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_max_inactivity_time_device_lock", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int PasswordGetMaxInactivityTimeDeviceLock(IntPtr handle, out int value);
+ // int dpm_password_get_max_inactivity_time_device_lock(device_policy_manager_h handle, int* value)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_maximum_failed_attempts_for_wipe", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int PasswordGetMaximumFailedAttemptsForWipe(IntPtr handle, out int value);
+ // int dpm_password_get_maximum_failed_attempts_for_wipe(device_policy_manager_h handle, int* value)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_min_complex_chars", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int PasswordGetMinComplexChars(IntPtr handle, out int value);
+ // int dpm_password_get_min_complex_chars(device_policy_manager_h handle, int* value)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_minimum_length", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int PasswordGetMinimumLength(IntPtr handle, out int value);
+ // int dpm_password_get_minimum_length(device_policy_manager_h handle, int* value)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_password_get_quality", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int PasswordGetQuality(IntPtr handle, out int quality);
+ // int dpm_password_get_quality(device_policy_manager_h handle, int* quality)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_messaging_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetMessagingState(IntPtr handle, string simId, out int allowed);
+ // int dpm_restriction_get_messaging_state(device_policy_manager_h handle, const char* sim_id, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_popimap_email_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetPopimapEmailState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_popimap_email_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_wifi_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetWifiState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_wifi_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_wifi_hotspot_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetWifiHotspotState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_wifi_hotspot_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_bluetooth_mode_change_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetBluetoothModeChangeState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_bluetooth_mode_change_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_bluetooth_tethering_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetBluetoothTetheringState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_bluetooth_tethering_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_browser_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetBrowserState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_browser_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_camera_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetCameraState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_camera_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_microphone_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetMicrophoneState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_microphone_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_location_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetLocationState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_location_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_external_storage_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetExternalStorageState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_external_storage_state(device_policy_manager_h handle, int* is_allowed)
+
+ [DllImport(Libraries.DevicePolicyManager, EntryPoint = "dpm_restriction_get_usb_tethering_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RestrictionGetUsbTetheringState(IntPtr handle, out int allowed);
+ // int dpm_restriction_get_usb_tethering_state(device_policy_manager_h handle, int* is_allowed)
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string DevicePolicyManager = "libdpm.so.0";
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Tizen\Tizen.csproj" />
+ </ItemGroup>
+</Project>
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26124.0
+MinimumVisualStudioVersion = 15.0.26124.0
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Security.DevicePolicyManager", "Tizen.Security.DevicePolicyManager.csproj", "{AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csproj", "{13DD8158-41C1-4B9F-B398-9E82BB74210B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Debug|x64.Build.0 = Debug|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Debug|x86.Build.0 = Debug|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Release|x64.ActiveCfg = Release|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Release|x64.Build.0 = Release|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Release|x86.ActiveCfg = Release|Any CPU
+ {AA4F6CF6-78E2-49D9-B73A-4FD63F7D90E3}.Release|x86.Build.0 = Release|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Debug|x64.Build.0 = Debug|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Debug|x86.Build.0 = Debug|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Release|x64.ActiveCfg = Release|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Release|x64.Build.0 = Release|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Release|x86.ActiveCfg = Release|Any CPU
+ {13DD8158-41C1-4B9F-B398-9E82BB74210B}.Release|x86.Build.0 = Release|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Debug|x64.Build.0 = Debug|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Debug|x86.Build.0 = Debug|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Release|x64.ActiveCfg = Release|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Release|x64.Build.0 = Release|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Release|x86.ActiveCfg = Release|Any CPU
+ {01B0E2DB-D4E8-4FB7-ACF1-A25C9920123F}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {F8F12835-C9A3-4982-9D07-F3C882536CA6}
+ EndGlobalSection
+EndGlobal
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The BluetoothPolicy provides methods to manage Bluetooth policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The BluetoothPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the BluetoothPolicy.</remarks>
+ public class BluetoothPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Bluetooth policy name. This represents <see cref="BluetoothPolicy.IsBluetoothAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string BluetoothPolicyName = "Bluetooth";
+
+ /// <summary>
+ /// The Bluetooth Tethering policy name. This represents <see cref="BluetoothPolicy.IsBluetoothTetheringAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string BluetoothTetheringPolicyName = "BluetoothTethering";
+
+ private readonly string _bluetoothPolicyName = "bluetooth";
+ private readonly string _bluetoothTetheringPolicyName = "bluetooth_tethering";
+ private int _bluetoothCallbackId;
+ private int _bluetoothTetheringCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _bluetoothPolicyChangedCallback;
+ private Interop.DevicePolicyManager.PolicyChangedCallback _bluetoothTetheringPolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _bluetoothPolicyChanged;
+ private EventHandler<PolicyChangedEventArgs> _bluetoothTetheringPolicyChanged;
+
+ internal BluetoothPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of BluetoothPolicy.
+ /// </summary>
+ ~BluetoothPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the the bluetooth state change is allowed or not.
+ /// </summary>
+ /// <value>true if the change is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsBluetoothAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetBluetoothModeChangeState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get bluetooth policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Gets whether the bluetooth tethering state change is allowed or not.
+ /// </summary>
+ /// <value>true if the change is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsBluetoothTetheringAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetBluetoothTetheringState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get bluetooth tethering policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_bluetoothCallbackId != 0)
+ {
+ try
+ {
+ RemoveBluetoothPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ if (_bluetoothTetheringCallbackId != 0)
+ {
+ try
+ {
+ RemoveBluetoothTetheringPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The BluetoothPolicyChanged event is raised when the Bluetooth policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when BluetoothPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> BluetoothPolicyChanged
+ {
+ add
+ {
+ if (_bluetoothPolicyChanged == null)
+ {
+ AddBluetoothPolicyChangedCallback();
+ }
+
+ _bluetoothPolicyChanged += value;
+ }
+
+ remove
+ {
+ _bluetoothPolicyChanged -= value;
+ if (_bluetoothPolicyChanged == null)
+ {
+ RemoveBluetoothPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddBluetoothPolicyChangedCallback()
+ {
+ if (_bluetoothPolicyChangedCallback == null)
+ {
+ _bluetoothPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _bluetoothPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(BluetoothPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _bluetoothPolicyName, _bluetoothPolicyChangedCallback, IntPtr.Zero, out _bluetoothCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _bluetoothPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveBluetoothPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _bluetoothCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _bluetoothPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _bluetoothPolicyChangedCallback = null;
+ _bluetoothCallbackId = 0;
+ }
+
+ /// <summary>
+ /// The BluetoothTetheringPolicyChanged event is raised when the Bluetooth tethering policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when BluetoothPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> BluetoothTetheringPolicyChanged
+ {
+ add
+ {
+ if (_bluetoothTetheringPolicyChanged == null)
+ {
+ AddBluetoothTetheringPolicyChangedCallback();
+ }
+
+ _bluetoothTetheringPolicyChanged += value;
+ }
+
+ remove
+ {
+ _bluetoothTetheringPolicyChanged -= value;
+ if (_bluetoothTetheringPolicyChanged == null)
+ {
+ RemoveBluetoothTetheringPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddBluetoothTetheringPolicyChangedCallback()
+ {
+ if (_bluetoothTetheringPolicyChangedCallback == null)
+ {
+ _bluetoothTetheringPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _bluetoothTetheringPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(BluetoothTetheringPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _bluetoothTetheringPolicyName, _bluetoothTetheringPolicyChangedCallback, IntPtr.Zero, out _bluetoothTetheringCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _bluetoothTetheringPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveBluetoothTetheringPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _bluetoothTetheringCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _bluetoothTetheringPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _bluetoothTetheringPolicyChangedCallback = null;
+ _bluetoothTetheringCallbackId = 0;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The BrowserPolicy provides methods to manage browser policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The BrowserPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the BrowserPolicy.</remarks>
+ public class BrowserPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Browser policy name. This represents <see cref="BrowserPolicy.IsBrowserAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string BrowserPolicyName = "Browser";
+
+ private readonly string _browserPolicyName = "browser";
+ private int _browserCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _browserPolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _browserPolicyChanged;
+
+ internal BrowserPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of BrowserPolicy.
+ /// </summary>
+ ~BrowserPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the use of web browser is allowed or not.
+ /// </summary>
+ /// <value>true if the use of web browser is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsBrowserAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetBrowserState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get browser policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_browserCallbackId != 0)
+ {
+ try
+ {
+ RemoveBrowserPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The BrowserPolicyChanged event is raised when the browser policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when BrowserPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> BrowserPolicyChanged
+ {
+ add
+ {
+ if (_browserPolicyChanged == null)
+ {
+ AddBrowserPolicyChangedCallback();
+ }
+
+ _browserPolicyChanged += value;
+ }
+
+ remove
+ {
+ _browserPolicyChanged -= value;
+ if (_browserPolicyChanged == null)
+ {
+ RemoveBrowserPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddBrowserPolicyChangedCallback()
+ {
+ if (_browserPolicyChangedCallback == null)
+ {
+ _browserPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _browserPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(BrowserPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _browserPolicyName, _browserPolicyChangedCallback, IntPtr.Zero, out _browserCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _browserPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveBrowserPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _browserCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _browserPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _browserPolicyChangedCallback = null;
+ _browserCallbackId = 0;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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
+ */
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The abstract class for Policy instances.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public abstract class DevicePolicy
+ {
+ protected internal readonly DevicePolicyManager _dpm;
+
+ internal DevicePolicy(DevicePolicyManager dpm)
+ {
+ _dpm = dpm;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 Tizen.Internals.Errors;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The DevicePolicyManager provides the methods to create handle for device policy.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public class DevicePolicyManager : IDisposable
+ {
+ private IntPtr _handle = IntPtr.Zero;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// A constructor of DevicePolicyManager that creates handle.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when connection refused or a memory error occurred.</exception>
+ public DevicePolicyManager()
+ {
+ _handle = Interop.DevicePolicyManager.CreateHandle();
+ var lastError = ErrorFacts.GetLastResult();
+ if (lastError != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ throw DevicePolicyManagerErrorFactory.CreateException(ErrorFacts.GetLastResult());
+ }
+ }
+
+ /// <summary>
+ /// Method to creates an instance of Device Policy.
+ /// </summary>
+ /// <typeparam name="T">The generic type to create.</typeparam>
+ /// <returns>An instance of policy.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when failed to create instance of the policy.</exception>
+ public T GetPolicy<T>() where T : DevicePolicy
+ {
+ try
+ {
+ T policy = Activator.CreateInstance(typeof(T),
+ System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
+ null, new object[] { this }, null) as T;
+ return policy;
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Failed to create policy. " + e.Message);
+ throw new InvalidOperationException("Failed to create policy.");
+ }
+ }
+
+ internal IntPtr GetHandle()
+ {
+ return _disposed ? IntPtr.Zero : _handle;
+ }
+
+ /// <summary>
+ /// A Destructor of DevicePolicyManager.
+ /// </summary>
+ ~DevicePolicyManager()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_handle != IntPtr.Zero)
+ {
+ int ret = Interop.DevicePolicyManager.DestroyHandle(_handle);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to destroy handle " + ret);
+ }
+
+ _handle = IntPtr.Zero;
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ }
+
+ static internal class Globals
+ {
+ internal const string LogTag = "Tizen.Security.DPM";
+ }
+
+ internal static class DevicePolicyManagerErrorFactory
+ {
+ static internal Exception CreateException(int error)
+ {
+ Interop.DevicePolicyManager.ErrorCode errCode = (Interop.DevicePolicyManager.ErrorCode)error;
+ switch (errCode)
+ {
+ case Interop.DevicePolicyManager.ErrorCode.InvalidParameter:
+ return new ArgumentException("Invalid parameter");
+ case Interop.DevicePolicyManager.ErrorCode.TimeOut:
+ return new TimeoutException("Timeout");
+ case Interop.DevicePolicyManager.ErrorCode.PermissionDenied:
+ return new UnauthorizedAccessException("Permission Denied");
+ case Interop.DevicePolicyManager.ErrorCode.OutOfMemory:
+ return new InvalidOperationException("Out of memory");
+ case Interop.DevicePolicyManager.ErrorCode.ConnectionRefused:
+ return new InvalidOperationException("Connection refused");
+ default:
+ return new InvalidOperationException("Unknown Error Code");
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The EmailPolicy provides methods to manage email policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The EmailPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the EmailPolicy.</remarks>
+ public class EmailPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The PopImap email policy name. This represents <see cref="EmailPolicy.IsPopImapAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string PopImapEmailPolicyName = "PopImapEmail";
+
+ private readonly string _popImapPolicyName = "popimap_email";
+ private int _popImapCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _popImapPolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _popImapPolicyChanged;
+
+ internal EmailPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of EmailPolicy.
+ /// </summary>
+ ~EmailPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the access to POP or IMAP email is allowed or not.
+ /// </summary>
+ /// <value>true if the POP or IMAP email is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsPopImapAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetPopimapEmailState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get popimap email policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_popImapCallbackId != 0)
+ {
+ try
+ {
+ RemovePopImapPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The PopImapPolicyChanged event is raised when the popimap-email policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when EmailPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> PopImapPolicyChanged
+ {
+ add
+ {
+ if (_popImapPolicyChanged == null)
+ {
+ AddPopImapPolicyChangedCallback();
+ }
+
+ _popImapPolicyChanged += value;
+ }
+
+ remove
+ {
+ _popImapPolicyChanged -= value;
+ if (_popImapPolicyChanged == null)
+ {
+ RemovePopImapPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddPopImapPolicyChangedCallback()
+ {
+ if (_popImapPolicyChangedCallback == null)
+ {
+ _popImapPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _popImapPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(PopImapEmailPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _popImapPolicyName, _popImapPolicyChangedCallback, IntPtr.Zero, out _popImapCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _popImapPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemovePopImapPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _popImapCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _popImapPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _popImapPolicyChangedCallback = null;
+ _popImapCallbackId = 0;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The LocationPolicy provides methods to manage location policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The LocationPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the LocationPolicy.</remarks>
+ public class LocationPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Location policy name. This represents <see cref="LocationPolicy.IsLocationAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string LocationPolicyName = "Location";
+
+ private readonly string _locationPolicyName = "location";
+ private int _locationCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _locationPolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _locationPolicyChanged;
+
+ internal LocationPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of LocationPolicy.
+ /// </summary>
+ ~LocationPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether user is allowed to change location state or not.
+ /// </summary>
+ /// <value>true if the location state change is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsLocationAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetLocationState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get location policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_locationCallbackId != 0)
+ {
+ try
+ {
+ RemoveLocationPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The LocationPolicyChanged event is raised when the location policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when LocationPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> LocationPolicyChanged
+ {
+ add
+ {
+ if (_locationPolicyChanged == null)
+ {
+ AddLocationPolicyChangedCallback();
+ }
+
+ _locationPolicyChanged += value;
+ }
+
+ remove
+ {
+ _locationPolicyChanged -= value;
+ if (_locationPolicyChanged == null)
+ {
+ RemoveLocationPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddLocationPolicyChangedCallback()
+ {
+ if (_locationPolicyChangedCallback == null)
+ {
+ _locationPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _locationPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(LocationPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _locationPolicyName, _locationPolicyChangedCallback, IntPtr.Zero, out _locationCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _locationPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveLocationPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _locationCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _locationPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _locationPolicyChangedCallback = null;
+ _locationCallbackId = 0;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The MediaPolicy provides methods to manage media policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The MediaPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the MediaPolicy.</remarks>
+ public class MediaPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Camera policy name. This represents <see cref="MediaPolicy.IsCameraAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string CameraPolicyName = "Camera";
+
+ /// <summary>
+ /// The Microphone policy name. This represents <see cref="MediaPolicy.IsMicrophoneAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string MicrophonePolicyName = "Microphone";
+
+ private readonly string _cameraPolicyName = "camera";
+ private readonly string _microphonePolicyName = "microphone";
+ private int _cameraCallbackId;
+ private int _microphoneCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _cameraPolicyChangedCallback;
+ private Interop.DevicePolicyManager.PolicyChangedCallback _microphonePolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _cameraPolicyChanged;
+ private EventHandler<PolicyChangedEventArgs> _microphonePolicyChanged;
+
+ internal MediaPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of MediaPolicy.
+ /// </summary>
+ ~MediaPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the use of camera is allowed or not.
+ /// </summary>
+ /// <value>true if the use of camera is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsCameraAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetCameraState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get camera policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Gets whether the use of microphone is allowed or not.
+ /// </summary>
+ /// <value>true if the use of microphone is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsMicrophoneAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetMicrophoneState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get microphone policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_cameraCallbackId != 0)
+ {
+ try
+ {
+ RemoveCameraPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ if (_microphoneCallbackId != 0)
+ {
+ try
+ {
+ RemoveMicrophonePolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The CameraPolicyChanged event is raised when the camera policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when MediaPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> CameraPolicyChanged
+ {
+ add
+ {
+ if (_cameraPolicyChanged == null)
+ {
+ AddCameraPolicyChangedCallback();
+ }
+
+ _cameraPolicyChanged += value;
+ }
+
+ remove
+ {
+ _cameraPolicyChanged -= value;
+ if (_cameraPolicyChanged == null)
+ {
+ RemoveCameraPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddCameraPolicyChangedCallback()
+ {
+ if (_cameraPolicyChangedCallback == null)
+ {
+ _cameraPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _cameraPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(CameraPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _cameraPolicyName, _cameraPolicyChangedCallback, IntPtr.Zero, out _cameraCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _cameraPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveCameraPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _cameraCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _cameraPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _cameraPolicyChangedCallback = null;
+ _cameraCallbackId = 0;
+ }
+
+ /// <summary>
+ /// The MicrophonePolicyChanged event is raised when the microphone policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when MediaPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> MicrophonePolicyChanged
+ {
+ add
+ {
+ if (_microphonePolicyChanged == null)
+ {
+ AddMicrophonePolicyChangedCallback();
+ }
+
+ _microphonePolicyChanged += value;
+ }
+
+ remove
+ {
+ _microphonePolicyChanged -= value;
+ if (_microphonePolicyChanged == null)
+ {
+ RemoveMicrophonePolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddMicrophonePolicyChangedCallback()
+ {
+ if (_microphonePolicyChangedCallback == null)
+ {
+ _microphonePolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _microphonePolicyChanged?.Invoke(this, new PolicyChangedEventArgs(MicrophonePolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _microphonePolicyName, _microphonePolicyChangedCallback, IntPtr.Zero, out _microphoneCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _microphonePolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveMicrophonePolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _microphoneCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _microphonePolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _microphonePolicyChangedCallback = null;
+ _microphoneCallbackId = 0;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The PasswordPolicy provides methods to manage password policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The PasswordPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the PasswordPolicy.</remarks>
+ public class PasswordPolicy : DevicePolicy
+ {
+ internal PasswordPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// Gets the number of days password expires.
+ /// </summary>
+ /// <value>Number of days after which the password expires. The default value is maximum of int.</value>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public int DaysToExpiration
+ {
+ get
+ {
+ int value = int.MaxValue;
+ int ret = Interop.DevicePolicyManager.PasswordGetExpires(_dpm.GetHandle(), out value);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password expires policy " + ret);
+ }
+
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets the number of min password history to avoid previous password.
+ /// </summary>
+ /// <value>Number of previous passwords which cannot be used when settings a new password. The default value is 0.</value>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public int MinimumPreviousHistory
+ {
+ get
+ {
+ int value = 0;
+ int ret = Interop.DevicePolicyManager.PasswordGetHistory(_dpm.GetHandle(), out value);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password history policy " + ret);
+ }
+
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets the maximum number of seconds of inactivity time before the screen timeout occurs.
+ /// </summary>
+ /// <value>Maximum inactivity time for device lock. The default value is maximum of int.</value>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public int MaxInactivityTimeDeviceLock
+ {
+ get
+ {
+ int value = int.MaxValue;
+ int ret = Interop.DevicePolicyManager.PasswordGetMaxInactivityTimeDeviceLock(_dpm.GetHandle(), out value);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password maximum inactivity time policy " + ret);
+ }
+
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets maximum number of failed attempts before device is wiped.
+ /// If user fails the last attempt, device will be wiped.
+ /// </summary>
+ /// <value>Maximum count for failed passwords. The default value is maximum of int.</value>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public int MaximumFailedAttemptsForWipe
+ {
+ get
+ {
+ int value = int.MaxValue;
+ int ret = Interop.DevicePolicyManager.PasswordGetMaximumFailedAttemptsForWipe(_dpm.GetHandle(), out value);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password maximum failed attempts policy " + ret);
+ }
+
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets minimum complex char in password.
+ /// Complex characters are all non-alphabetic characters; that is, numbers and symbols.
+ /// </summary>
+ /// <value>Number of minimum complex char in password. The default value is 0.</value>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public int MinimumRequiredComplexChars
+ {
+ get
+ {
+ int value = 0;
+ int ret = Interop.DevicePolicyManager.PasswordGetMinComplexChars(_dpm.GetHandle(), out value);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password min complext chars policy " + ret);
+ }
+
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets the minimum allowed password length.
+ /// </summary>
+ /// <value>Allowed minimum password length. The default value is 0.</value>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public int MinimunLength
+ {
+ get
+ {
+ int value = 0;
+ int ret = Interop.DevicePolicyManager.PasswordGetMinimumLength(_dpm.GetHandle(), out value);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password min length policy " + ret);
+ }
+
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets password quality.
+ /// An administrator can get the password restrictions it is imposing.
+ /// </summary>
+ /// <value>Password quality type, values of PasswordQuality. The default value is PasswordQuality UNSPECIFIED.</value>
+ /// <seealso cref="PasswordQuality"/>
+ /// <since_tizen> 6 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/dpm.password</privilege>
+ /// <privlevel>partner</privlevel>
+ public PasswordQuality Quality
+ {
+ get
+ {
+ int quality;
+ int ret = Interop.DevicePolicyManager.PasswordGetQuality(_dpm.GetHandle(), out quality);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get password quality policy " + ret);
+ return PasswordQuality.Unspecified;
+ }
+
+ return (PasswordQuality)quality;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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
+ */
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// Enumeration for dpm password quality type
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public enum PasswordQuality
+ {
+ /// <summary>
+ /// No requirements for password.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ Unspecified = 0x00,
+ /// <summary>
+ /// EAS(Exchange ActiveSync) requirement for simple password.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ Simple = 0x01,
+ /// <summary>
+ /// Some kind password required, but doesn't care what it is.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ Something = 0x10,
+ /// <summary>
+ /// Containing at least numeric character.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ Numeric = 0x20,
+ /// <summary>
+ /// Containing at least alphabetic (or other symbol) characters.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ Alphabetic = 0x40,
+ /// <summary>
+ /// Containing at least numeric and alphabetic characters.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ Alphanumeric = 0x80
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// An extended EventArgs class contains the changed dpm policy state.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public class PolicyChangedEventArgs : EventArgs
+ {
+ internal PolicyChangedEventArgs(string name, string state)
+ {
+ PolicyName = name;
+ IsAllowed = state.Equals("allowed");
+ }
+
+ /// <summary>
+ /// Gets the name of the changed policy.
+ /// </summary>
+ /// <remarks>Each policy that can raise event has the name. The policy name value is in each policy class.</remarks>
+ public string PolicyName { get; }
+
+ /// <summary>
+ /// Gets the current state of the policy.
+ /// </summary>
+ public bool IsAllowed { get; }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The StoragePolicy provides methods to manage storage policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The StoragePolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the StoragePolicy.</remarks>
+ public class StoragePolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The External storage policy name. This represents <see cref="StoragePolicy.IsExternalStorageAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string ExternalStoragePolicyName = "ExternalStorage";
+
+ private readonly string _externalStoragePolicyName = "external_storage";
+ private int _externalStorageCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _externalStoragePolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _externalStoragePolicyChanged;
+
+ internal StoragePolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of StoragePolicy.
+ /// </summary>
+ ~StoragePolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the use of external storage is allowed or not.
+ /// </summary>
+ /// <value>true if the use of external storage is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsExternalStorageAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetExternalStorageState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get external storage policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_externalStorageCallbackId != 0)
+ {
+ try
+ {
+ RemoveExternalStoragePolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The ExternalStoragePolicyChanged event is raised when the external storage policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when StoragePolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> ExternalStoragePolicyChanged
+ {
+ add
+ {
+ if (_externalStoragePolicyChanged == null)
+ {
+ AddExternalStoragePolicyChangedCallback();
+ }
+
+ _externalStoragePolicyChanged += value;
+ }
+
+ remove
+ {
+ _externalStoragePolicyChanged -= value;
+ if (_externalStoragePolicyChanged == null)
+ {
+ RemoveExternalStoragePolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddExternalStoragePolicyChangedCallback()
+ {
+ if (_externalStoragePolicyChangedCallback == null)
+ {
+ _externalStoragePolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _externalStoragePolicyChanged?.Invoke(this, new PolicyChangedEventArgs(ExternalStoragePolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _externalStoragePolicyName, _externalStoragePolicyChangedCallback, IntPtr.Zero, out _externalStorageCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _externalStoragePolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveExternalStoragePolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _externalStorageCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _externalStoragePolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _externalStoragePolicyChangedCallback = null;
+ _externalStorageCallbackId = 0;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The TelephonyPolicy provides methods to manage telephony policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The TelephonyPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the TelephonyPolicy.</remarks>
+ public class TelephonyPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Text messaging policy name. This represents <see cref="TelephonyPolicy.IsMessagingAllowed(string)"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string MessagingPolicyName = "Messaging";
+
+ private readonly string _messagingPolicyName = "messaging";
+ private int _messagingCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _messagingPolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _messagingPolicyChanged;
+
+ internal TelephonyPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of TelephonyPolicy.
+ /// </summary>
+ ~TelephonyPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Checks whether the text messaging is allowed or not.
+ /// </summary>
+ /// <param name="simId">SIM identifier</param>
+ /// <returns>true if the messaging is allowed, false otherwise.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of invalid parameter.</exception>
+ /// <exception cref="TimeoutException">Thrown when failed because of timeout.</exception>
+ public bool IsMessagingAllowed(string simId)
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetMessagingState(_dpm.GetHandle(), simId, out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ return state == 1;
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_messagingCallbackId != 0)
+ {
+ try
+ {
+ RemoveMessagingPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The MessagingPolicyChanged event is raised when the messaging policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when TelephonyPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> MessagingPolicyChanged
+ {
+ add
+ {
+ if (_messagingPolicyChanged == null)
+ {
+ AddMessagingPolicyChangedCallback();
+ }
+
+ _messagingPolicyChanged += value;
+ }
+
+ remove
+ {
+ _messagingPolicyChanged -= value;
+ if (_messagingPolicyChanged == null)
+ {
+ RemoveMessagingPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddMessagingPolicyChangedCallback()
+ {
+ if (_messagingPolicyChangedCallback == null)
+ {
+ _messagingPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _messagingPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(MessagingPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _messagingPolicyName, _messagingPolicyChangedCallback, IntPtr.Zero, out _messagingCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _messagingPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveMessagingPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _messagingCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _messagingPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _messagingPolicyChangedCallback = null;
+ _messagingCallbackId = 0;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The UsbPolicy provides methods to manage usb policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The UsbPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the UsbPolicy.</remarks>
+ public class UsbPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Usb tethering policy name. This represents <see cref="UsbPolicy.IsUsbTetheringAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string UsbTetheringPolicyName = "UsbTethering";
+
+ private readonly string _usbTetheringPolicyName = "usb_tethering";
+ private int _usbTetheringCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _usbTetheringPolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _usbTetheringPolicyChanged;
+
+ internal UsbPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of UsbPolicy.
+ /// </summary>
+ ~UsbPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the USB tethering state change is allowed.
+ /// </summary>
+ /// <value>true if the change is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsUsbTetheringAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetUsbTetheringState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get usb tethering state change policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_usbTetheringCallbackId != 0)
+ {
+ try
+ {
+ RemoveUsbTetheringPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The UsbTetheringPolicyChanged event is raised when the usb tethering policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when UsbPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> UsbTetheringPolicyChanged
+ {
+ add
+ {
+ if (_usbTetheringPolicyChanged == null)
+ {
+ AddUsbTetheringPolicyChangedCallback();
+ }
+
+ _usbTetheringPolicyChanged += value;
+ }
+
+ remove
+ {
+ _usbTetheringPolicyChanged -= value;
+ if (_usbTetheringPolicyChanged == null)
+ {
+ RemoveUsbTetheringPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddUsbTetheringPolicyChangedCallback()
+ {
+ if (_usbTetheringPolicyChangedCallback == null)
+ {
+ _usbTetheringPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _usbTetheringPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(UsbTetheringPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _usbTetheringPolicyName, _usbTetheringPolicyChangedCallback, IntPtr.Zero, out _usbTetheringCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _usbTetheringPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveUsbTetheringPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _usbTetheringCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _usbTetheringPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _usbTetheringPolicyChangedCallback = null;
+ _usbTetheringCallbackId = 0;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Security.DevicePolicyManager
+{
+ /// <summary>
+ /// The WifiPolicy provides methods to manage wifi policies.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// <remarks>The WifiPolicy is created by <seealso cref="DevicePolicyManager.GetPolicy{T}"/>. and the DevicePolicyManager instance must exists when using the WifiPolicy.</remarks>
+ public class WifiPolicy : DevicePolicy, IDisposable
+ {
+ /// <summary>
+ /// The Wifi policy name. This represents <see cref="WifiPolicy.IsWifiAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string WifiPolicyName = "Wifi";
+
+ /// <summary>
+ /// The Wifi hotspot policy name. This represents <see cref="WifiPolicy.IsWifiHotspotAllowed"/>.
+ /// </summary>
+ /// <remarks>This is used in <see cref="PolicyChangedEventArgs.PolicyName"/>.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public static readonly string WifiHotspotPolicyName = "WifiHotspot";
+
+ private readonly string _wifiPolicyName = "wifi";
+ private readonly string _wifiHotspotPolicyName = "wifi_hotspot";
+
+ private int _wifiCallbackId;
+ private int _wifiHotspotCallbackId;
+ private bool _disposed = false;
+
+ private Interop.DevicePolicyManager.PolicyChangedCallback _wifiPolicyChangedCallback;
+ private Interop.DevicePolicyManager.PolicyChangedCallback _wifiHotspotStatePolicyChangedCallback;
+ private EventHandler<PolicyChangedEventArgs> _wifiPolicyChanged;
+ private EventHandler<PolicyChangedEventArgs> _wifiHotspotPolicyChanged;
+
+ internal WifiPolicy(DevicePolicyManager dpm) : base(dpm)
+ {
+ }
+
+ /// <summary>
+ /// A Destructor of WifiPolicy.
+ /// </summary>
+ ~WifiPolicy()
+ {
+ this.Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets whether the Wi-Fi state change is allowed or not.
+ /// </summary>
+ /// <value>true if the state change is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsWifiAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetWifiState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get wifi policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Gets whether the the Wi-Fi hotspot state change is allowed or not.
+ /// </summary>
+ /// <value>true if the state change is allowed, false otherwise. The default value is true.</value>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsWifiHotspotAllowed
+ {
+ get
+ {
+ int state;
+ int ret = Interop.DevicePolicyManager.RestrictionGetWifiHotspotState(_dpm.GetHandle(), out state);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get wifi hotspot policy " + ret);
+ return true;
+ }
+
+ return state == 1;
+ }
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ // to be used if there are any other disposable objects
+ }
+
+ if (_wifiCallbackId != 0)
+ {
+ try
+ {
+ RemoveWifiStatePolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ if (_wifiHotspotCallbackId != 0)
+ {
+ try
+ {
+ RemoveWifiHotspotPolicyChangedCallback();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, e.ToString());
+ }
+ }
+
+ _disposed = true;
+ }
+ }
+
+ /// <summary>
+ /// The WifiPolicyChanged event is raised when the wifi state policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when WifiPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> WifiPolicyChanged
+ {
+ add
+ {
+ if (_wifiPolicyChanged == null)
+ {
+ AddWifiStatePolicyChangedCallback();
+ }
+
+ _wifiPolicyChanged += value;
+ }
+
+ remove
+ {
+ _wifiPolicyChanged -= value;
+ if (_wifiPolicyChanged == null)
+ {
+ RemoveWifiStatePolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddWifiStatePolicyChangedCallback()
+ {
+ if (_wifiPolicyChangedCallback == null)
+ {
+ _wifiPolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _wifiPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(WifiPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _wifiPolicyName, _wifiPolicyChangedCallback, IntPtr.Zero, out _wifiCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _wifiPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveWifiStatePolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _wifiCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _wifiPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _wifiPolicyChangedCallback = null;
+ _wifiCallbackId = 0;
+ }
+
+ /// <summary>
+ /// The WifiHotspotPolicyChanged event is raised when the wifi hotspot policy is changed.
+ /// </summary>
+ /// <remarks>This event will be removed automatically when WifiPolicy is destroyed.</remarks>
+ /// <since_tizen> 6 </since_tizen>
+ public event EventHandler<PolicyChangedEventArgs> WifiHotspotPolicyChanged
+ {
+ add
+ {
+ if (_wifiHotspotPolicyChanged == null)
+ {
+ AddWifiHotspotPolicyChangedCallback();
+ }
+
+ _wifiHotspotPolicyChanged += value;
+ }
+
+ remove
+ {
+ _wifiHotspotPolicyChanged -= value;
+ if (_wifiHotspotPolicyChanged == null)
+ {
+ RemoveWifiHotspotPolicyChangedCallback();
+ }
+ }
+ }
+
+ private void AddWifiHotspotPolicyChangedCallback()
+ {
+ if (_wifiHotspotStatePolicyChangedCallback == null)
+ {
+ _wifiHotspotStatePolicyChangedCallback = (string name, string state, IntPtr userData) =>
+ {
+ _wifiHotspotPolicyChanged?.Invoke(this, new PolicyChangedEventArgs(WifiHotspotPolicyName, state));
+ };
+ }
+
+ int ret = Interop.DevicePolicyManager.AddPolicyChangedCallback(_dpm.GetHandle(), _wifiHotspotPolicyName, _wifiHotspotStatePolicyChangedCallback, IntPtr.Zero, out _wifiHotspotCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to add policy changed callback, name " + _wifiHotspotPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+ }
+
+ private void RemoveWifiHotspotPolicyChangedCallback()
+ {
+ int ret = Interop.DevicePolicyManager.RemovePolicyChangedCallback(_dpm.GetHandle(), _wifiHotspotCallbackId);
+ if (ret != (int)Interop.DevicePolicyManager.ErrorCode.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove policy changed callback, name " + _wifiHotspotPolicyName + ", ret : " + ret);
+ throw DevicePolicyManagerErrorFactory.CreateException(ret);
+ }
+
+ _wifiHotspotStatePolicyChangedCallback = null;
+ _wifiHotspotCallbackId = 0;
+ }
+ }
+}
--- /dev/null
+---
+uid: Tizen.Security.DevicePolicyManager
+summary: The Tizen.Security.DevicePolicyManager namespace provides classes to manage the device policy management framework. The device policy management framework provides APIs to create security-aware applications that are useful in enterprise settings.
+remarks: *content
+---
+## Overview
+The primary purpose of the DPM(Device Policy Management) framework is to support enterprise applications.
+The device policy API supports the policies listed in the below, and application can subscribe to those policies from events.
+
+### Policy List
+| <center>Policy Name</center> | <center>Event</center> | <center>Description</center> |
+|:--------|:--------|:--------|
+|Wifi |WifiPolicyChanged |Specifies wether the use of Wi-Fi is allowed or not |
+|WifiHotspot |WifiHotspotChanged |Specifies whether the use of Wi-Fi hotspot is allowed or not |
+|Bluetooth |BluetoothPolicyChanged |Specifies whether the use of bluetooth is allowed or not |
+|Camera |CameraPolicyChanged |Specifies whether the use of camera is allowed or not |
+|Microphone |MicrophonePolicyChanged |Specifies whether the use of microphone is allowed or not |
+|Location |LocationPolicyChanged |Specifies whether the use of GPS is allowed or not |
+|ExternalStorage |ExternalStoragePolicyChanged |Specifies whether the use of external storage is allowed or not |
+|Messaging |MessagingPolicyChanged |Specifies whether the use of text messaging is allowed or not |
+|PopImapEmail |PopImapPolicyChanged |Specifies whether the use of POP/IMAP Email is allowed or not |
+|Browser |BrowserPolicyChanged |Specifies whether the use of browser is allowed or not |
+|BluetoothTethering |BluetoothTetheringPolicyChanged |Specifies whether the use of bluetooth tethering is allowed or not |
+|UsbTethering |UsbTetheringPolicyChanged |Specifies whether the use of usb tethering is allowed or not |
\ No newline at end of file