Add Restriction Policy 70/64270/16
authorseolhee, kim <s414.kim@samsung.com>
Thu, 31 Mar 2016 06:31:57 +0000 (15:31 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Thu, 14 Apr 2016 23:29:50 +0000 (08:29 +0900)
Change-Id: I22aacccc1d4bbaac91d2b4d9faf730ea76f92492
Signed-off-by: seolhee, kim <s414.kim@samsung.com>
libs/CMakeLists.txt
libs/dpm/restriction.cpp [new file with mode: 0644]
libs/dpm/restriction.h [new file with mode: 0644]
libs/restriction.cpp [new file with mode: 0644]
policy/restriction.hxx [new file with mode: 0644]
server/CMakeLists.txt
server/restriction.cpp [new file with mode: 0644]
tests/api/CMakeLists.txt
tests/api/restriction.c [new file with mode: 0644]
tests/integration/CMakeLists.txt
tests/integration/restriction.cpp [new file with mode: 0644]

index 6485609..497b97c 100755 (executable)
@@ -28,6 +28,7 @@ SET(SOURCES policy-client.cpp
                        wifi.cpp
                        zone.cpp
                        misc.cpp
+                       restriction.cpp
                        dpm/client-handle.cpp
             dpm/security.cpp
                        dpm/password.cpp
@@ -35,6 +36,7 @@ SET(SOURCES policy-client.cpp
                        dpm/zone.cpp
                        dpm/application.cpp
                        dpm/misc.cpp
+                       dpm/restriction.cpp
 )
 
 SET(CAPI_INCLUDE_FILES  dpm/dpm.h
diff --git a/libs/dpm/restriction.cpp b/libs/dpm/restriction.cpp
new file mode 100644 (file)
index 0000000..c7aef0b
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <cassert>
+
+#include "restriction.h"
+#include "restriction.hxx"
+#include "policy-client.h"
+
+using namespace DevicePolicyManager;
+
+int dpm_set_clipboard_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setClipboardRestriction(enable);
+}
+
+int dpm_is_clipboard_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isClipboardRestricted();
+}
+
+int dpm_set_clipboard_share_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setClipboardShareRestriction(enable);
+}
+
+int dpm_is_clipboard_share_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isClipboardShareRestricted();
+}
+
+
+int dpm_set_settings_changes_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setSettingsChangesRestriction(enable);
+}
+
+int dpm_is_settings_changes_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isSettingsChangesRestricted();
+}
+
+int dpm_set_background_data_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setBackgroundDataRestriction(enable);
+}
+
+int dpm_is_background_data_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isBackgroundDataRestricted();
+}
+
+int dpm_set_usb_debugging_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setUsbDebuggingRestriction(enable);
+}
+
+int dpm_is_usb_debugging_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isUsbDebuggingRestricted();
+}
+
+int dpm_set_usb_mass_storage_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setUsbMassStorageRestriction(enable);
+}
+
+int dpm_is_usb_mass_storage_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isUsbMassStorageRestricted();
+}
+
+int dpm_set_factory_reset_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.setFactoryResetRestriction(enable);
+}
+
+int dpm_is_factory_reset_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient& client = GetDevicePolicyClient(handle);
+       Restriction restriction = client.createPolicyInterface<Restriction>();
+       return restriction.isFactoryResetRestricted();
+}
diff --git a/libs/dpm/restriction.h b/libs/dpm/restriction.h
new file mode 100644 (file)
index 0000000..666d27f
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __CAPI_RESTRICTION_POLICY_H__
+#define __CAPI_RESTRICTION_POLICY_H__
+
+#include <dpm/device-policy-client.h>
+
+/**
+ * @file restriction.h
+ * @brief This file provides APIs to control restriction functionality
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  DPM_RESTRICTION_POLICY
+ * @{
+ */
+
+/**
+ * @brief       Allows or disallows the user to use the clipboard.
+ * @details     An administrator can use this API to set whether the clipboard.
+ *              is allowed or not
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the clipboard, if false, allow the clipboard
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_clipboard_restricted()
+ */
+DPM_API int dpm_set_clipboard_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the clipboard restriction is enable or not.
+ * @details     An administrator can use this API to check the restriction status of
+ *              the clipboard
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the clipboard is disallowed, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_clipboard_restriction()
+ */
+DPM_API int dpm_is_clipboard_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the user to share the clipboard data between applications.
+ * @details     An administrator can use this API to set whether the clipboard
+ *              is allowed or not for sharing between applications.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow to share the clipboard, if false, allow to share the clipboard
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_clipboard_share_restriction()
+ */
+DPM_API int dpm_set_clipboard_share_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the clipboard share restriction is enable or not.
+ * @details     An administrator can use this API to check the restriction status of
+ *              sharing clipboard between applications.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the clipboard cannot shared data, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_clipboard_share_restriction()
+ */
+DPM_API int dpm_is_clipboard_share_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the user to use the settings changes.
+ * @details     An administrator can use this API to set whether the Settins
+ *              changes is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the settings changes, if false, allow
+ *              the settings changes
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_settings_changes_restricted()
+ */
+DPM_API int dpm_set_settings_changes_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the settings changes restriction is enable or not.
+ * @details     An administrator can use this API to get the allow statsus of
+ *              the Settins changes.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the settings changes is disallowed, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_settings_changes_restriction()
+ */
+DPM_API int dpm_is_settings_changes_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the user to use the background data.
+ * @details     An administrator can use this API to set whether the background
+ *              data is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the background data, if false, allow
+ *              the background data
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_background_data_restricted()
+ */
+DPM_API int dpm_set_background_data_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the background data restriction is enable or not.
+ * @details     An administrator can use this API to check the restriction status of
+ *              the background data.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the background data is disallowed, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_background_data_restriction()
+ */
+DPM_API int dpm_is_background_data_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the user to use the usb debugging
+ * @details     An administrator can use this API to set whether the usb debugging
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the usb debugging, if false, disallow the usb
+ *              debugging
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_usb_debugging_restricted()
+ */
+DPM_API int dpm_set_usb_debugging_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the usb debugging restriction is enable or not.
+ * @details     An administrator can use this API to check the restriction status of
+ *              the usb debugging.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the usb debugging is disallowed, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_usb_debugging_restriction()
+ */
+DPM_API int dpm_is_usb_debugging_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the user to use the usb mass storage
+ * @details     An administrator can use this API to set whether the usb mass
+ *              storage is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the usb mass storage, if false, allow
+ *              the usb mas storage
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_usb_mass_storage_restricted()
+ */
+DPM_API int dpm_set_usb_mass_storage_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the usb mass storage restriction is enable or not.
+ * @details     An administrator can use this API to check the restriction status of
+ *              the usb mass storage.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the usb mass storage is disallowed, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_usb_mass_storage_restriction()
+ */
+DPM_API int dpm_is_usb_mass_storage_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the user to use the factory reset
+ * @details     An administrator can use this API to set whether the factory
+ *              reset is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.restriction
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the factory reset, if false, allow
+ *              the factory reset
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_ACCESS_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_factory_reset_restricted()
+ */
+DPM_API int dpm_set_factory_reset_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the factory reset restriction is enable or not.
+ * @details     An administrator can use this API to check the restriction status of
+ *              factory reset.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      true if the factory reset is disallowed, else false
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_factory_reset_restriction()
+ */
+DPM_API int dpm_is_factory_reset_restricted(dpm_client_h handle);
+
+/**
+ * @} // end of DPM_RESTRICTION_POLICY
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CAPI_RESTRICTION_POLICY_H__ */
diff --git a/libs/restriction.cpp b/libs/restriction.cpp
new file mode 100644 (file)
index 0000000..c117150
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "restriction.hxx"
+#include "audit/logger.h"
+
+namespace DevicePolicyManager
+{
+
+Restriction::Restriction(PolicyControlContext& ctxt)
+       : context(ctxt)
+{
+}
+
+Restriction::~Restriction()
+{
+}
+
+int Restriction::setClipboardRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setClipboardRestriction", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isClipboardRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isClipboardRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Restriction::setClipboardShareRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setClipboardShareRestriction", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isClipboardShareRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isClipboardShareRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+
+int Restriction::setSettingsChangesRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setSettingsChangesRestriction",enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isSettingsChangesRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isSettingsChangesRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Restriction::setBackgroundDataRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setBackgroundDataRestriction", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isBackgroundDataRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isBackgroundDataRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Restriction::setUsbDebuggingRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setUsbDebuggingRestriction", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isUsbDebuggingRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isUsbDebuggingRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Restriction::setUsbMassStorageRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setUsbMassStorageRestriction", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isUsbMassStorageRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isUsbMassStorageRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Restriction::setFactoryResetRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Restriction::setFactoryResetRestriction", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool Restriction::isFactoryResetRestricted()
+{
+       try {
+               return context->methodCall<bool>("Restriction::isFactoryResetRestricted");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+} //namespace DevicePolicyManager
diff --git a/policy/restriction.hxx b/policy/restriction.hxx
new file mode 100644 (file)
index 0000000..8d63947
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __RESTRICTION_POLICY__
+#define __RESTRICTION_POLICY__
+
+#include "data-type.h"
+#include "policy-context.hxx"
+
+namespace DevicePolicyManager
+{
+
+class Restriction
+{
+public:
+       Restriction(PolicyControlContext& ctxt);
+       ~Restriction();
+
+       int setClipboardRestriction(bool enable);
+       bool isClipboardRestricted();
+       int setClipboardShareRestriction(bool enable);
+       bool isClipboardShareRestricted();
+
+       int setSettingsChangesRestriction(bool enable);
+       bool isSettingsChangesRestricted();
+
+       int setBackgroundDataRestriction(bool enable);
+       bool isBackgroundDataRestricted();
+
+       int setUsbDebuggingRestriction(bool enable);
+       bool isUsbDebuggingRestricted();
+
+       int setUsbMassStorageRestriction(bool enable);
+       bool isUsbMassStorageRestricted();
+
+       int setFactoryResetRestriction(bool enable);
+       bool isFactoryResetRestricted();
+
+private:
+       PolicyControlContext& context;
+};
+
+} // namespace DevicePolicyManager
+
+#endif /* __RESTRICTION_POLICY__ */
index b56211a..84fa455 100644 (file)
@@ -31,6 +31,7 @@ SET(SOURCES   main.cpp
                        launchpad.cpp
                        packman.cpp
                        misc.cpp
+                       restriction.cpp
 )
 
 ADD_EXECUTABLE(${TARGET} ${SOURCES} ${INCLUDE_SRCS})
diff --git a/server/restriction.cpp b/server/restriction.cpp
new file mode 100644 (file)
index 0000000..9dfb426
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "restriction.hxx"
+#include "audit/logger.h"
+
+namespace DevicePolicyManager
+{
+
+Restriction::Restriction(PolicyControlContext& ctxt)
+       : context(ctxt)
+{
+       context.registerParametricMethod(this, (int)(Restriction::setClipboardRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isClipboardRestricted));
+       context.registerParametricMethod(this, (int)(Restriction::setClipboardShareRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isClipboardShareRestricted));
+       context.registerParametricMethod(this, (int)(Restriction::setSettingsChangesRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isSettingsChangesRestricted));
+       context.registerParametricMethod(this, (int)(Restriction::setBackgroundDataRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isBackgroundDataRestricted));
+       context.registerParametricMethod(this, (int)(Restriction::setUsbDebuggingRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isUsbDebuggingRestricted));
+       context.registerParametricMethod(this, (int)(Restriction::setUsbMassStorageRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isUsbMassStorageRestricted));
+       context.registerParametricMethod(this, (int)(Restriction::setFactoryResetRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Restriction::isFactoryResetRestricted));
+}
+
+Restriction::~Restriction()
+{
+}
+
+int Restriction::setClipboardRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isClipboardRestricted()
+{
+       return true;
+}
+
+int Restriction::setClipboardShareRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isClipboardShareRestricted()
+{
+       return true;
+}
+
+
+int Restriction::setSettingsChangesRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isSettingsChangesRestricted()
+{
+       return true;
+}
+
+int Restriction::setBackgroundDataRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isBackgroundDataRestricted()
+{
+       return true;
+}
+
+int Restriction::setUsbDebuggingRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isUsbDebuggingRestricted()
+{
+       return true;
+}
+
+int Restriction::setUsbMassStorageRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isUsbMassStorageRestricted()
+{
+       return true;
+}
+
+int Restriction::setFactoryResetRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Restriction::isFactoryResetRestricted()
+{
+       return true;
+}
+
+Restriction restrictionPolicy(Server::instance());
+
+} // namespace DevicePolicyManager
+
index b19fb95..776649a 100644 (file)
@@ -21,6 +21,7 @@ SET(API_TEST_SOURCES main.c
                      password.c
                      testbench.c
                      misc.c
+                     restriction.c
 )
 
 ADD_EXECUTABLE(${API_TEST_TARGET} ${API_TEST_SOURCES})
diff --git a/tests/api/restriction.c b/tests/api/restriction.c
new file mode 100644 (file)
index 0000000..78a9f18
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <dpm/restriction.h>
+#include "testbench.h"
+
+static int restriction_clipboard(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_clipboard_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_clipboard_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int restriction_clipboard_share(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_clipboard_share_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_clipboard_share_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int restriction_settings_changes(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_settings_changes_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_settings_changes_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int restriction_background_data(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_background_data_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_background_data_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int restriction_usb_debugging(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_usb_debugging_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_usb_debugging_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int restriction_usb_mass_storage(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_usb_mass_storage_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_usb_mass_storage_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int restriction_factory_reset(struct testcase* tc)
+{
+       dpm_client_h handle;
+       bool enable = false;
+
+       handle = dpm_create_client();
+       if (handle == NULL) {
+               printf("Failed to create client handle\n");
+               return TEST_FAILED;
+       }
+
+       if (dpm_set_factory_reset_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_factory_reset_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+struct testcase restriction_testcase_clipboard = {
+       .description = "dpm_clipboard",
+       .handler = restriction_clipboard
+};
+
+struct testcase restriction_testcase_clipboard_share = {
+       .description = "dpm_clipboard_share",
+       .handler = restriction_clipboard_share
+};
+
+struct testcase restriction_testcase_settings_changes = {
+       .description = "dpm_settings_changes",
+       .handler = restriction_settings_changes
+};
+
+struct testcase restriction_testcase_background_data = {
+       .description = "dpm_background_data",
+       .handler = restriction_background_data
+};
+
+struct testcase restriction_testcase_usb_debugging = {
+       .description = "dpm_usb_debugging",
+       .handler = restriction_usb_debugging
+};
+
+struct testcase restriction_testcase_usb_mass_storage = {
+       .description = "dpm_usb_mass_storage",
+       .handler = restriction_usb_mass_storage
+};
+
+struct testcase restriction_testcase_factory_reset = {
+       .description = "dpm_factory_reset",
+       .handler = restriction_factory_reset
+};
+
+void TESTCASE_CONSTRUCTOR restriction_policy_build_testcase(void)
+{
+       testbench_populate_testcase(&restriction_testcase_clipboard);
+       testbench_populate_testcase(&restriction_testcase_clipboard_share);
+       testbench_populate_testcase(&restriction_testcase_settings_changes);
+       testbench_populate_testcase(&restriction_testcase_background_data);
+       testbench_populate_testcase(&restriction_testcase_usb_debugging);
+       testbench_populate_testcase(&restriction_testcase_usb_mass_storage);
+       testbench_populate_testcase(&restriction_testcase_factory_reset);
+}
index ee80d2b..b11faf5 100755 (executable)
@@ -21,12 +21,14 @@ SET(INTEGRATION_TEST_SOURCES main.cpp
                                                         security.cpp
                                                         zone.cpp
                                                         misc.cpp
+                                                        restriction.cpp
                                                         ${DPM_LIBS}/policy-client.cpp
                                                         ${DPM_LIBS}/application.cpp
                                                         ${DPM_LIBS}/administration.cpp
                                                         ${DPM_LIBS}/security.cpp
                                                         ${DPM_LIBS}/zone.cpp
                                                         ${DPM_LIBS}/misc.cpp
+                                                        ${DPM_LIBS}/restriction.cpp
                                                         ${DPM_TESTBENCH}/testbench.cpp
 )
 
diff --git a/tests/integration/restriction.cpp b/tests/integration/restriction.cpp
new file mode 100644 (file)
index 0000000..5ddd556
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "policy-client.h"
+#include "restriction.hxx"
+#include "testbench/testbench.h"
+
+#include "audit/logger.h"
+
+TESTCASE(ClipboardTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Restriction restriction = client.createPolicyInterface<DevicePolicyManager::Restriction>();
+
+       error = restriction.setClipboardRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isClipboardRestricted();
+       TEST_EXPECT(true, status);
+
+       error = restriction.setClipboardRestriction(false);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isClipboardRestricted();
+       TEST_EXPECT(false, status);
+
+       error = restriction.setClipboardShareRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isClipboardShareRestricted();
+       TEST_EXPECT(true, status);
+
+       error = restriction.setClipboardShareRestriction(false);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isClipboardShareRestricted();
+       TEST_EXPECT(false, status);
+}
+
+TESTCASE(SettingsChangesTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Restriction restriction = client.createPolicyInterface<DevicePolicyManager::Restriction>();
+
+       error = restriction.setSettingsChangesRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isSettingsChangesRestricted();
+       TEST_EXPECT(true, status);
+
+       error = restriction.setSettingsChangesRestriction(false);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isSettingsChangesRestricted();
+       TEST_EXPECT(false, status);
+}
+
+TESTCASE(SettingsBackgroundData)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Restriction restriction = client.createPolicyInterface<DevicePolicyManager::Restriction>();
+
+       error = restriction.setBackgroundDataRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isBackgroundDataRestricted();
+       TEST_EXPECT(true, status);
+
+       error = restriction.setBackgroundDataRestriction(false);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isBackgroundDataRestricted();
+       TEST_EXPECT(false, status);
+}
+
+TESTCASE(UsbDebuggingTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Restriction restriction = client.createPolicyInterface<DevicePolicyManager::Restriction>();
+
+       error = restriction.setUsbDebuggingRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isUsbDebuggingRestricted();
+       TEST_EXPECT(true, status);
+
+       error = restriction.setUsbDebuggingRestriction(false);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isUsbDebuggingRestricted();
+       TEST_EXPECT(false, status);
+}
+
+TESTCASE(FactoryResetTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Restriction restriction = client.createPolicyInterface<DevicePolicyManager::Restriction>();
+
+       error = restriction.setFactoryResetRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isFactoryResetRestricted();
+       TEST_EXPECT(true, status);
+
+       error = restriction.setFactoryResetRestriction(false);
+       TEST_EXPECT(0, error);
+
+       status = restriction.isFactoryResetRestricted();
+       TEST_EXPECT(false, status);
+}