Add MISC Policy 75/64275/13
authorseolhee, kim <s414.kim@samsung.com>
Thu, 31 Mar 2016 06:51:10 +0000 (15:51 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Thu, 14 Apr 2016 23:24:42 +0000 (08:24 +0900)
Change-Id: I02d949dfee8ee0ea3283e50059c946fd0f0d2e21
Signed-off-by: seolhee, kim <s414.kim@samsung.com>
libs/CMakeLists.txt
libs/dpm/misc.cpp [new file with mode: 0644]
libs/dpm/misc.h [new file with mode: 0644]
libs/misc.cpp [new file with mode: 0644]
policy/misc.hxx [new file with mode: 0644]
server/CMakeLists.txt
server/misc.cpp [new file with mode: 0644]
tests/api/CMakeLists.txt
tests/api/misc.c [new file with mode: 0644]
tests/integration/CMakeLists.txt
tests/integration/misc.cpp [new file with mode: 0644]

index bedb698..6485609 100755 (executable)
@@ -27,12 +27,14 @@ SET(SOURCES policy-client.cpp
                        password.cpp
                        wifi.cpp
                        zone.cpp
+                       misc.cpp
                        dpm/client-handle.cpp
             dpm/security.cpp
                        dpm/password.cpp
                        dpm/wifi.cpp
                        dpm/zone.cpp
                        dpm/application.cpp
+                       dpm/misc.cpp
 )
 
 SET(CAPI_INCLUDE_FILES  dpm/dpm.h
@@ -42,6 +44,7 @@ SET(CAPI_INCLUDE_FILES  dpm/dpm.h
                                                dpm/password.h
                                                dpm/wifi.h
                                                dpm/zone.h
+                                               dpm/misc.h
 )
 
 SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
diff --git a/libs/dpm/misc.cpp b/libs/dpm/misc.cpp
new file mode 100644 (file)
index 0000000..0dc8b13
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ *  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 "misc.h"
+#include "misc.hxx"
+#include "policy-client.h"
+
+using namespace DevicePolicyManager;
+
+int dpm_set_camera_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.setCameraRestriction(enable);
+}
+
+int dpm_is_camera_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.isCameraRestricted();
+}
+
+int dpm_set_microphone_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.setMicrophoneRestriction(enable);
+}
+
+int dpm_is_microphone_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.isMicrophoneRestricted();
+}
+
+int dpm_set_location_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.setLocationRestriction(enable);
+}
+
+int dpm_is_location_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.isLocationRestricted();
+}
+
+int dpm_set_sd_card_restriction(dpm_client_h handle, int enable)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.setSdCardRestriction(enable);
+}
+
+int dpm_is_sd_card_restricted(dpm_client_h handle)
+{
+       assert(handle);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       Misc misc = client.createPolicyInterface<Misc>();
+       return misc.isSdCardRestricted();
+}
diff --git a/libs/dpm/misc.h b/libs/dpm/misc.h
new file mode 100644 (file)
index 0000000..43ad761
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ *  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_MISC_POLICY_H__
+#define __CAPI_MISC_POLICY_H__
+
+#include <dpm/device-policy-client.h>
+
+/**
+ * @file misc.h
+ * @brief This file provides APIs to control misc functionality
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  DPM_MISC_POLICY
+ * @{
+ */
+
+/**
+ * @brief       Allows or disallows the camera.
+ * @details     An administrator can use this API to set whether the camera
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.misc
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the camera, if false, allow the camera
+ * @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_TIMED_OUT Time out
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The handle must be created by dpm_create_client().
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_set_camera_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Gets the allow status of the camera.
+ * @details     An administrator can use this API to get the allow status of
+ *              the camera.
+ * @since_tizen 3.0
+ * @param[in]   handle Device Policy Client handle
+ * @return      status The restriction status of the camera
+ * @pre         The handle must be created by dpm_create_client().
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_is_camera_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the microphone.
+ * @details     An administrator can use this API to set whether the microphone
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.misc
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If true, disallow the microphone, if false, allow the microphone
+ * @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_TIMED_OUT Time out
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The handle must be created by dpm_create_client().
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_set_microphone_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Gets the allow status of the microphone.
+ * @details     An administrator can use this API to check the state of
+ *              the microphone.
+ * @since_tizen 3.0
+ * @param[in]   handle Device Policy Client handle
+ * @return      status The allow status of the microphone
+ * @pre         The handle must be created by dpm_create_client().
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_is_microphone_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Aallows or disallows the location.
+ * @details     An administrator can use this API to set whether the location
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.misc
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If TRUE, restrict the location, if false, disable the location
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @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()
+ * @post
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_set_location_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       API to get the allow status of the location.
+ * @details     An administrator can use this API to get the restriction status of
+ *              the location.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      status Restriction status of localtion
+ * @pre         handle must be created by dpm_create_client()
+ * @post
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_is_location_restricted(dpm_client_h handle);
+
+/**
+ * @brief       Allows or disallows the SD Card.
+ * @details     An administrator can use this API to set whether the sd card
+ *              is restricted or not.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.misc
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable If TRUE, disallow SD Card, if FALSE, allow the SD Card
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMOUT Timeout
+ * @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()
+ * @post
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_set_sd_card_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Gets the restriction status of the sd card.
+ * @details     An administrator can use this API to get the restriction status of
+ *              the sd card.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @return      status Restriction status of the SD Card
+ * @pre         handle must be created by dpm_create_client()
+ * @post
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ */
+DPM_API int dpm_is_sd_card_restricted(dpm_client_h handle);
+
+/**
+ * @} // end of DPM_MISC_POLICY
+ */
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CAPI_MISC_POLICY_H__ */
diff --git a/libs/misc.cpp b/libs/misc.cpp
new file mode 100644 (file)
index 0000000..9c7fa10
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ *  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 "misc.hxx"
+#include "audit/logger.h"
+
+namespace DevicePolicyManager {
+
+Misc::Misc(PolicyControlContext &ctxt) :
+    context(ctxt)
+{
+}
+
+Misc::~Misc()
+{
+}
+
+int Misc::setCameraRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Misc::setCameraRestriction", enable);
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+bool Misc::isCameraRestricted()
+{
+       try {
+               return context->methodCall<bool>("Misc::isCameraRestricted");
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+int Misc::setMicrophoneRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Misc::setMicrophoneRestriction", enable);
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+bool Misc::isMicrophoneRestricted()
+{
+       try {
+               return context->methodCall<bool>("Misc::isMicrophoneRestricted");
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+int Misc::setLocationRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Misc::setLocationRestriction", enable);
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+bool Misc::isLocationRestricted()
+{
+       try {
+               return context->methodCall<bool>("Misc::isLocationRestricted");
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+int Misc::setSdCardRestriction(bool enable)
+{
+       try {
+               return context->methodCall<int>("Misc::setSdCardRestriction", enable);
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+bool Misc::isSdCardRestricted()
+{
+       try {
+               return context->methodCall<bool>("Misc::isSdCardRestricted");
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+} //namespace DevicePolicyManager
diff --git a/policy/misc.hxx b/policy/misc.hxx
new file mode 100644 (file)
index 0000000..0569c6a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  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 __MISC_POLICY__
+#define __MISC_POLICY__
+
+#include "data-type.h"
+#include "policy-context.hxx"
+
+namespace DevicePolicyManager {
+
+class Misc {
+public:
+       Misc(PolicyControlContext& ctxt);
+       ~Misc();
+
+       int setCameraRestriction(bool enable);
+       bool isCameraRestricted();
+
+       int setMicrophoneRestriction(bool enable);
+       bool isMicrophoneRestricted();
+
+       int setLocationRestriction(bool enable);
+       bool isLocationRestricted();
+
+       int setSdCardRestriction(bool enable);
+       bool isSdCardRestricted();
+
+private:
+       PolicyControlContext& context;
+};
+
+} // namespace DevicePolicyManager
+
+#endif /* __MISC_POLICY__ */
index 529055d..b56211a 100644 (file)
@@ -30,6 +30,7 @@ SET(SOURCES   main.cpp
                        syspopup.cpp
                        launchpad.cpp
                        packman.cpp
+                       misc.cpp
 )
 
 ADD_EXECUTABLE(${TARGET} ${SOURCES} ${INCLUDE_SRCS})
diff --git a/server/misc.cpp b/server/misc.cpp
new file mode 100644 (file)
index 0000000..49f6e51
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ *  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 <sys/stat.h>
+#include <sys/mount.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <dd-deviced.h>
+#include <dd-control.h>
+#include <glib.h>
+
+#include "misc.hxx"
+#include "audit/logger.h"
+
+#define SETTING_MEMORY_STATUS_MMC_PATH         "/opt/storage/sdcard"
+#define SETTING_MEMORY_STATUS_MMC_PARENT_PATH  "/opt/storage/sdcard/.."
+
+#define DPM_LOCATION_DISABLED 0
+#define DPM_MMC_MOUNTED 1
+#define DPM_MMC_UMOUNTED 0
+
+namespace DevicePolicyManager {
+
+namespace {
+
+static int checkMMCStatus(void)
+{
+       int ret = 0;
+       struct stat parent_stat, mount_stat;
+
+       ret = ::stat(SETTING_MEMORY_STATUS_MMC_PATH, &mount_stat);
+       if (ret != 0) {
+               ERROR("failed to get stat : /opt/storage/sdcard");
+               return -1;
+       }
+
+       ret = ::stat(SETTING_MEMORY_STATUS_MMC_PARENT_PATH, &parent_stat);
+       if (ret != 0) {
+               ERROR("failed to get stat : /opt/stroage/sdcard/..");
+               return -1;
+       }
+
+       if (mount_stat.st_dev == parent_stat.st_dev)
+               return 0;
+       else
+               return 1;
+}
+
+static void callbackMMCResult(int result, void *p_userdata)
+{
+       return ;
+}
+
+static gboolean callbackMMCUmountTimer(void *data)
+{
+       struct mmc_contents *lp_mmc = NULL;
+       int vconf_status = -1, mmc_status = -1;
+       int ret = 0;
+
+       ret = ::vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &vconf_status);
+       if (ret != 0) {
+               ERROR("failed to get vconf mmc status");
+               return FALSE;
+       }
+
+       if (vconf_status == VCONFKEY_SYSMAN_MMC_REMOVED || vconf_status == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
+               ERROR("MMC device is ejected or not mounted");
+               return FALSE;
+       }
+
+       mmc_status = checkMMCStatus();
+       if (mmc_status == DPM_MMC_MOUNTED) {
+               lp_mmc = (struct mmc_contents *)g_malloc(sizeof(struct mmc_contents));
+               lp_mmc->mmc_cb = callbackMMCResult;
+               ret = ::deviced_request_unmount_mmc(lp_mmc, MNT_FORCE);
+               if (ret == -1) {
+                       ERROR("failed to request to umount");
+                       return FALSE;
+               }
+               g_free(lp_mmc);
+       } else if (mmc_status == DPM_MMC_UMOUNTED) {
+               WARN("MMC was umounted");
+               return FALSE;
+       } else {
+               ERROR("failed to check status of mmc");
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+static gboolean callbackMMCMountTimer(void *data)
+{
+       struct mmc_contents *lp_mmc = NULL;
+       int vconf_status = -1, mmc_status = -1;
+       int ret = 0;
+
+       ret = ::vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &vconf_status);
+       if (ret != 0) {
+               ERROR("failed to get vconf mmc status");
+               return FALSE;
+       }
+
+       if (vconf_status != VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
+               ERROR("MMC was mounted");
+               return FALSE;
+       }
+
+       mmc_status = checkMMCStatus();
+       if (mmc_status == DPM_MMC_UMOUNTED) {
+               lp_mmc = (struct mmc_contents *)g_malloc(sizeof(struct mmc_contents));
+               lp_mmc->mmc_cb = callbackMMCResult;
+               ret = ::deviced_request_mount_mmc(lp_mmc);
+               if (ret == -1) {
+                       ERROR("failed to request to mount");
+                       return FALSE;
+               }
+               g_free(lp_mmc);
+       } else if (mmc_status == DPM_MMC_MOUNTED) {
+               WARN("MMC was mounted");
+               return FALSE;
+       } else {
+               ERROR("failed to check status of mmc");
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+} // namespace
+
+Misc::Misc(PolicyControlContext &ctxt) :
+    context(ctxt)
+{
+       context.registerParametricMethod(this, (int)(Misc::setCameraRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Misc::isCameraRestricted));
+       context.registerParametricMethod(this, (int)(Misc::setMicrophoneRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Misc::isMicrophoneRestricted));
+       context.registerParametricMethod(this, (int)(Misc::setLocationRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Misc::isLocationRestricted));
+       context.registerParametricMethod(this, (int)(Misc::setSdCardRestriction)(bool));
+       context.registerNonparametricMethod(this, (bool)(Misc::isSdCardRestricted));
+}
+
+Misc::~Misc()
+{
+}
+
+int Misc::setCameraRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Misc::isCameraRestricted()
+{
+       bool ret = true;
+       return ret;
+}
+
+int Misc::setMicrophoneRestriction(bool enable)
+{
+       return 0;
+}
+
+bool Misc::isMicrophoneRestricted()
+{
+       bool ret = true;
+       return ret;
+}
+
+int Misc::setLocationRestriction(bool enable)
+{
+       int ret = 0;
+       int status = -1;
+
+       ret = ::vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &status);
+       if (ret != 0) {
+               ERROR("failed to get the status of location");
+               return ret;
+       }
+
+       if (status != DPM_LOCATION_DISABLED) {
+               ret = ::vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, DPM_LOCATION_DISABLED);
+               if (ret != 0)
+                       ERROR("failed to set key(VCONFKEY_LOACTION_USE_MY_LOACATION)");
+
+               ret = ::vconf_set_int(VCONFKEY_LOCATION_ENABLED, DPM_LOCATION_DISABLED);
+               if (ret != 0)
+                       ERROR("failed to set key(VCONFKEY_LOCATION_ENABLED)");
+
+               ret = ::vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, DPM_LOCATION_DISABLED);
+               if (ret != 0)
+                       ERROR("failed to set key(VCONFKEY_LOCATION_NETWORK_ENABLED)");
+       }
+
+       return ret;
+}
+
+bool Misc::isLocationRestricted()
+{
+       bool ret = true;
+       return ret;
+}
+
+int Misc::setSdCardRestriction(bool enable)
+{
+       int ret = 0;
+
+       if (enable == false)
+               ::g_timeout_add(5000, callbackMMCUmountTimer, NULL);
+       else if (enable == true)
+               ::g_timeout_add(5000, callbackMMCMountTimer, NULL);
+
+       ret = ::deviced_mmc_control(enable);
+       if (ret != 0)
+               ERROR("failed to control MMC device");
+
+       return ret;
+}
+
+bool Misc::isSdCardRestricted()
+{
+       int ret = true;
+       return ret;
+}
+
+} // namespace DevicePolicyManager
index 388129d..b19fb95 100644 (file)
@@ -20,6 +20,7 @@ SET(API_TEST_SOURCES main.c
                      security.c
                      password.c
                      testbench.c
+                     misc.c
 )
 
 ADD_EXECUTABLE(${API_TEST_TARGET} ${API_TEST_SOURCES})
diff --git a/tests/api/misc.c b/tests/api/misc.c
new file mode 100644 (file)
index 0000000..d44f2c2
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ *  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/misc.h>
+#include "testbench.h"
+
+static int misc_camera(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_camera_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_camera_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int misc_microphone(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_microphone_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_microphone_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int misc_location(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_location_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_location_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+static int misc_sd_card(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_sd_card_restriction(handle, true) != 0) {
+               dpm_destroy_client(handle);
+               return TEST_FAILED;
+       }
+
+       enable = dpm_is_sd_card_restricted(handle);
+       if (enable == true) {
+               dpm_destroy_client(handle);
+               return TEST_SUCCESSED;
+       }
+
+       dpm_destroy_client(handle);
+       return TEST_FAILED;
+}
+
+struct testcase misc_testcase_camera = {
+       .description = "dpm_camera",
+       .handler = misc_camera
+};
+
+struct testcase misc_testcase_microphone = {
+       .description = "dpm_microphone",
+       .handler = misc_microphone
+};
+
+struct testcase misc_testcase_location = {
+       .description = "dpm_location",
+       .handler = misc_location
+};
+
+struct testcase misc_testcase_sd_card = {
+       .description = "dpm_sd_card",
+       .handler = misc_sd_card
+};
+
+void TESTCASE_CONSTRUCTOR misc_policy_build_testcase(void)
+{
+       testbench_populate_testcase(&misc_testcase_camera);
+       testbench_populate_testcase(&misc_testcase_microphone);
+       testbench_populate_testcase(&misc_testcase_location);
+       testbench_populate_testcase(&misc_testcase_sd_card);
+}
index a0a6a64..ee80d2b 100755 (executable)
@@ -20,11 +20,13 @@ SET(INTEGRATION_TEST_SOURCES main.cpp
                                                         application.cpp
                                                         security.cpp
                                                         zone.cpp
+                                                        misc.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_TESTBENCH}/testbench.cpp
 )
 
diff --git a/tests/integration/misc.cpp b/tests/integration/misc.cpp
new file mode 100644 (file)
index 0000000..10046eb
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *  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 "testbench/testbench.h"
+#include "audit/logger.h"
+#include "misc.hxx"
+
+TESTCASE(CameraTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Misc misc = client.createPolicyInterface<DevicePolicyManager::Misc>();
+
+       error = misc.setCameraRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = misc.isCameraRestricted();
+       TEST_EXPECT(true, status);
+}
+
+TESTCASE(MicrophoneTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Misc misc = client.createPolicyInterface<DevicePolicyManager::Misc>();
+
+       error = misc.setMicrophoneRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = misc.isMicrophoneRestricted();
+       TEST_EXPECT(true, status);
+}
+
+TESTCASE(LocationTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Misc misc = client.createPolicyInterface<DevicePolicyManager::Misc>();
+
+       error = misc.setLocationRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = misc.isLocationRestricted();
+       TEST_EXPECT(true, status);
+}
+
+TESTCASE(SDCardTest)
+{
+       DevicePolicyClient client;
+       int error = -1;
+       bool status = false;
+
+       TEST_EXPECT(0, client.connect());
+
+       DevicePolicyManager::Misc misc = client.createPolicyInterface<DevicePolicyManager::Misc>();
+
+       error = misc.setSdCardRestriction(true);
+       TEST_EXPECT(0, error);
+
+       status = misc.isSdCardRestricted();
+       TEST_EXPECT(true, status);
+}