src/ui/naviframe.cpp
src/ui/conformant-window.cpp)
-#INCLUDE("${TIZEN_PROFILE_NAME}.cmake")
+SET(TESTCASES src/policy/application.cpp
+ src/policy/bluetooth.cpp
+ src/policy/password.cpp
+ src/policy/security.cpp
+ src/policy/restriction.cpp
+ src/policy/wifi.cpp
+ src/policy/zone.cpp)
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -fPIE -std=${CXX_STD}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wp,-U_FORTIFY_SOURCE")
+++ /dev/null
-#
-# Copyright (c) 2015 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.
-#
-
-SET(TESTCASES
- src/application.c
- src/password.c
- src/security.c
- src/restriction.c
-)
+++ /dev/null
-#
-# Copyright (c) 2015 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.
-#
-
-SET(TESTCASES
- src/application.c
- src/password.c
- src/security.c
- src/restriction.c
-)
+++ /dev/null
-#
-# Copyright (c) 2015 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.
-#
-
-SET(TESTCASES
- src/application.c
- src/password.c
- src/security.c
- src/restriction.c
- src/zone.c
-)
BuildRequires: pkgconfig(dpm)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(klay)
-Requires: %{name}-binary = %{version}-%{release}
-Recommends: %{name}-profile_common = %{version}-%{release}
%description
Device Policy Manager test toolkit pakcage
-%package profile_common
-Summary: Tizen DPM test toolkit binary for common profile
-Provides: %{name}-binary = %{version}-%{release}
-Conflicts: %{name}-profile_mobile
-Conflicts: %{name}-profile_wearable
-Conflicts: %{name}-profile_tv
-Conflicts: %{name}-profile_ivi
-%description profile_common
-Device Policy Manager test toolkit binary for common profile.
-
-%package profile_mobile
-Summary: Tizen DPM test toolkit binary for mobile profile
-Provides: %{name}-binary = %{version}-%{release}
-Conflicts: %{name}-profile_common
-Conflicts: %{name}-profile_wearable
-Conflicts: %{name}-profile_tv
-Conflicts: %{name}-profile_ivi
-%description profile_mobile
-Device Policy Manager test toolkit binary for mobile profile.
-%package profile_wearable
-Summary: Tizen DPM test toolkit binary for wearable profile
-Provides: %{name}-binary = %{version}-%{release}
-Conflicts: %{name}-profile_mobile
-Conflicts: %{name}-profile_common
-Conflicts: %{name}-profile_tv
-Conflicts: %{name}-profile_ivi
-%description profile_wearable
-Device Policy Manager test toolkit binary for wearable profile.
-
-%package profile_tv
-Summary: Tizen DPM test toolkit binary for tv profile
-Provides: %{name}-binary = %{version}-%{release}
-Conflicts: %{name}-profile_mobile
-Conflicts: %{name}-profile_wearable
-Conflicts: %{name}-profile_common
-Conflicts: %{name}-profile_ivi
-%description profile_tv
-Device Policy Manager test toolkit binary for tv profile.
-
-%package profile_ivi
-Summary: Tizen DPM test toolkit binary for ivi profile
-Provides: %{name}-binary = %{version}-%{release}
-Conflicts: %{name}-profile_mobile
-Conflicts: %{name}-profile_wearable
-Conflicts: %{name}-profile_tv
-Conflicts: %{name}-profile_common
-%description profile_ivi
-Device Policy Manager test toolkit binary for ivi profile.
-
%prep
%setup -q
%restore_fcommon
%endif
-mkdir -p bin
-
cmake . -DCMAKE_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
-DCMAKE_DESKTOP_ICON_DIR="%{TZ_SYS_RW_ICONS}/default/small" \
- -DCMAKE_APP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
- -DTIZEN_PROFILE_NAME=common
-make %{?jobs:-j%jobs}
-cp %{name} bin/%{name}.common
+ -DCMAKE_APP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}"
-cmake . -DCMAKE_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
- -DCMAKE_DESKTOP_ICON_DIR="%{TZ_SYS_RW_ICONS}/default/small" \
- -DCMAKE_APP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
- -DTIZEN_PROFILE_NAME=mobile
-make %{?jobs:-j%jobs}
-cp %{name} bin/%{name}.mobile
-
-cmake . -DCMAKE_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
- -DCMAKE_DESKTOP_ICON_DIR="%{TZ_SYS_RW_ICONS}/default/small" \
- -DCMAKE_APP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
- -DTIZEN_PROFILE_NAME=wearable
make %{?jobs:-j%jobs}
-cp %{name} bin/%{name}.wearable
-
-cmake . -DCMAKE_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
- -DCMAKE_DESKTOP_ICON_DIR="%{TZ_SYS_RW_ICONS}/default/small" \
- -DCMAKE_APP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
- -DTIZEN_PROFILE_NAME=tv
-make %{?jobs:-j%jobs}
-cp %{name} bin/%{name}.tv
-
-cmake . -DCMAKE_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
- -DCMAKE_DESKTOP_ICON_DIR="%{TZ_SYS_RW_ICONS}/default/small" \
- -DCMAKE_APP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
- -DTIZEN_PROFILE_NAME=ivi
-make %{?jobs:-j%jobs}
-cp %{name} bin/%{name}.ivi
%install
%make_install
-rm %{buildroot}%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-install -m 0755 bin/%{name}.* %{buildroot}%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/
%post
/sbin/ldconfig
%files
%manifest org.tizen.dpm-toolkit.manifest
%defattr(-,root,root,-)
+%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/*
%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/res/*
%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/dpm-toolkit.xml
%{TZ_SYS_RO_PACKAGES}/org.tizen.dpm-toolkit.xml
%{TZ_SYS_RW_ICONS}/default/small/org.tizen.dpm-toolkit.png
-
-%post profile_common
-ln -sf %{name}.common %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%preun profile_common
-rm %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%files profile_common
-%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}.common
-
-%post profile_mobile
-ln -sf %{name}.mobile %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%preun profile_mobile
-rm %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%files profile_mobile
-%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}.mobile
-
-%post profile_wearable
-ln -sf %{name}.wearable %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%preun profile_wearable
-rm %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%files profile_wearable
-%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}.wearable
-
-%post profile_tv
-ln -sf %{name}.tv %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%preun profile_tv
-rm %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%files profile_tv
-%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}.tv
-
-%post profile_ivi
-ln -sf %{name}.ivi %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%preun profile_ivi
-rm %{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}
-%files profile_ivi
-%{TZ_SYS_RO_APP}/org.tizen.dpm-toolkit/bin/%{name}.ivi
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/application.h>
+
+class ApplicationPolicy : public AbstractPolicy {
+public:
+ ApplicationPolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Install Package", this, &ApplicationPolicy::installPackage),
+ WorkbenchActionDelegate("Uninstall Package", this, &ApplicationPolicy::uninstallPackage),
+ WorkbenchActionDelegate("Add Privilege to Blacklist", this, &ApplicationPolicy::addPrivilegeToBlacklist),
+ WorkbenchActionDelegate("Check Privilege is Blacklisted", this, &ApplicationPolicy::checkPrivilegeIsBlacklisted),
+ WorkbenchActionDelegate("Remove Privilege from Blacklist", this, &ApplicationPolicy::removePrivilegeFromBlacklist),
+ WorkbenchActionDelegate("Disable package install/uninstall", this, &ApplicationPolicy::setModeRestriction),
+ WorkbenchActionDelegate("Enable package install/uninstall", this, &ApplicationPolicy::unsetModeRestriction),
+ WorkbenchActionDelegate("Get package install/uninstall restriction state", this, &ApplicationPolicy::getModeRestriction)
+ };
+ return actionList;
+ }
+
+ virtual ~ApplicationPolicy()
+ {
+ }
+
+ int installPackage(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+
+ std::string pkgPath;
+ if (workbench->showEntryPopup(desc, "/usr/apps/org.tizen.dpm-toolkit/res/sampleapp.tpk", "Enter package path", pkgPath))
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_install_package(handle, pkgPath.c_str()) != DPM_ERROR_NONE) {
+ ::dlog_print(DLOG_ERROR, LOG_TAG, "Failed dpm_application_install_package");
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ workbench->showMessagePopup(desc, "Package installed");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int uninstallPackage(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ std::string pkgId;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (workbench->showEntryPopup(desc, "sampleapp", "Enter package id", pkgId) == -1) {
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_uninstall_package(handle, pkgId.c_str()) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ workbench->showMessagePopup(desc, "Package uninstalled");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int addPrivilegeToBlacklist(Workbench *workbench, std::string& desc)
+ {
+ int state, index;
+ std::string privilege;
+ device_policy_manager_h handle;
+ std::string text[] = {
+ "Wrt Package Privilege",
+ "Core Package Privilege"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index))
+ return POLICY_RESULT_FAIL;
+
+ if (workbench->showEntryPopup(desc, "http://tizen.org.privilege/internet", "Enter package privilege name", privilege))
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_add_privilege_to_blacklist(handle, index, privilege.c_str()) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_check_privilege_is_blacklisted(handle, index, privilege.c_str(), &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query privilege blacklist");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (!state) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Adding privilege to blacklist was failed");
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "The privilege is disabled");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int checkPrivilegeIsBlacklisted(Workbench *workbench, std::string& desc) {
+ int state, index;
+ std::string privilege;
+ device_policy_manager_h handle;
+ std::string text[] = {
+ "Wrt Package Privilege",
+ "Core Package Privilege"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ if (workbench->showEntryPopup(desc, "http://tizen.org.privilege/internet",
+ "Enter package privilege name",
+ privilege) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_check_privilege_is_blacklisted(handle, index, privilege.c_str(), &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query privilege blacklist");
+ return POLICY_RESULT_FAIL;
+ }
+
+ workbench->showMessagePopup(desc, state ? "Privilege is disabled"
+ : "Privilege is enabled");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int removePrivilegeFromBlacklist(Workbench *workbench, std::string& desc) {
+ int state, index;
+ std::string privilege;
+ device_policy_manager_h handle;
+ std::string text[] = {
+ "Wrt Package Privilege",
+ "Core Package Privilege"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ if (workbench->showEntryPopup(desc, "http://tizen.org.privilege/internet",
+ "Enter package privilege name",
+ privilege) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_remove_privilege_from_blacklist(handle, index, privilege.c_str()) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_check_privilege_is_blacklisted(handle, index, privilege.c_str(), &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query privilege blacklist");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Removing privilege from blacklist was failed");
+ return POLICY_RESULT_FAIL;
+ }
+
+ workbench->showMessagePopup(desc, "Privilege is enabled");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int setModeRestriction(Workbench *workbench, std::string& desc) {
+ std::string msg;
+ int state, index;
+ device_policy_manager_h handle;
+ const std::string text[] = {
+ "Disable package installation",
+ "Disable package uninstallation"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ switch (index) {
+ case 0: index = DPM_PACKAGE_RESTRICTION_MODE_INSTALL; break;
+ case 1: index = DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL; break;
+ }
+
+ if (::dpm_application_set_mode_restriction(handle, index) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_get_mode_restriction(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (index != (state & index)) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Policy was not setted properly");
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ switch (index) {
+ case DPM_PACKAGE_RESTRICTION_MODE_INSTALL:
+ msg = "All package installation will not be allowed";
+ break;
+ case DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL:
+ msg = "All package uninstallation will not be allowed";
+ break;
+ }
+
+ workbench->showMessagePopup(desc, msg);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int unsetModeRestriction(Workbench *workbench, std::string& desc) {
+ std::string msg;
+ int state, index;
+ device_policy_manager_h handle;
+ const std::string text[] = {
+ "Enable package installation",
+ "Enable package uninstallation"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ switch (index) {
+ case 0: index = DPM_PACKAGE_RESTRICTION_MODE_INSTALL; break;
+ case 1: index = DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL; break;
+ }
+
+ if (::dpm_application_unset_mode_restriction(handle, index) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "Set mode index %d ", index);
+ if (::dpm_application_get_mode_restriction(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query policy");
+ return POLICY_RESULT_FAIL;
+ }
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "Set mode state %d ", state);
+ if ((state & index) == index) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Policy was not setted properly");
+ return POLICY_RESULT_FAIL;
+ }
+
+ switch (index) {
+ case DPM_PACKAGE_RESTRICTION_MODE_INSTALL:
+ msg = "All package installation is enabled";
+ break;
+ case DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL:
+ msg = "All package uninstallation is enabled";
+ break;
+ }
+
+ workbench->showMessagePopup(desc, msg);
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int getModeRestriction(Workbench *workbench, std::string& desc) {
+ int state;
+ char msg[128];
+ std::string msgStr;
+ device_policy_manager_h handle;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_application_get_mode_restriction(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ ::snprintf(msg, 128, "Package installation is %s, Package uninstallation is %s",
+ (state & DPM_PACKAGE_RESTRICTION_MODE_INSTALL) ? "DISABLED" : "ENABLED",
+ (state & DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL) ? "DISABLED" : "ENABLED");
+ msgStr = msg;
+ workbench->showMessagePopup(desc, msgStr);
+
+ return POLICY_RESULT_SUCCESS;
+ }
+};
+
+PolicyBuilder<ApplicationPolicy> applicationPolicy("Application");
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/bluetooth.h>
+
+class BluetoothPolicy : public AbstractPolicy {
+public:
+ BluetoothPolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Set uuid restriction", this, &BluetoothPolicy::setUuidRestriction),
+ WorkbenchActionDelegate("Get uuid restriction", this, &BluetoothPolicy::getUuidRestriction),
+ WorkbenchActionDelegate("Set device restriction", this, &BluetoothPolicy::setDeviceRestriction),
+ WorkbenchActionDelegate("Get device restriction", this, &BluetoothPolicy::getDeviceRestriction)
+ };
+ return actionList;
+ }
+
+ virtual ~BluetoothPolicy()
+ {
+ }
+
+ int setUuidRestriction(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ int state, enable;
+
+ if (workbench->showRadioPopup(desc, RESTRICTION_MODE_OPTIONS, enable) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_bluetooth_set_uuid_restriction(handle, enable) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_bluetooth_is_uuid_restricted(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == enable) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, RESTRICTION_MODE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set uuid restriction");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getUuidRestriction(Workbench *workbench, std::string& desc)
+ {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_bluetooth_is_uuid_restricted(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, RESTRICTION_MODE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get uuid restriction");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setDeviceRestriction(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ int state, enable;
+
+ if (workbench->showRadioPopup(desc, RESTRICTION_MODE_OPTIONS, enable) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_bluetooth_set_device_restriction(handle, enable) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_bluetooth_is_device_restricted(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == enable) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, RESTRICTION_MODE_MESSAGE(state));
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set device restriction");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int getDeviceRestriction(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_bluetooth_is_device_restricted(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, RESTRICTION_MODE_MESSAGE(state));
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get device restriction");
+ return POLICY_RESULT_SUCCESS;
+ }
+};
+
+PolicyBuilder<BluetoothPolicy> bluetoothPolicy("Bluetooth");
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/password.h>
+
+class PasswordPolicy : public AbstractPolicy {
+public:
+ PasswordPolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Set Password Quality", this, &PasswordPolicy::setPasswordQuality),
+ WorkbenchActionDelegate("Get Password Quality", this, &PasswordPolicy::getPasswordQuality),
+ WorkbenchActionDelegate("Set Password Minimum Length", this, &PasswordPolicy::setPasswordMinLength),
+ WorkbenchActionDelegate("Get Password Minimum Length", this, &PasswordPolicy::getPasswordMinLength),
+ WorkbenchActionDelegate("Set Password Min Complex Chars", this, &PasswordPolicy::setMinComplexChars),
+ WorkbenchActionDelegate("Get Password Min Complex Chars", this, &PasswordPolicy::getMinComplexChars),
+ WorkbenchActionDelegate("Set Max number of failed attempts", this, &PasswordPolicy::setMaxFailedAttemptsForWipe),
+ WorkbenchActionDelegate("Get Max number of failed attempts", this, &PasswordPolicy::getMaxFailedAttemptsForWipe),
+ WorkbenchActionDelegate("Set the number of days a pw expires", this, &PasswordPolicy::setPasswordExpires),
+ WorkbenchActionDelegate("Get the number of days a pw expires", this, &PasswordPolicy::getPasswordExpires),
+ WorkbenchActionDelegate("Set the number of password history", this, &PasswordPolicy::setPasswordHistory),
+ WorkbenchActionDelegate("Get the number of password history", this, &PasswordPolicy::getPasswordHistory),
+ WorkbenchActionDelegate("Reset Password", this, &PasswordPolicy::resetPassword),
+ WorkbenchActionDelegate("Enforce Password Change", this, &PasswordPolicy::enforcePasswordChange),
+ WorkbenchActionDelegate("Set Max Inactivity Time Device Lock", this, &PasswordPolicy::setMaxInactivityTimeDeviceLock),
+ WorkbenchActionDelegate("Get Max Inactivity Time Device Lock", this, &PasswordPolicy::getMaxInactivityTimeDeviceLock),
+ WorkbenchActionDelegate("Set Password Status", this, &PasswordPolicy::setPasswordStatus),
+ WorkbenchActionDelegate("Set Password Pattern", this, &PasswordPolicy::setPasswordPattern),
+ WorkbenchActionDelegate("Get Password Pattern", this, &PasswordPolicy::getPasswordPattern),
+ WorkbenchActionDelegate("Delete Password Pattern", this, &PasswordPolicy::deletePasswordPattern),
+ WorkbenchActionDelegate("Set Max Character Occurrences", this, &PasswordPolicy::setMaxCharOccurrences),
+ WorkbenchActionDelegate("Get Max Character Occurrences", this, &PasswordPolicy::getMaxCharOccurrences),
+ WorkbenchActionDelegate("Set Max Numeric Sequence Length", this, &PasswordPolicy::setMaxNumericSequenceLength),
+ WorkbenchActionDelegate("Get Max Numeric Sequence Length", this, &PasswordPolicy::getMaxNumericSequenceLength)
+ };
+ return actionList;
+ }
+
+ virtual ~PasswordPolicy()
+ {
+ }
+
+ int setPasswordQuality(Workbench *workbench, std::string& desc)
+ {
+ int quality, index;
+ device_policy_manager_h handle = NULL;
+
+ std::string radioText[6] = {
+ "UNSPECIFIED",
+ "SIMPLE_PASSWORD",
+ "SOMETHING",
+ "NUMERIC",
+ "ALPHABETIC",
+ "ALPHANUMERIC"
+ };
+
+ if (workbench->showRadioPopup(desc, radioText, ARRAY_SIZE(radioText), index) == -1) {
+ ::dlog_print(DLOG_INFO, LOG_TAG, "Radio popup canceled");
+ return POLICY_RESULT_FAIL;
+ }
+
+ switch (index) {
+ case 0:
+ quality = DPM_PASSWORD_QUALITY_UNSPECIFIED;
+ break;
+ case 1:
+ quality = DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD;
+ break;
+ case 2:
+ quality = DPM_PASSWORD_QUALITY_SOMETHING;
+ break;
+ case 3:
+ quality = DPM_PASSWORD_QUALITY_NUMERIC;
+ break;
+ case 4:
+ quality = DPM_PASSWORD_QUALITY_ALPHABETIC;
+ break;
+ case 5:
+ quality = DPM_PASSWORD_QUALITY_ALPHANUMERIC;
+ break;
+ default:
+ quality = DPM_PASSWORD_QUALITY_UNSPECIFIED;
+ break;
+ }
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_quality(handle, quality) == 0) {
+ workbench->showMessagePopup(desc, "Successed to set password quality");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getPasswordQuality(Workbench *workbench, std::string& desc)
+ {
+ int quality, index;
+
+ std::string radioText[6] = {
+ "UNSPECIFIED",
+ "SIMPLE_PASSWORD",
+ "SOMETHING",
+ "NUMERIC",
+ "ALPHABETIC",
+ "ALPHANUMERIC"
+ };
+ device_policy_manager_h handle = NULL;
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_quality(handle, &quality) == 0) {
+ ::dpm_manager_destroy(handle);
+ switch (quality) {
+ case DPM_PASSWORD_QUALITY_UNSPECIFIED:
+ index = 0;
+ break;
+ case DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD:
+ index = 1;
+ break;
+ case DPM_PASSWORD_QUALITY_SOMETHING:
+ index = 2;
+ break;
+ case DPM_PASSWORD_QUALITY_NUMERIC:
+ index = 3;
+ break;
+ case DPM_PASSWORD_QUALITY_ALPHABETIC:
+ index = 4;
+ break;
+ case DPM_PASSWORD_QUALITY_ALPHANUMERIC:
+ index = 5;
+ break;
+ default:
+ index = 0;
+ break;
+ }
+ workbench->showMessagePopup(desc, radioText[index]);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setPasswordMinLength(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_minimum_length(handle, ::atoi(inputEntry.c_str())) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getPasswordMinLength(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int minLength;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_minimum_length(handle, &minLength) == 0) {
+ ::dpm_manager_destroy(handle);
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "Successed get password minimum length");
+ std::string minLengthStr = std::to_string(minLength);
+ workbench->showMessagePopup(desc, minLengthStr);
+ return POLICY_RESULT_SUCCESS;
+ }
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMinComplexChars(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_min_complex_chars(handle, ::atoi(inputEntry.c_str())) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMinComplexChars(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int minComplexChars;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_min_complex_chars(handle, &minComplexChars) == 0) {
+ workbench->showMessagePopup(desc, std::to_string(minComplexChars));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMaxFailedAttemptsForWipe(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_maximum_failed_attempts_for_wipe(handle, ::atoi(inputEntry.c_str())) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMaxFailedAttemptsForWipe(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxFailedAttempts;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_maximum_failed_attempts_for_wipe(handle, &maxFailedAttempts) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(maxFailedAttempts));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setPasswordExpires(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ std::string inputEntry;
+
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_expires(handle, ::atoi(inputEntry.c_str())) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getPasswordExpires(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int expires;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_expires(handle, &expires) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(expires));
+ return POLICY_RESULT_SUCCESS;;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setPasswordHistory(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_history(handle, ::atoi(inputEntry.c_str())) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getPasswordHistory(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int history;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_history(handle, &history) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(history));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int resetPassword(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_reset(handle, inputEntry.c_str()) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_FAIL;
+ }
+
+ int enforcePasswordChange(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_enforce_change(handle) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Successed to enforce policy");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMaxInactivityTimeDeviceLock(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxInactivityTime, testMaxInactivityTime;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ maxInactivityTime = ::atoi(inputEntry.c_str());
+ testMaxInactivityTime = 0;
+
+ if (::dpm_password_set_max_inactivity_time_device_lock(handle, maxInactivityTime) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_max_inactivity_time_device_lock(handle, &testMaxInactivityTime) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (maxInactivityTime == testMaxInactivityTime) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMaxInactivityTimeDeviceLock(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxInactivityTime;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_max_inactivity_time_device_lock(handle, &maxInactivityTime) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(maxInactivityTime));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setPasswordStatus(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_status(handle, (dpm_password_status_e)::atoi(inputEntry.c_str())) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setPasswordPattern(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ std::string testPwPattern;
+ std::string inputEntry;
+
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_set_pattern(handle, inputEntry.c_str()) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ char* testPattern = (char*)testPwPattern.c_str();
+ if (::dpm_password_get_pattern(handle, &testPattern) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (!inputEntry.compare(testPwPattern)) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getPasswordPattern(Workbench* workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ std::string pwPattern;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ char *testPattern = (char*)pwPattern.c_str();
+ if (::dpm_password_get_pattern(handle, &testPattern) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, pwPattern);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int deletePasswordPattern(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_delete_pattern(handle) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Successed to delete password pattern");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMaxCharOccurrences(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxCharOccur, testMaxCharOccur;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ maxCharOccur = ::atoi(inputEntry.c_str());
+ testMaxCharOccur = 0;
+
+ if (::dpm_password_set_maximum_character_occurrences(handle, maxCharOccur) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_maximum_character_occurrences(handle, &testMaxCharOccur) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (maxCharOccur == testMaxCharOccur) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, inputEntry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMaxCharOccurrences(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxCharOccur;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_maximum_character_occurrences(handle, &maxCharOccur) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(maxCharOccur));
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMaxNumericSequenceLength(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxNumSeqLength, testMaxNumSeqLength;
+
+ std::string inputEntry;
+ if (workbench->showEntryPopup(desc, "", "", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ maxNumSeqLength = ::atoi(inputEntry.c_str());
+ testMaxNumSeqLength = 0;
+
+ if (::dpm_password_set_maximum_numeric_sequence_length(handle, maxNumSeqLength) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_maximum_numeric_sequence_length(handle, &testMaxNumSeqLength) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (maxNumSeqLength == testMaxNumSeqLength) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(maxNumSeqLength));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMaxNumericSequenceLength(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle;
+ int maxNumSeqLength;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_password_get_maximum_numeric_sequence_length(handle, &maxNumSeqLength) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, std::to_string(maxNumSeqLength));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+};
+
+PolicyBuilder<PasswordPolicy> passwordPolicy("Password");
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/restriction.h>
+
+class RestrictionPolicy : public AbstractPolicy {
+public:
+ RestrictionPolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Set Camera State", this, &RestrictionPolicy::setCameraStatus),
+ WorkbenchActionDelegate("Get Camera State", this, &RestrictionPolicy::getCameraStatus),
+ WorkbenchActionDelegate("Set Microphone State", this, &RestrictionPolicy::setMicrophoneState),
+ WorkbenchActionDelegate("Get Microphone State", this, &RestrictionPolicy::getMicrophoneState),
+ WorkbenchActionDelegate("Set Location State", this, &RestrictionPolicy::setLocationState),
+ WorkbenchActionDelegate("Get Location State", this, &RestrictionPolicy::getLocationState),
+ WorkbenchActionDelegate("Set Clipboard State", this, &RestrictionPolicy::setClipboardState),
+ WorkbenchActionDelegate("Get Clipboard State", this, &RestrictionPolicy::getClipboardState),
+ WorkbenchActionDelegate("Set USB Debugging State", this, &RestrictionPolicy::setUsbDebuggingState),
+ WorkbenchActionDelegate("Get USB Debugging State", this, &RestrictionPolicy::getUsbDebuggingState),
+ WorkbenchActionDelegate("Set Wifi State", this, &RestrictionPolicy::setWifiState),
+ WorkbenchActionDelegate("Get Wifi State", this, &RestrictionPolicy::getWifiState),
+ WorkbenchActionDelegate("Set Wifi Hotspot State", this, &RestrictionPolicy::setWifiHotspotState),
+ WorkbenchActionDelegate("Get Wifi Hotspot State", this, &RestrictionPolicy::getWifiHotspotState),
+ WorkbenchActionDelegate("Set Bluetooth Tethering State", this, &RestrictionPolicy::setBluetoothTetheringState),
+ WorkbenchActionDelegate("Get Bluetooth Tethering State", this, &RestrictionPolicy::getBluetoothTetheringState),
+ WorkbenchActionDelegate("Set USB Tethering State", this, &RestrictionPolicy::setUsbTetheringState),
+ WorkbenchActionDelegate("Get USB Tethering State", this, &RestrictionPolicy::getUsbTetheringState),
+ WorkbenchActionDelegate("Set External Storage State", this, &RestrictionPolicy::setExternalStorageState),
+ WorkbenchActionDelegate("Get External Storage State", this, &RestrictionPolicy::getExternalStorageState),
+ WorkbenchActionDelegate("Set Bluetooth Mode Change State", this, &RestrictionPolicy::setBluetoothModeChangeState),
+ WorkbenchActionDelegate("Get Bluetooth Mode Change State", this, &RestrictionPolicy::getBluetoothModeChangeState),
+ WorkbenchActionDelegate("Set Bluetooth Desktop Connectivity State", this, &RestrictionPolicy::setBluetoothDesktopConnectivityState),
+ WorkbenchActionDelegate("Get Bluetooth Desktop Connectivity State", this, &RestrictionPolicy::getBluetoothDesktopConnectivityState),
+ WorkbenchActionDelegate("Set Bluetooth Pairing State", this, &RestrictionPolicy::setBluetoothPairingState),
+ WorkbenchActionDelegate("Get Bluetooth Pairing State", this, &RestrictionPolicy::getBluetoothPairingState),
+ WorkbenchActionDelegate("Set POP/IMAP EMail State", this, &RestrictionPolicy::setPopimapEmailState),
+ WorkbenchActionDelegate("Get POP/IMAP EMail State", this, &RestrictionPolicy::getPopimapEmailState),
+ WorkbenchActionDelegate("Set Text Messaging State", this, &RestrictionPolicy::setMessagingState),
+ WorkbenchActionDelegate("Get Text Messaging State", this, &RestrictionPolicy::getMessagingState),
+ WorkbenchActionDelegate("Set Browser State", this, &RestrictionPolicy::setBrowserState),
+ WorkbenchActionDelegate("Get Browser State", this, &RestrictionPolicy::getBrowserState)
+ };
+ return actionList;
+ }
+
+ virtual ~RestrictionPolicy()
+ {
+ }
+
+ int setCameraStatus(Workbench *workbench, std::string& desc)
+ {
+ int state, allow = 0;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_camera_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_camera_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set camera state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getCameraStatus(Workbench *workbench, std::string& desc)
+ {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_camera_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get camera state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMicrophoneState(Workbench *workbench, std::string& desc)
+ {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_microphone_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_microphone_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handley");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set microphone state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMicrophoneState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_microphone_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get microphone state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setLocationState(Workbench *workbench, std::string& desc) {
+ int state;
+ int allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_location_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_location_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set location state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getLocationState(Workbench *workbench, std::string& desc) {
+ int state, ret;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ ret = ::dpm_restriction_get_location_state(handle, &state);
+ if (ret == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get location state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setClipboardState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_clipboard_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_clipboard_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set clipboard state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getClipboardState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_clipboard_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get clipboard state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setUsbDebuggingState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1) {
+ return POLICY_RESULT_FAIL;
+ }
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_usb_debugging_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_usb_debugging_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set usb debugging state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getUsbDebuggingState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_usb_debugging_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get usb debugging state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setWifiState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_wifi_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_wifi_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set wifi state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getWifiState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_wifi_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get wifi state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setWifiHotspotState(Workbench *workbench, std::string& desc) {
+ int state;
+ int allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_wifi_hotspot_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_wifi_hotspot_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set wifi hotspot state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getWifiHotspotState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_wifi_hotspot_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get wifi hotspot state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setBluetoothTetheringState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_bluetooth_tethering_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_bluetooth_tethering_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set bluetooth tethering state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getBluetoothTetheringState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_bluetooth_tethering_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get bluetooth tethering state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setUsbTetheringState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_usb_tethering_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_usb_tethering_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set usb tethering state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getUsbTetheringState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_usb_tethering_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get usb tethering state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setExternalStorageState(Workbench *workbench, std::string& desc) {
+ int index, state;
+ device_policy_manager_h handle = NULL;
+ const std::string text[] = {
+ "Disallow External Storage",
+ "Allow External Storage"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_external_storage_state(handle, index) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_external_storage_state(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state != index) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Policy was not setted properly");;
+ return POLICY_RESULT_FAIL;
+ }
+
+ workbench->showMessagePopup(desc, state ? "External Storage Allowed"
+ : "External Storage Disallowed");
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int getExternalStorageState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_external_storage_state(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ workbench->showMessagePopup(desc, state ? "External Storage Allowed"
+ : "External Storage Disallowed");
+
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int setBluetoothModeChangeState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_bluetooth_mode_change_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_bluetooth_mode_change_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set bluetooth mode change state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getBluetoothModeChangeState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_bluetooth_mode_change_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get bluetooth mode change state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setBluetoothDesktopConnectivityState(Workbench *workbench, std::string& desc) {
+ int state, allow = 0;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_camera_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_camera_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set bluetooth desktop connectivity state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getBluetoothDesktopConnectivityState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_camera_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get bluetooth desktop connectivity state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setBluetoothPairingState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_bluetooth_pairing_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_bluetooth_pairing_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set bluetooth pairing state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getBluetoothPairingState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_bluetooth_pairing_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get bluetooth pairing state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setPopimapEmailState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_popimap_email_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_popimap_email_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set popimap email state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getPopimapEmailState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_popimap_email_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get popimap email state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setMessagingState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1) {
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "Radio popup canceled");
+ return POLICY_RESULT_FAIL;
+ }
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_messaging_state(handle, "sim1", allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_messaging_state(handle, "sim1", &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set messaging state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getMessagingState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_messaging_state(handle, "sim1", &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get messaging state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setBrowserState(Workbench *workbench, std::string& desc) {
+ int state, allow;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_set_browser_state(handle, allow) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_browser_state(handle, &state) != 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set browser state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getBrowserState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device handle manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_restriction_get_browser_state(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get browser state");
+ return POLICY_RESULT_FAIL;
+ }
+};
+
+PolicyBuilder<RestrictionPolicy> restrictionPolicy("Restriction");
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/security.h>
+
+class SecurityPolicy : public AbstractPolicy {
+public:
+ SecurityPolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Force Lock", this, &SecurityPolicy::forceLock),
+ WorkbenchActionDelegate("Wipe Data", this, &SecurityPolicy::wipeData),
+ WorkbenchActionDelegate("Encrypt Device", this, &SecurityPolicy::encryptDevice),
+ WorkbenchActionDelegate("Decrypt Device", this, &SecurityPolicy::decryptDevice)
+ };
+ return actionList;
+ }
+
+ virtual ~SecurityPolicy()
+ {
+ }
+
+ int forceLock(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showConfirmPopup(desc, "This operation will lockout the screen") == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_security_lockout_screen(handle) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to lockout screen");
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int wipeData(Workbench *workbench, std::string& desc)
+ {
+ int index;
+ device_policy_manager_h handle = NULL;
+
+ const std::string text[] = {
+ "Wipe Internal Storage",
+ "Wipe External Storage"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (index == 0) {
+ if (::dpm_security_wipe_data(handle, DPM_SECURITY_WIPE_INTERNAL_STORAGE) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ } else if (index == 1) {
+ if (::dpm_security_wipe_data(handle, DPM_SECURITY_WIPE_EXTERNAL_STORAGE) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Operation successfully triggerred, "
+ "but it may take a long time to complete");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int encryptDevice(Workbench *workbench, std::string& desc)
+ {
+ int index;
+ device_policy_manager_h handle = NULL;
+
+ const std::string text[] = {
+ "Encrypt Internal Storage",
+ "Encrypt External Storage"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (index == 0) {
+ if (::dpm_security_set_internal_storage_encryption(handle, TRUE) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ } else if (index == 1) {
+ if (::dpm_security_set_external_storage_encryption(handle, TRUE) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Operation successfully triggerred, "
+ "but product must provide encryption backend");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ int decryptDevice(Workbench *workbench, std::string& desc)
+ {
+ int index;
+ device_policy_manager_h handle = NULL;
+
+ const std::string text[] = {
+ "Decrypt Internal Storage",
+ "Decrypt External Storage"
+ };
+
+ if (workbench->showRadioPopup(desc, text, ARRAY_SIZE(text), index) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (index == 0) {
+ if (::dpm_security_set_internal_storage_encryption(handle, FALSE) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ } else if (index == 1) {
+ if (::dpm_security_set_internal_storage_encryption(handle, FALSE) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Operation successfully triggerred, "
+ "but product must provide decryption backend");
+ return POLICY_RESULT_SUCCESS;
+ }
+};
+
+PolicyBuilder<SecurityPolicy> securityPolicy("Security");
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/wifi.h>
+
+class WifiPolicy : public AbstractPolicy {
+public:
+ WifiPolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Add ssid to blocklist", this, &WifiPolicy::addSsidToBlocklist),
+ WorkbenchActionDelegate("Remove ssid from blocklist", this, &WifiPolicy::removeSsidFromBlocklist),
+ WorkbenchActionDelegate("Set network access restriction", this, &WifiPolicy::setNetworkAccessRestriction),
+ WorkbenchActionDelegate("Get network access restriction", this, &WifiPolicy::getNetworkAccessRestriction),
+ WorkbenchActionDelegate("Set profile change state", this, &WifiPolicy::setProfileChangeState),
+ WorkbenchActionDelegate("Get profile change state", this, &WifiPolicy::getProfileChangeState)
+ };
+ return actionList;
+ }
+
+ virtual ~WifiPolicy()
+ {
+ }
+
+ int addSsidToBlocklist(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ std::string entry;
+
+ if (workbench->showEntryPopup(desc, "", "SSID", entry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ if (entry.size() == 0)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_add_ssid_to_blocklist(handle, entry.c_str()) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, entry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to add ssid to blocklist");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int removeSsidFromBlocklist(Workbench *workbench, std::string& desc)
+ {
+ std::string entry;
+ device_policy_manager_h handle = NULL;
+
+ if (workbench->showEntryPopup(desc, "", "SSID", entry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ if (entry.size() == 0)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_remove_ssid_from_blocklist(handle, entry.c_str()) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, entry);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to remove ssid from blocklist");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setNetworkAccessRestriction(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ int state, enable;
+
+ if (workbench->showRadioPopup(desc, RESTRICTION_MODE_OPTIONS, enable) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_set_network_access_restriction(handle, enable) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_is_network_access_restricted(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to query handle");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == enable) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, RESTRICTION_MODE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set network access restriction");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getNetworkAccessRestriction(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_is_network_access_restricted(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, RESTRICTION_MODE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get network access restriction");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int setProfileChangeState(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle = NULL;
+ int state, allow;
+
+ if (workbench->showRadioPopup(desc, STATE_CHANGE_OPTIONS, allow) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_set_profile_change_restriction(handle, allow) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_is_profile_change_restricted(handle, &state) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to enforce policy");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (state == allow) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to set profile change state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getProfileChangeState(Workbench *workbench, std::string& desc) {
+ int state;
+ device_policy_manager_h handle = NULL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_wifi_is_profile_change_restricted(handle, &state) == 0) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, STATE_CHANGE_MESSAGE(state));
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Fail to get profile change state");
+ return POLICY_RESULT_FAIL;
+ }
+};
+
+PolicyBuilder<WifiPolicy> wifiPolicy("Wifi");
--- /dev/null
+/*
+ *
+ * Copyright (c) 2017 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 "dpmtoolkit.h"
+#include "policy.h"
+
+#include <dpm/zone.h>
+
+int numOfzone;
+
+struct ZoneCbInfo {
+ Workbench* ui;
+ std::string title;
+};
+
+static bool zoneListCbDispatcher(const char* name, void* userData) {
+ ZoneCbInfo* info = reinterpret_cast<ZoneCbInfo*>(userData);
+ const std::string zoneName = name;
+ info->ui->showMessagePopup(info->title, zoneName);
+ numOfzone++;
+ return true;
+}
+
+class ZonePolicy : public AbstractPolicy {
+public:
+ ZonePolicy(const std::string& name) :
+ AbstractPolicy(name)
+ {
+ }
+
+ std::vector<WorkbenchActionDelegate> inspect()
+ {
+ std::vector<WorkbenchActionDelegate> actionList = {
+ WorkbenchActionDelegate("Create Zone", this, &ZonePolicy::createZone),
+ WorkbenchActionDelegate("Destroy Zone", this, &ZonePolicy::destroyZone),
+ WorkbenchActionDelegate("Get Zone State", this, &ZonePolicy::getZoneState),
+ WorkbenchActionDelegate("Get Zone List", this, &ZonePolicy::getZoneList)
+ };
+ return actionList;
+ }
+
+ virtual ~ZonePolicy()
+ {
+ }
+
+ int createZone(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ std::string inputEntry;
+ const std::string wizardId = "org.tizen.krate-setup-wizard";
+
+ if (workbench->showEntryPopup(desc, "", "Zone name", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_zone_create(handle, inputEntry.c_str(), wizardId.c_str()) == DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to create the zone");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int destroyZone(Workbench *workbench, std::string& desc)
+ {
+ device_policy_manager_h handle = NULL;
+ std::string inputEntry;
+
+ if (workbench->showEntryPopup(desc, "", "Zone name", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ if (::dpm_zone_destroy(handle, inputEntry.c_str()) == DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to destroy the zone");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getZoneState(Workbench *workbench, std::string& desc)
+ {
+ dpm_zone_state_e state;
+ device_policy_manager_h handle = NULL;
+ std::string inputEntry;
+ std::string zoneState;
+
+ if (workbench->showEntryPopup(desc, "", "Zone name", inputEntry) == -1)
+ return POLICY_RESULT_FAIL;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int ret = ::dpm_zone_get_state(handle, inputEntry.c_str(), &state);
+ ::dpm_manager_destroy(handle);
+
+ switch(ret) {
+ case DPM_ERROR_NONE:
+ if (state & DPM_ZONE_STATE_RUNNING) {
+ zoneState = "Running";
+ } else if (state & DPM_ZONE_STATE_LOCKED) {
+ zoneState = "Locked";
+ }
+
+ workbench->showMessagePopup(desc, zoneState);
+ return POLICY_RESULT_SUCCESS;
+ case DPM_ERROR_NO_DATA:
+ workbench->showMessagePopup(desc, "Not exists");
+ return POLICY_RESULT_SUCCESS;
+ }
+
+ workbench->showMessagePopup(desc, "Failed to get zone state");
+ return POLICY_RESULT_FAIL;
+ }
+
+ int getZoneList(Workbench *workbench, std::string& desc) {
+ device_policy_manager_h handle = NULL;
+ char string[256];
+ std::string stringStr;
+
+ handle = ::dpm_manager_create();
+ if (handle == NULL) {
+ workbench->showMessagePopup(desc, "Failed to create device policy manager");
+ return POLICY_RESULT_FAIL;
+ }
+
+ numOfzone = 0;
+
+ ZoneCbInfo* info = new ZoneCbInfo;
+ info->ui = workbench;
+ info->title = desc;
+
+ if (::dpm_zone_foreach_name(handle, DPM_ZONE_STATE_ALL, zoneListCbDispatcher, info) != DPM_ERROR_NONE) {
+ ::dpm_manager_destroy(handle);
+ workbench->showMessagePopup(desc, "Failed to get zone list");
+ return POLICY_RESULT_FAIL;
+ }
+
+ ::dpm_manager_destroy(handle);
+ ::snprintf(string, sizeof(string), "%d zone are found", numOfzone);
+ stringStr = string;
+ workbench->showMessagePopup(desc, stringStr);
+ return POLICY_RESULT_SUCCESS;
+ }
+};
+
+PolicyBuilder<ZonePolicy> zonePolicy("Zone");
+++ /dev/null
-SET(TESTCASES
- src/application.c
- src/security.c
- src/restriction.c
-)
+++ /dev/null
-SET(TESTCASES
- src/application.c
- src/password.c
- src/security.c
- src/wifi.c
- src/restriction.c
- src/bluetooth.c
-)