#
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(org.tizen.dpm-toolkit C)
+PROJECT(org.tizen.dpm-toolkit C CXX)
SET(VERSION_MAJOR 0)
SET(VERSION "${VERSION_MAJOR}.1.0")
PKG_CHECK_MODULES(test_pkgs REQUIRED
dlog
glib-2.0
- efl-extension
elementary
capi-appfw-application
- libxml-2.0
capi-system-system-settings
+ capi-ui-efl-util
evas
dpm
+ bundle
)
+IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ SET(CXX_STD "c++0x")
+else()
+ SET(CXX_STD "c++11")
+endif()
+
INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS} include)
LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
-SET(BASE_SRCS src/dpm-toolkit.c src/dpm-toolkit-cli.c src/dpm-toolkit-gui.c)
+SET(BASE_SRCS src/main.cpp)
+
+SET(UI_SRCS src/ui/widget.cpp
+ src/ui/window.cpp
+ src/ui/conformant.cpp
+ src/ui/popup.cpp
+ src/ui/message-box.cpp
+ src/ui/confirm-box.cpp
+ src/ui/text-input-box.cpp
+ src/ui/select-popup.cpp
+ src/ui/button.cpp
+ src/ui/radio.cpp
+ src/ui/entry.cpp
+ src/ui/naviframe.cpp
+ src/ui/conformant-window.cpp)
-INCLUDE("${TIZEN_PROFILE_NAME}.cmake")
+#INCLUDE("${TIZEN_PROFILE_NAME}.cmake")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -fPIE")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wp,-U_FORTIFY_SOURCE")
-SET(CMAKE_C_FLAGS_RELEASE "-O2")
+SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -fPIE -std=${CXX_STD}")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wp,-U_FORTIFY_SOURCE")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed -pie")
-ADD_EXECUTABLE(${PROJECT_NAME} ${BASE_SRCS} ${TESTCASES})
+ADD_EXECUTABLE(${PROJECT_NAME} ${BASE_SRCS} ${UI_SRCS} ${TESTCASES})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/bin)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${test_pkgs_LIBRARIES})
+++ /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
- */
-
-#ifndef __DPM_TOOLKIT_H__
-#define __DPM_TOOLKIT_H__
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <glib.h>
-#include <string.h>
-
-#include <app.h>
-#include <dlog.h>
-#include <libxml/xpath.h>
-#include <system_settings.h>
-#include <efl_extension.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "dpm-toolkit"
-
-#if !defined(PACKAGE)
-#define PACKAGE "org.tizen.dpm-toolkit"
-#endif
-
-#define __CONSTRUCTOR__ __attribute__ ((constructor))
-
-#define ARRAY_SIZE(p) (sizeof(p) / sizeof(p[0]))
-
-#define POLICY_RESULT_SUCCESS 0
-#define POLICY_RESULT_FAIL -1
-#define POLICY_RESULT_NONE 100
-
-#define POLICY_XML_FILE_PATH "/usr/apps/org.tizen.dpm-toolkit/dpm-toolkit.xml"
-
-typedef struct xtk_policy {
- const char* id;
- const char* description;
- const char* param;
- int (*handler)(struct xtk_policy* self);
- xmlNodePtr model;
-} xtk_policy_t;
-
-typedef struct xtk_policy_group {
- const char* id;
- const char* title;
- const char* description;
- GList* policies;
-} xtk_policy_group_t;
-
-typedef struct xtk_context {
- int (*message_popup)(const char* title, const char* message);
- int (*confirm_popup)(const char* title, const char* message);
- int (*entry_popup)(const char* title, const char* message, const char* guide, char** value);
- int (*radio_popup)(const char* title, const char* text[], int nr, int* index);
-} xtk_context_t;
-
-#define xtk_foreach_policy_group(_g_) \
- for (_g_ = g_list_first(xtk_policy_group_list); \
- (_g_ && _g_->data); \
- (_g_ = g_list_next(_g_)))
-
-#define xtk_foreach_policy(_e_, _g_) \
- for (_e_ = g_list_first(_g_->policies); \
- (_e_ && _e_->data); \
- (_e_ = g_list_next(_e_)))
-
-static inline xtk_policy_group_t* glist_to_policy_group(GList *list)
-{
- return (xtk_policy_group_t *)(list->data);
-}
-
-static inline xtk_policy_t* glist_to_policy(GList *list)
-{
- return (xtk_policy_t *)(list->data);
-}
-
-static inline const char* policy_get_title(xtk_policy_t* entity)
-{
- return entity->description;
-}
-
-static inline const char* policy_get_default_value(xtk_policy_t* entity)
-{
- return entity->param;
-}
-
-xtk_context_t* xtk_context_get_current(void);
-void xtk_context_set_current(xtk_context_t* context);
-
-int xtk_init_policy(xtk_policy_group_t* group, xtk_policy_t* policy, int nr);
-void xtk_free_policy_list(void);
-int xtk_rebuild_policy_group(const char *xmlFilePath);
-
-#define XTK_EVENT_CANCEL 1
-#define XTK_EVENT_OK 2
-
-#define STATE_CHANGE_OPTIONS \
- state_change_options, ARRAY_SIZE(state_change_options)
-
-#define RESTRICTION_MODE_OPTIONS \
- restriction_mode_options, ARRAY_SIZE(restriction_mode_options)
-
-#define STATE_CHANGE_MESSAGE(status) \
-({ \
- char buffer[64] = "State Change "; \
- strncat(buffer, state_change_results[!status], 16); \
-})
-
-#define RESTRICTION_MODE_MESSAGE(status) \
-({ \
- char buffer[64] = "Restriction Mode "; \
- strncat(buffer, restriction_mode_results[!status], 16); \
-})
-
-int xtk_open_message_popup(xtk_policy_t* policy, const char* message);
-int xtk_open_confirm_popup(xtk_policy_t* policy, const char *message);
-int xtk_open_entry_popup(xtk_policy_t* policy, const char* message, const char* guide, char** entry);
-int xtk_open_radio_popup(xtk_policy_t* policy, const char* text[], int nr, int* index);
-
-char* get_now_zone(void);
-
-int xtk_gui_main(int argc, char* argv[]);
-int xtk_cli_main(int argc, char* argv[]);
-
-extern const char* state_change_options[2];
-extern const char* restriction_mode_options[2];
-
-extern const char state_change_results[2][16];
-extern const char restriction_mode_results[2][16];
-
-extern GList* xtk_policy_group_list;
-
-#endif /* __DPM_TOOLKIT_H__ */
--- /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.
+ *
+ */
+#ifndef __DPMTOOLKIT_H__
+#define __DPMTOOLKIT_H__
+
+#include <stdbool.h>
+#include <glib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <app.h>
+#include <dlog.h>
+#include <system_settings.h>
+
+#include <iostream>
+#include <unordered_map>
+#include <vector>
+#include <string>
+#include <memory>
+#include <functional>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "dpm-toolkit"
+
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.dpm-toolkit"
+#endif
+
+#define ARRAY_SIZE(p) (sizeof(p) / sizeof(p[0]))
+
+#endif /* __DPMTOOLKIT_H__ */
BuildRequires: pkgconfig(elementary)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(capi-appfw-application)
-BuildRequires: pkgconfig(efl-extension)
-BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(capi-system-system-settings)
+BuildRequires: pkgconfig(capi-ui-efl-util)
BuildRequires: pkgconfig(evas)
BuildRequires: pkgconfig(dpm)
+BuildRequires: pkgconfig(bundle)
Requires: %{name}-binary = %{version}-%{release}
Recommends: %{name}-profile_common = %{version}-%{release}
+++ /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
- */
-
-#include <dpm/application.h>
-
-#include "dpm-toolkit.h"
-
-int install_package_handler(struct xtk_policy *self)
-{
- char *pkgpath;
- device_policy_manager_h handle;
-
- if (xtk_open_entry_popup(self, "/usr/apps/org.tizen.dpm-toolkit/res/sampleapp.tpk",
- "Enter package path",
- &pkgpath) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_NONE;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device policy manager");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_install_package(handle, pkgpath) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
-
- xtk_open_message_popup(self, "Package installed");
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int uninstall_package_handler(struct xtk_policy *self)
-{
- char *pkgid;
- device_policy_manager_h handle;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device policy manager");
- return POLICY_RESULT_FAIL;
- }
-
- if (xtk_open_entry_popup(self, "sampleapp",
- "Enter package id",
- &pkgid) == XTK_EVENT_CANCEL) {
- dpm_manager_destroy(handle);
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_NONE;
- };
-
- if (dpm_application_uninstall_package(handle, pkgid) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
-
- xtk_open_message_popup(self, "Package uninstalled");
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int set_mode_restriction_handler(struct xtk_policy *self)
-{
- char *msg;
- int state, index;
- device_policy_manager_h handle;
- const char *text[] = {
- "Disable package installation",
- "Disable package uninstallation"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_get_mode_restriction(handle, &state) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to query policy");
- return POLICY_RESULT_FAIL;
- }
-
- if (index != (state & index)) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "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;
- default:
- msg = "Undefined";
- break;
- }
-
- xtk_open_message_popup(self, msg);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int unset_mode_restriction_handler(struct xtk_policy *self)
-{
- char *msg;
- int state, index;
- device_policy_manager_h handle;
- const char *text[] = {
- "Enable package installation",
- "Enable package uninstallation"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_get_mode_restriction(handle, &state) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to query policy");
- return POLICY_RESULT_FAIL;
- }
-
- if ((state & index) == index) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "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;
- default:
- msg = "Undefined";
- break;
- }
-
- xtk_open_message_popup(self, msg);
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int get_mode_restriction_handler(struct xtk_policy *self)
-{
- int state;
- char msg[128];
- device_policy_manager_h handle;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "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");
-
- xtk_open_message_popup(self, msg);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int add_privilege_to_blacklist_handler(struct xtk_policy *self)
-{
- int state, index;
- char *privilege;
- device_policy_manager_h handle;
- const char *text[] = {
- "Wrt Packakage Privilege",
- "Core Package Privilege"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- if (xtk_open_entry_popup(self, "http://tizen.org/privilege/internet",
- "Enter package privilege name",
- &privilege) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_NONE;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- free(privilege);
- xtk_open_message_popup(self, "Failed to create device policy manager");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_add_privilege_to_blacklist(handle, index, privilege) != DPM_ERROR_NONE) {
- free(privilege);
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_check_privilege_is_blacklisted(handle, index, privilege, &state) != DPM_ERROR_NONE) {
- free(privilege);
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to query privilege blacklist");
- return POLICY_RESULT_FAIL;
- }
-
- if (!state) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Adding privilege to blacklist was failed");
- free(privilege);
- return POLICY_RESULT_FAIL;
- }
-
- dpm_manager_destroy(handle);
-
- xtk_open_message_popup(self, "The privilege is disabled");
- return POLICY_RESULT_SUCCESS;
-}
-
-int remove_privilege_from_blacklist_handler(struct xtk_policy *self)
-{
- int state, index;
- char *privilege;
- device_policy_manager_h handle;
- const char *text[] = {
- "Wrt Packakage Privilege",
- "Core Package Privilege"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- if (xtk_open_entry_popup(self, "http://tizen.org/privilege/internet",
- "Enter package privilege name",
- &privilege) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_NONE;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- free(privilege);
- xtk_open_message_popup(self, "Failed to create device policy manager");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_remove_privilege_from_blacklist(handle, index, privilege) != DPM_ERROR_NONE) {
- free(privilege);
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_check_privilege_is_blacklisted(handle, index, privilege, &state) != DPM_ERROR_NONE) {
- free(privilege);
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to query privilege blacklist");
- return POLICY_RESULT_FAIL;
- }
-
- free(privilege);
-
- if (state) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Removing privilege from blacklist was failed");
- return POLICY_RESULT_FAIL;
- }
-
- xtk_open_message_popup(self, "Privilege is enabled");
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int check_privilege_is_blacklisted_handler(struct xtk_policy *self)
-{
- int state, index;
- char *privilege;
- device_policy_manager_h handle;
- const char *text[] = {
- "Wrt Packakage Privilege",
- "Core Package Privilege"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- if (xtk_open_entry_popup(self, "http://tizen.org/privilege/internet",
- "Enter package privilege name",
- &privilege) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_NONE;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device policy manager");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_application_check_privilege_is_blacklisted(handle, index, privilege, &state) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to query privilege blacklist");
- return POLICY_RESULT_FAIL;
- }
-
- xtk_open_message_popup(self, state ? "Privilege is disabled"
- : "Privilege is enabled");
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-xtk_policy_t xtk_application_policy[] = {
- {
- .id = "INSTALL_PACKAGE",
- .handler = install_package_handler
- },
- {
- .id = "UNINSTALL_PACKAGE",
- .handler = uninstall_package_handler
- },
- {
- .id = "SET_MODE_RESTRICTION",
- .handler = set_mode_restriction_handler
- },
- {
- .id = "UNSET_MODE_RESTRICTION",
- .handler = unset_mode_restriction_handler
- },
- {
- .id = "GET_MODE_RESTRICTION",
- .handler = get_mode_restriction_handler
- },
- {
- .id = "ADD_PRIVILEGE_TO_BLACKLIST",
- .handler = add_privilege_to_blacklist_handler
- },
- {
- .id = "REMOVE_PRIVILEGE_FROM_BLACKLIST",
- .handler = remove_privilege_from_blacklist_handler
- },
- {
- .id = "CHECK_PRIVILEGE_IS_BLACKLISTED",
- .handler = check_privilege_is_blacklisted_handler
- }
-};
-
-xtk_policy_group_t xtk_application_policy_group = {
- .id = "APPLICATION"
-};
-
-void __CONSTRUCTOR__ xtk_application_policy_constructor()
-{
- int ret = 0;
-
- dlog_print(DLOG_DEBUG, LOG_TAG, "application policy constructor");
-
- int nr = ARRAY_SIZE(xtk_application_policy);
- ret = xtk_init_policy(&xtk_application_policy_group, xtk_application_policy, nr);
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "application policy initialization failed");
- }
-}
+++ /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
- */
-
-#include <stdbool.h>
-
-#include <dpm/bluetooth.h>
-
-#include "dpm-toolkit.h"
-
-int set_device_restriction_handler(struct xtk_policy *self)
-{
- int state;
- int enable;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, RESTRICTION_MODE_OPTIONS, &enable) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- dlog_print(DLOG_ERROR, LOG_TAG, "enable %d", enable);
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_bluetooth_set_device_restriction(handle, enable) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_bluetooth_is_device_restricted(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == enable) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, RESTRICTION_MODE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int is_device_restricted_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_bluetooth_is_device_restricted(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, RESTRICTION_MODE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_uuid_restriction_handler(struct xtk_policy *self)
-{
- int state;
- int enable;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, RESTRICTION_MODE_OPTIONS, &enable) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_bluetooth_set_uuid_restriction(handle, enable) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_bluetooth_is_uuid_restricted(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == enable) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, RESTRICTION_MODE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int is_uuid_restricted_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_bluetooth_is_uuid_restricted(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, RESTRICTION_MODE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-xtk_policy_t xtk_bluetooth_policy[] = {
- {
- .id = "SET_DEVICE_RESTRICTION",
- .handler = set_device_restriction_handler
- },
- {
- .id = "IS_DEVICE_RESTRICTED",
- .handler = is_device_restricted_handler
- },
- {
- .id = "SET_UUID_RESTRICTION",
- .handler = set_uuid_restriction_handler
- },
- {
- .id = "IS_UUID_RESTRICTED",
- .handler = is_uuid_restricted_handler
- }
-};
-
-xtk_policy_group_t bluetooth_policy_group = {
- .id = "BLUETOOTH"
-};
-
-void __CONSTRUCTOR__ xtk_bluetooth_policy_constructor()
-{
- int ret = 0;
- dlog_print(DLOG_DEBUG, LOG_TAG, "bluetooth policy constructor");
-
- int nr = ARRAY_SIZE(xtk_bluetooth_policy);
- ret = xtk_init_policy(&bluetooth_policy_group, xtk_bluetooth_policy, nr);
-
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "bluetooth policy initialization fail");
- }
-}
+++ /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
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdio.h>
-
-#include "dpm-toolkit.h"
-
-enum color {
- DEFAULT = 0,
- BLACK = 30,
- RED = 31,
- GREEN = 32,
- YELLOW = 33,
- BLUE = 34,
- MAGENTA = 35,
- CYAN = 36,
- WHITE = 37
-};
-
-enum attribute {
- NONE = 0,
- BOLD = 1
-};
-
-#define fancy_text(color, attr, fmt, ...) \
- printf("%c[%u;%um" fmt, 0x1B, attr, color, ##__VA_ARGS__)
-
-static inline void set_color(int color, int attr)
-{
- printf("%c[%u;%um", 0x1B, attr, color);
-}
-
-static inline void section_separator(void)
-{
- fancy_text(DEFAULT, NONE, "==================================================\n");
-}
-
-static inline void group_separator(void)
-{
- fancy_text(DEFAULT, NONE, "--------------------------------------------------\n");
-}
-
-static inline void text_header(const char* title, const char* msg)
-{
- fancy_text(DEFAULT, NONE, "\n[ ");
- fancy_text(BLUE, BOLD, "%s", title);
- fancy_text(DEFAULT, NONE, " : %s ]\n", msg);
-}
-
-static inline void error_message(const char *msg, int code)
-{
- fancy_text(RED, BOLD, "\n%s(%d)\n", msg, code);
-}
-
-static int open_entry_popup(const char* title, const char* msg, const char* guide, char** value)
-{
- text_header(title, msg);
- section_separator();
- fancy_text(DEFAULT, NONE, "Enter text(type '.' to cancel) : ");
- *value = malloc(64);
- scanf("%64s", *value);
- if (*value[0] == '.') {
- return XTK_EVENT_CANCEL;
- }
-
- if (*value[0] == '~') {
- return XTK_EVENT_OK;
- }
-
- return XTK_EVENT_OK;
-}
-
-static int open_radio_popup(const char* title, const char* text[], int nr, int* index)
-{
- int i, option;
-
- while (1) {
- text_header(title, "Select Option");
- section_separator();
- for (i = 0; i < nr; i++) {
- fancy_text(DEFAULT, NONE, "%3d - %s\n", i, text[i]);
- }
- group_separator();
- fancy_text(DEFAULT, NONE, " -1 - Cancel\n");
- section_separator();
- fancy_text(DEFAULT, NONE, "Select item : ");
- scanf("%d", &option);
- if (option == -1) {
- return XTK_EVENT_CANCEL;
- }
-
- if (option < 0 || option >= i) {
- error_message("WRONG OPTION", option);
- continue;
- }
-
- *index = option;
- return XTK_EVENT_OK;
- }
-}
-
-static int open_message_popup(const char* title, const char* message)
-{
- text_header(title, message);
-
- return XTK_EVENT_OK;
-}
-
-static int open_confirm_popup(const char* title, const char* message)
-{
- int cont;
- text_header(title, message);
- section_separator();
- while (1) {
- fancy_text(YELLOW, NONE, "Enter 1 to continue, or -1 to cancel: ");
- scanf("%d", &cont);
- printf("\n");
-
- if (cont == 1) {
- return XTK_EVENT_OK;
- } if (cont == -1) {
- return XTK_EVENT_CANCEL;
- }
- }
-
- return 0;
-}
-
-static int xtk_cli_select_policy(xtk_policy_group_t* group)
-{
- int i = 0, code, maxid;
- GList* policy_list;
- xtk_policy_t* policy_map[64];
-
- xtk_foreach_policy(policy_list, group) {
- xtk_policy_t* policy = glist_to_policy(policy_list);
- policy_map[i] = policy;
- i++;
- }
-
- maxid = i - 1;
- while (1) {
- int done = 0;
- fancy_text(DEFAULT, NONE, "\n=");
- fancy_text(BLUE, BOLD, " Policy List ");
- fancy_text(DEFAULT, NONE, "=============================\n");
- for (i = 0; i <= maxid; i++) {
- fancy_text(DEFAULT, BOLD, "%3d - %s\n", i, policy_map[i]->description);
- }
- group_separator();
- fancy_text(DEFAULT, NONE, " 99 - Back to policy group list menu\n");
- fancy_text(DEFAULT, NONE, " -1 - Exit\n");
- section_separator();
-
- while (!done) {
- fancy_text(YELLOW, NONE, "> Select policy to test: ");
- scanf("%d", &code);
-
- if (code == 99 || code == -1) {
- return code;
- }
-
- if (code > maxid || code < 0) {
- fancy_text(RED, BOLD, "\n***INVALID POLICY ID (%d)\n", code);
- continue;
- }
-
- printf("Start handler\n");
- if (code >= 0 && code < 64) {
- policy_map[code]->handler(policy_map[code]);
- done = 1;
- }
- }
- }
-
- return 0;
-}
-
-static int xtk_cli_start_toolkit(void)
-{
- int i = 0, code, maxid;
- xtk_policy_group_t* policy_group_map[16];
- GList* group_list;
-
- xtk_foreach_policy_group(group_list) {
- xtk_policy_group_t* group = glist_to_policy_group(group_list);
- policy_group_map[i] = group;
- i++;
- }
-
- maxid = i - 1;
-
- while (1) {
- fancy_text(DEFAULT, NONE, "\n=");
- fancy_text(BLUE, BOLD, " Device Policy Group List ");
- fancy_text(DEFAULT, NONE, "=======================\n");
- for (i = 0; i <= maxid; i++) {
- fancy_text(DEFAULT, NONE, "%3d - %s\n", i, policy_group_map[i]->id);
- }
- group_separator();
- fancy_text(DEFAULT, NONE, " -1 - Exit\n");
- section_separator();
- fancy_text(YELLOW, NONE, " > Enter policy group ID: ");
- scanf("%d", &code);
- if (code > maxid) {
- error_message("INVALID POLICY GROUP ID", code);
- continue;
- }
-
- if (code < 0) {
- set_color(DEFAULT, NONE);
- return 0;
- }
-
- if (xtk_cli_select_policy(policy_group_map[code]) == -1) {
- set_color(DEFAULT, NONE);
- return 0;
- }
- }
-
- return 0;
-}
-
-static xtk_context_t xtk_cli_context = {
- .entry_popup = open_entry_popup,
- .radio_popup = open_radio_popup,
- .message_popup = open_message_popup,
- .confirm_popup = open_confirm_popup
-};
-
-int xtk_cli_main(int argc, char* argv[])
-{
- xtk_context_set_current(&xtk_cli_context);
-
- if (xtk_rebuild_policy_group(POLICY_XML_FILE_PATH) != 0) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Failed to rebuild policy group");
- xtk_free_policy_list();
- return EXIT_FAILURE;
- }
-
- xtk_cli_start_toolkit();
-
- xtk_free_policy_list();
-
- return EXIT_SUCCESS;
-}
+++ /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
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdio.h>
-
-#include "dpm-toolkit.h"
-
-#define BUTTON_CANCEL 1
-#define BUTTON_OK 2
-#define BUTTON_SET 4
-
-static Evas_Object* naviframe;
-static Evas_Object* mainwindow;
-
-static void on_popup_hide(void* data, Evas_Object* obj, void* event_info)
-{
- int* done = (int *)data;
- *done = BUTTON_CANCEL;
-}
-
-static void on_dismissed(void* data, Evas_Object* obj, void* event_info)
-{
- int* done = (int *)data;
- *done = BUTTON_CANCEL;
-}
-
-static void on_block_clicked(void* data, Evas_Object* obj, void* event_info)
-{
- int* done = (int *)data;
- *done = BUTTON_CANCEL;
-}
-
-static void on_cancel_button_clicked(void* data, Evas_Object* obj, void* event_info)
-{
- int* done = (int *)data;
- *done = BUTTON_CANCEL;
-}
-
-static void on_set_button_clicked(void* data, Evas_Object* obj, void* event_info)
-{
- int* done = (int *)data;
- *done = BUTTON_SET;
-}
-
-void wait_for_event(int* done)
-{
- ecore_thread_main_loop_begin();
- while (!*done) {
- ecore_main_loop_iterate();
- }
-
- ecore_thread_main_loop_end();
-}
-
-static Evas_Object* create_basic_popup(Evas_Object* parent, const char* title, void* data)
-{
- Evas_Object* popup = elm_popup_add(parent);
- elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
- evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_part_text_set(popup, "title,text", title);
-
- eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, on_popup_hide, data);
- evas_object_smart_callback_add(popup, "dismissed", on_dismissed, data);
- evas_object_smart_callback_add(popup, "block,clicked", on_block_clicked, data);
-
- return popup;
-}
-
-static Evas_Object* create_entry_box(Evas_Object* parent, const char* msg, const char* guide)
-{
- Evas_Object* entry = elm_entry_add(parent);
- elm_entry_single_line_set(entry, EINA_TRUE);
- elm_entry_scrollable_set(entry, EINA_TRUE);
- evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_object_style_set(entry, "center");
- elm_object_part_content_set(parent, "elm.swallow.content", entry);
-
- if (msg != NULL) {
- elm_entry_entry_set(entry, msg);
- } else if (guide != NULL) {
- elm_object_part_text_set(entry, "guide", guide);
- } else {
- elm_object_part_text_set(entry, "guide", "Enter value");
- }
-
- return entry;
-}
-
-static Evas_Object* create_radio_group(Evas_Object* parent, const char* text[], int nr)
-{
- int i;
- Evas_Object* radio_group = NULL;
- Evas_Object* box = elm_box_add(parent);
- evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_object_style_set(box, "center");
- elm_object_part_content_set(parent, "elm.swallow.content", box);
-
- for (i = 0; i < nr; i++) {
- Evas_Object* radio = elm_radio_add(box);
- evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_object_text_set(radio, text[i]);
- evas_object_show(radio);
- elm_box_pack_end(box, radio);
-
- elm_radio_state_value_set(radio, i);
-
- if (i == 0) {
- radio_group = radio;
- }
-
- elm_radio_group_add(radio, radio_group);
- }
-
- evas_object_size_hint_align_set(radio_group, EVAS_HINT_FILL, EVAS_HINT_FILL);
-
- return radio_group;
-}
-
-static void create_button_group(Evas_Object* parent, int mask, void* data)
-{
- Evas_Object* button;
-
- if (mask & BUTTON_SET) {
- button = elm_button_add(parent);
- elm_object_text_set(button, "set");
- elm_object_style_set(button, "bottom");
- elm_object_part_content_set(parent, "button1", button);
- evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_smart_callback_add(button, "clicked", on_set_button_clicked, data);
- }
-
- if (mask & BUTTON_OK) {
- button = elm_button_add(parent);
- elm_object_text_set(button, "OK");
- elm_object_style_set(button, "bottom");
- elm_object_part_content_set(parent, "button1", button);
- evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_smart_callback_add(button, "clicked", on_set_button_clicked, data);
- }
-
- if (mask & BUTTON_CANCEL) {
- button = elm_button_add(parent);
- elm_object_text_set(button, "cancel");
- elm_object_style_set(button, "bottom");
- elm_object_part_content_set(parent, "button2", button);
- evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_smart_callback_add(button, "clicked", on_cancel_button_clicked, data);
- }
-}
-
-static int open_entry_popup(const char* title, const char* msg, const char* guide, char** value)
-{
- int done = 0;
- Evas_Object* popup = NULL;
- Evas_Object* entry = NULL;
-
- popup = create_basic_popup(naviframe, title, (void *)&done);
- entry = create_entry_box(popup, msg, guide);
- create_button_group(popup, BUTTON_SET | BUTTON_CANCEL, (void *)&done);
- evas_object_show(popup);
-
- wait_for_event(&done);
- if (done != BUTTON_CANCEL) {
- *value = strdup(elm_entry_entry_get(entry));
- } else {
- *value = NULL;
- }
-
- evas_object_del(popup);
-
- return done == BUTTON_CANCEL ? XTK_EVENT_CANCEL : XTK_EVENT_OK;
-}
-
-static int open_radio_popup(const char* title, const char* text[], int nr, int* index)
-{
- int done = 0;
- Evas_Object* popup = NULL;
- Evas_Object* radio = NULL;
-
- popup = create_basic_popup(naviframe, title, (void *)&done);
- radio = create_radio_group(popup, text, nr);
- create_button_group(popup, BUTTON_SET | BUTTON_CANCEL, (void *)&done);
- evas_object_show(popup);
-
- wait_for_event(&done);
-
- if (done != BUTTON_CANCEL) {
- *index = elm_radio_value_get(radio);
- } else {
- *index = -1;
- }
-
- evas_object_del(popup);
-
- return done == BUTTON_CANCEL ? XTK_EVENT_CANCEL : XTK_EVENT_OK;
-}
-
-static int open_message_popup(const char* title, const char* message)
-{
- int done = 0;
- Evas_Object* popup = NULL;
-
- if (title == NULL || message == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameters");
- }
-
- popup = create_basic_popup(naviframe, title, (void *)&done);
- elm_object_text_set(popup, message);
- create_button_group(popup, BUTTON_OK, (void *)&done);
- evas_object_show(popup);
-
- wait_for_event(&done);
-
- evas_object_del(popup);
-
- return done == BUTTON_CANCEL ? XTK_EVENT_CANCEL : XTK_EVENT_OK;
-}
-
-static int open_confirm_popup(const char* title, const char* message)
-{
- int done = 0;
- Evas_Object* popup = NULL;
-
- if (title == NULL || message == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameters");
- }
-
- popup = create_basic_popup(naviframe, title, (void *)&done);
- elm_object_text_set(popup, message);
- create_button_group(popup, BUTTON_OK | BUTTON_CANCEL, (void *)&done);
- evas_object_show(popup);
-
- wait_for_event(&done);
-
- evas_object_del(popup);
-
- return done == BUTTON_CANCEL ? XTK_EVENT_CANCEL : XTK_EVENT_OK;
-}
-
-static void _gl_policy_select(void* data, Evas_Object* obj, void* event_info)
-{
- xtk_policy_t* entity = (xtk_policy_t *)data;
-
- entity->handler(entity);
-
- elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
-}
-
-static char* _gl_policy_label_get(void* data, Evas_Object* obj, const char* part)
-{
- if (strcmp(part, "elm.text") == 0)
- return strdup(policy_get_title((xtk_policy_t *)data));
- else
- return NULL;
-}
-
-static void _gl_policy_group_select(void* data, Evas_Object* obj, void* event_info)
-{
- GList* policy_list = NULL;
- Elm_Genlist_Item_Class* itc;
- Evas_Object* genlist = elm_genlist_add(naviframe);
- xtk_policy_group_t* selected_group = (xtk_policy_group_t *)data;
-
- elm_genlist_item_selected_set((Elm_Object_Item *) event_info, EINA_FALSE);
- elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
-
- itc = elm_genlist_item_class_new();
- itc->item_style = "type1";
- itc->func.text_get = _gl_policy_label_get;
- itc->func.state_get = NULL;
- itc->func.del = NULL;
-
- xtk_foreach_policy(policy_list, selected_group) {
- xtk_policy_t* entity = glist_to_policy(policy_list);
-
- elm_genlist_item_append(genlist, itc, (void *)entity, NULL, ELM_GENLIST_ITEM_NONE,
- _gl_policy_select, (void *)entity);
- }
- elm_genlist_item_class_free(itc);
-
- elm_naviframe_item_push(naviframe, selected_group->id, NULL, NULL, genlist, NULL);
-}
-
-static char* _gl_policy_group_label_get(void* data, Evas_Object* obj, const char* part)
-{
- if (strcmp(part, "elm.text") == 0)
- return strdup(((xtk_policy_group_t *)data)->id);
-
- return NULL;
-}
-
-static Evas_Object* create_genlist(Evas_Object* naviframe)
-{
- Evas_Object* widget;
- Elm_Genlist_Item_Class* itc;
- GList* policy_group_list = NULL;
-
- itc = elm_genlist_item_class_new();
- itc->item_style = "type1";
- itc->func.text_get = _gl_policy_group_label_get;
- itc->func.state_get = NULL;
- itc->func.del = NULL;
-
- widget = elm_genlist_add(naviframe);
-
- xtk_foreach_policy_group(policy_group_list) {
- xtk_policy_group_t* policy_group = glist_to_policy_group(policy_group_list);
- elm_genlist_item_append(widget, itc, (void *)policy_group, NULL, ELM_GENLIST_ITEM_NONE,
- _gl_policy_group_select, (void *)policy_group);
- }
- elm_genlist_item_class_free(itc);
-
- return widget;
-}
-
-static void win_terminate_request_cb(void* data, Evas_Object* obj, void* event_info)
-{
- ui_app_exit();
-}
-
-static void win_delete_request_cb(void* data, Evas_Object* obj, void* event_info)
-{
- /* To make your application go to background,
- Call the elm_win_lower() instead
- Evas_Object *win = (Evas_Object *) data;
- elm_win_lower(win); */
- ui_app_exit();
-}
-
-static Eina_Bool naviframe_pop_cb(void* data, Elm_Object_Item* it)
-{
- ui_app_exit();
- return EINA_FALSE;
-}
-
-static int create_base_gui()
-{
- Elm_Object_Item* nfitem;
- Evas_Object* button;
- Evas_Object* genlist;
- Evas_Object* conform;
-
- /* Window */
- mainwindow = elm_win_util_standard_add(PACKAGE, PACKAGE);
- elm_win_conformant_set(mainwindow, EINA_TRUE);
- elm_win_autodel_set(mainwindow, EINA_TRUE);
-
- if (elm_win_wm_rotation_supported_get(mainwindow)) {
- int rots[4] = { 0, 90, 180, 270 };
- elm_win_wm_rotation_available_rotations_set(mainwindow, (const int*)(&rots), 4);
- }
-
- evas_object_smart_callback_add(mainwindow, "delete,request", win_delete_request_cb, NULL);
-
- /* Conformant */
- conform = elm_conformant_add(mainwindow);
- evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_win_resize_object_add(mainwindow, conform);
- evas_object_show(conform);
-
- /* Indicator */
- elm_win_indicator_mode_set(mainwindow, ELM_WIN_INDICATOR_SHOW);
- elm_win_indicator_opacity_set(mainwindow, ELM_WIN_INDICATOR_TRANSPARENT);
-
- /* Naviframe */
- naviframe = elm_naviframe_add(conform);
- elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_TRUE);
- eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
- evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_content_set(conform, naviframe);
- evas_object_show(naviframe);
-
- /*Genlist */
- genlist = create_genlist(naviframe);
-
- button = elm_button_add(naviframe);
- elm_object_style_set(button, "naviframe/end_btn/default");
- evas_object_smart_callback_add(button, "clicked", win_terminate_request_cb, NULL);
-
- nfitem = elm_naviframe_item_push(naviframe, "DPM Toolkit", button, NULL, genlist, NULL);
- elm_naviframe_item_pop_cb_set(nfitem, naviframe_pop_cb, NULL);
-
- /* Show window after base gui is set up */
- evas_object_show(mainwindow);
-
- return 0;
-}
-
-static xtk_context_t gui_context = {
- .radio_popup = open_radio_popup,
- .entry_popup = open_entry_popup,
- .message_popup = open_message_popup,
- .confirm_popup = open_confirm_popup
-};
-
-static bool app_create(void* data)
-{
- /* Hook to take necessary actions before main event loop starts
- Initialize UI resources and application's data
- If this function returns true, the main loop of application starts
- If this function returns false, the application is terminated */
-
- dlog_print(DLOG_DEBUG, LOG_TAG, " ###### app_create ###### ");
-
- xtk_context_set_current(&gui_context);
-
- if (xtk_rebuild_policy_group(POLICY_XML_FILE_PATH) != 0) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Failed to rebuild policy group");
- return false;
- }
-
- elm_app_base_scale_set(1.8);
- if (create_base_gui() != 0) {
- return false;
- }
-
- return true;
-}
-
-static void app_control(app_control_h app_control, void* data)
-{
- /* Handle the launch request. */
-}
-
-static void app_pause(void* data)
-{
- /* Take necessary actions when application becomes invisible. */
- dlog_print(DLOG_DEBUG, LOG_TAG, " ###### app_pause ###### ");
-}
-
-static void app_resume(void* data)
-{
- /* Take necessary actions when application becomes visible. */
- dlog_print(DLOG_DEBUG, LOG_TAG, " ###### app_resume ###### ");
-}
-
-static void app_terminate(void* data)
-{
- /* Release all resources. */
- dlog_print(DLOG_DEBUG, LOG_TAG, " ###### app_terminate ###### ");
- xtk_free_policy_list();
-}
-
-static void ui_app_lang_changed(app_event_info_h event_info, void* user_data)
-{
- /*APP_EVENT_LANGUAGE_CHANGED */
- char* locale = NULL;
-
- system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
- elm_language_set(locale);
- free(locale);
-
- return;
-}
-
-static void ui_app_orient_changed(app_event_info_h event_info, void* user_data)
-{
- /*APP_EVENT_DEVICE_ORIENTATION_CHANGED */
- return;
-}
-
-static void ui_app_region_changed(app_event_info_h event_info, void* user_data)
-{
- /*APP_EVENT_REGION_FORMAT_CHANGED */
-}
-
-static void ui_app_low_battery(app_event_info_h event_info, void* user_data)
-{
- /*APP_EVENT_LOW_BATTERY */
-}
-
-static void ui_app_low_memory(app_event_info_h event_info, void* user_data)
-{
- /*APP_EVENT_LOW_MEMORY */
-}
-
-int xtk_gui_main(int argc, char* argv[])
-{
- int ret = 0;
-
- ui_app_lifecycle_callback_s event_callback = { 0, };
- app_event_handler_h handlers[5] = { NULL, };
-
- event_callback.create = app_create;
- event_callback.terminate = app_terminate;
- event_callback.pause = app_pause;
- event_callback.resume = app_resume;
- event_callback.app_control = app_control;
-
- ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, NULL);
- ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
-
- ret = ui_app_main(argc, argv, &event_callback, NULL);
- if (ret != APP_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
-
- return ret;
-}
+++ /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
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#include "dpm-toolkit.h"
-
-GList* xtk_policy_group_list;
-static xmlDoc* dpmDoc;
-
-const char* state_change_options[2] = {
- "Allow State Change",
- "Disallow State Change"
-};
-
-const char* restriction_mode_options[2] = {
- "Enable Restriction Mode",
- "Disable Restriction Mode"
-};
-
-const char state_change_results[2][16] = {
- "Allowed",
- "Disallowed"
-};
-
-const char restriction_mode_results[2][16] = {
- "Enabled",
- "Disabled"
-};
-
-int xtk_open_entry_popup(xtk_policy_t* policy, const char* msg, const char* guide, char** entry)
-{
- const char *title = policy_get_title(policy);
- const char *init = policy_get_default_value(policy);
-
- return xtk_context_get_current()->entry_popup(title, msg ? msg : init, guide, entry);
-}
-
-int xtk_open_radio_popup(xtk_policy_t* policy, const char* text[], int nr, int* index)
-{
- int ret;
- const char *title = policy_get_title(policy);
-
- ret = xtk_context_get_current()->radio_popup(title, text, nr, index);
- if (text == state_change_options ||
- text == restriction_mode_options) {
- *index = *index ? 0 : 1;
- }
-
- return ret;
-}
-
-int xtk_open_message_popup(xtk_policy_t* policy, const char* message)
-{
- const char* title = policy_get_title(policy);
-
- return xtk_context_get_current()->message_popup(title, message);
-}
-
-int xtk_open_confirm_popup(xtk_policy_t* policy, const char* message)
-{
- const char* title = policy_get_title(policy);
-
- return xtk_context_get_current()->confirm_popup(title, message);
-}
-
-xmlNodePtr evaluate_xml_node(xmlDoc* dpmDoc, const char* policy_group, const char* policy_id)
-{
- char* xpath = NULL;
- size_t xpath_size;
- xmlXPathContext* context = NULL;
- xmlXPathObject* result = NULL;
- xmlNodePtr xNode = NULL;
- xmlNodeSet* nodeset = NULL;
-
- xpath_size = strlen(policy_group) + strlen(policy_id) + strlen("/manifest/policy-group[@id='%s']/policy[@id='%s']") + 1;
- xpath = (char*)malloc(xpath_size);
-
- if (xpath == NULL) {
- /* malloc fail */
- return NULL;
- }
-
- snprintf(xpath, xpath_size, "/manifest/policy-group[@id='%s']/policy[@id='%s']", policy_group, policy_id);
- dlog_print(DLOG_DEBUG, LOG_TAG, "xPath: %s \n", xpath);
-
- context = xmlXPathNewContext(dpmDoc);
- if (context == NULL) {
- /* error */
- dlog_print(DLOG_ERROR, LOG_TAG, "error make context");
- free(xpath);
- return NULL;
- }
-
- result = xmlXPathEvalExpression((xmlChar*) xpath, context);
- xmlXPathFreeContext(context);
- if (result == NULL) {
- /* error */
- dlog_print(DLOG_ERROR, LOG_TAG, "error make result");
- free(xpath);
- return NULL;
- }
-
- if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
- xmlXPathFreeObject(result);
- /* No result */
- dlog_print(DLOG_ERROR, LOG_TAG, "error nodesetval");
- free(xpath);
- return NULL;
- }
-
- nodeset = result->nodesetval;
- xNode = xmlXPathNodeSetItem(nodeset, 0);
- free(xpath);
- xmlXPathFreeObject(result);
-
- return xNode;
-}
-
-int xtk_init_policy(xtk_policy_group_t* group, xtk_policy_t* policy, int nr)
-{
- int i;
-
- if (policy == NULL) {
- return -1;
- }
-
- for (i = 0; i < nr; i++) {
- group->policies = g_list_append(group->policies, &policy[i]);
- }
- xtk_policy_group_list = g_list_append(xtk_policy_group_list, group);
-
- return 0;
-}
-
-char* get_now_zone(void)
-{
- struct passwd pwd, *result;
- int bufsize;
-
- bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (bufsize == -1) {
- bufsize = 16384;
- }
-
- char *buf = malloc(bufsize * sizeof(char));
- if (buf == NULL) {
- return NULL;
- }
-
- getpwuid_r(getuid(), &pwd, buf, bufsize, &result);
- if (result == NULL) {
- free(buf);
- return NULL;
- }
-
- free(buf);
-
- return strdup(result->pw_name);
-}
-
-void xtk_free_policy_list(void)
-{
- xmlFreeDoc(dpmDoc);
-
- GList* policy_group_list = NULL;
- xtk_foreach_policy_group(policy_group_list) {
- xtk_policy_group_t* policy_group = glist_to_policy_group(policy_group_list);
- if (policy_group->policies) {
- g_list_free(policy_group->policies);
- }
- }
-
- g_list_free(xtk_policy_group_list);
-
- dlog_print(DLOG_DEBUG, LOG_TAG, "All policy group removed");
-}
-
-int xtk_rebuild_policy_group(const char *xmlFilePath)
-{
- GList* policy_group_list = NULL;
-
- dpmDoc = xmlParseFile(xmlFilePath);
- if (dpmDoc == NULL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Failed to load policy specification");
- return -1;
- }
-
- xtk_foreach_policy_group(policy_group_list) {
- xtk_policy_group_t* group = glist_to_policy_group(policy_group_list);
-
- GList* policy_list = NULL;
- xtk_foreach_policy(policy_list, group) {
- xtk_policy_t* policy = glist_to_policy(policy_list);
-
- xmlNodePtr model = evaluate_xml_node(dpmDoc, group->id, policy->id);
- if (!model) {
- printf("Policy %s removed\n", policy->id);
- policy_list = g_list_remove(group->policies, policy);
- continue;
- }
-
- printf("Policy %s added\n", policy->id);
- policy->description = (const char*)xmlGetProp(model, (xmlChar*)"desc");
- policy->model = model;
- }
- }
-
- dlog_print(DLOG_DEBUG, LOG_TAG, "Policy group is successfully reconstructed");
-
- return 0;
-}
-
-static xtk_context_t* xtk_context = NULL;
-
-xtk_context_t* xtk_context_get_current(void)
-{
- return xtk_context;
-}
-
-void xtk_context_set_current(xtk_context_t* context)
-{
- xtk_context = context;
-}
-
-struct xtk_submain {
- const char* name;
- int (*submain)(int argc, char* argv[]);
-} xtk_submains[] = {
- {
- .name = PACKAGE,
- .submain = xtk_gui_main
- },
- {
- .name = "dpm-toolkit",
- .submain = xtk_cli_main
- },
-};
-
-int main(int argc, char* argv[])
-{
- int i;
- struct xtk_submain* submain;
- char* name = strrchr(argv[0], '/');
- name = name ? name + 1 : argv[0];
-
- for (i = 0; i < ARRAY_SIZE(xtk_submains); i++) {
- submain = &xtk_submains[i];
- if (strcmp(name, submain->name) == 0) {
- return submain->submain(argc, argv);
- }
- }
-
- return EXIT_FAILURE;
-}
--- /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"
+
+int main(int argc, char *argv[])
+{
+ /* TBD create interface */
+ return 0;
+}
+++ /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
- */
-
-#include <dpm/password.h>
-
-#include "dpm-toolkit.h"
-
-int set_password_quality_handler(struct xtk_policy *self)
-{
- int index;
- device_policy_manager_h handle;
- int quality;
-
- const char *text[] = {
- "UNSPECIFIED",
- "SIMPLE_PASSWORD",
- "SOMETHING",
- "NUMERIC",
- "ALPHABETIC",
- "ALPHANUMERIC"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- 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) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_quality(handle, quality) == 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_SUCCESS;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_quality_handler(struct xtk_policy *self)
-{
- int index;
- device_policy_manager_h handle;
- int quality;
-
- const char *text[] = {
- "UNSPECIFIED",
- "SIMPLE_PASSWORD",
- "SOMETHING",
- "NUMERIC",
- "ALPHABETIC",
- "ALPHANUMERIC"
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- 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;
- }
- xtk_open_message_popup(self, text[index]);
- return POLICY_RESULT_SUCCESS;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_min_length_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_minimum_length(handle, atoi(input_entry)) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_min_length_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int min_length;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_minimum_length(handle, &min_length) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", min_length);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_min_complex_chars_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_min_complex_chars(handle, atoi(input_entry)) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_min_complex_chars_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int min_complex_chars;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_min_complex_chars(handle, &min_complex_chars) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", min_complex_chars);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_max_failed_attempts_for_wipe_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_maximum_failed_attempts_for_wipe(handle, atoi(input_entry)) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_max_failed_attempts_for_wipe_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_failed_attempts;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_maximum_failed_attempts_for_wipe(handle, &max_failed_attempts) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", max_failed_attempts);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_expires_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_expires(handle, atoi(input_entry)) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_expires_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int expires;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_expires(handle, &expires) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", expires);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_history_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_history(handle, atoi(input_entry)) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_history_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int history;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_history(handle, &history) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", history);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int reset_password_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_reset(handle, input_entry) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_SUCCESS;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int enforce_password_change_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_enforce_change(handle) == 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_SUCCESS;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_max_inactivity_time_device_lock_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_inactivity_time, test_max_inactivity_time;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- max_inactivity_time = atoi(input_entry);
- test_max_inactivity_time = 0;
-
- if (dpm_password_set_max_inactivity_time_device_lock(handle, max_inactivity_time) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_max_inactivity_time_device_lock(handle, &test_max_inactivity_time) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (max_inactivity_time == test_max_inactivity_time) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_max_inactivity_time_device_lock_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_inactivity_time;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_max_inactivity_time_device_lock(handle, &max_inactivity_time) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", max_inactivity_time);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_status_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_status(handle, atoi(input_entry)) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_password_pattern_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- char *test_pw_pattern;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_set_pattern(handle, input_entry) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_pattern(handle, &test_pw_pattern) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (strcmp(input_entry, test_pw_pattern) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- free(test_pw_pattern);
- return POLICY_RESULT_NONE;
- }
-
- free(test_pw_pattern);
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_password_pattern_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *pw_pattern;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_pattern(handle, &pw_pattern) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, pw_pattern);
- free(pw_pattern);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int delete_password_pattern_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_delete_pattern(handle) == 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_max_char_occurrences_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_char_occur, test_max_char_occur;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- max_char_occur = atoi(input_entry);
- test_max_char_occur = 0;
-
- if (dpm_password_set_maximum_character_occurrences(handle, max_char_occur) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_maximum_character_occurrences(handle, &test_max_char_occur) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (max_char_occur == test_max_char_occur) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_max_char_occurrences_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_char_occur;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_maximum_character_occurrences(handle, &max_char_occur) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", max_char_occur);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int set_max_numeric_sequence_length_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_num_seq_length, test_max_num_seq_length;
-
- char *input_entry;
- if (xtk_open_entry_popup(self, "", "", &input_entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- max_num_seq_length = atoi(input_entry);
- test_max_num_seq_length = 0;
-
- if (dpm_password_set_maximum_numeric_sequence_length(handle, max_num_seq_length) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_maximum_numeric_sequence_length(handle, &test_max_num_seq_length) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (max_num_seq_length == test_max_num_seq_length) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, input_entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-int get_max_numeric_sequence_length_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
- int max_num_seq_length;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_password_get_maximum_numeric_sequence_length(handle, &max_num_seq_length) == 0) {
- dpm_manager_destroy(handle);
- char num_text[10] = {0, };
- snprintf(num_text, sizeof(num_text), "%d", max_num_seq_length);
- xtk_open_message_popup(self, num_text);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
-}
-
-xtk_policy_t xtk_password_handle[] = {
- {
- .id = "SET_PASSWORD_QUALITY",
- .handler = set_password_quality_handler
- },
- {
- .id = "GET_PASSWORD_QUALITY",
- .handler = get_password_quality_handler
- },
- {
- .id = "SET_PASSWORD_MIN_LENGTH",
- .handler = set_password_min_length_handler
- },
- {
- .id = "GET_PASSWORD_MIN_LENGTH",
- .handler = get_password_min_length_handler
- },
- {
- .id = "SET_PASSWORD_MIN_COMPLEX_CHARS",
- .handler = set_password_min_complex_chars_handler
- },
- {
- .id = "GET_PASSWORD_MIN_COMPLEX_CHARS",
- .handler = get_password_min_complex_chars_handler
- },
- {
- .id = "SET_PASSWORD_MAX_FAILED_ATTEMPTS_FOR_WIPE",
- .handler = set_password_max_failed_attempts_for_wipe_handler
- },
- {
- .id = "GET_PASSWORD_MAX_FAILED_ATTEMPTS_FOR_WIPE",
- .handler = get_password_max_failed_attempts_for_wipe_handler
- },
- {
- .id = "SET_PASSWORD_EXPIRES",
- .handler = set_password_expires_handler
- },
- {
- .id = "GET_PASSWORD_EXPIRES",
- .handler = get_password_expires_handler
- },
- {
- .id = "SET_PASSWORD_HISTORY",
- .handler = set_password_history_handler
- },
- {
- .id = "GET_PASSWORD_HISTORY",
- .handler = get_password_history_handler
- },
- {
- .id = "RESET_PASSWORD",
- .handler = reset_password_handler
- },
- {
- .id = "ENFORCE_PASSWORD_CHANGE",
- .handler = enforce_password_change_handler
- },
- {
- .id = "SET_MAX_INACTIVITY_TIME_DEVICE_LOCK",
- .handler = set_max_inactivity_time_device_lock_handler
- },
- {
- .id = "GET_MAX_INACTIVITY_TIME_DEVICE_LOCK",
- .handler = get_max_inactivity_time_device_lock_handler
- },
- {
- .id = "SET_PASSWORD_STATUS",
- .handler = set_password_status_handler
- },
- {
- .id = "SET_PASSWORD_PATTERN",
- .handler = set_password_pattern_handler
- },
- {
- .id = "GET_PASSWORD_PATTERN",
- .handler = get_password_pattern_handler
- },
- {
- .id = "DELETE_PASSWORD_PATTERN",
- .handler = delete_password_pattern_handler
- },
- {
- .id = "SET_MAX_CHAR_OCCURRENCES",
- .handler = set_max_char_occurrences_handler
- },
- {
- .id = "GET_MAX_CHAR_OCCURRENCES",
- .handler = get_max_char_occurrences_handler
- },
- {
- .id = "SET_MAX_NUMERIC_SEQUENCE_LENGTH",
- .handler = set_max_numeric_sequence_length_handler
- },
- {
- .id = "GET_MAX_NUMERIC_SEQUENCE_LENGTH",
- .handler = get_max_numeric_sequence_length_handler
- }
-};
-
-xtk_policy_group_t password_handle_group = {
- .id = "PASSWORD"
-};
-
-void __CONSTRUCTOR__ xtk_password_handle_constructor()
-{
- int ret = 0;
-
- dlog_print(DLOG_DEBUG, LOG_TAG, "password handle constructor");
-
- int nr = ARRAY_SIZE(xtk_password_handle);
- ret = xtk_init_policy(&password_handle_group, xtk_password_handle, nr);
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "password handle initialization fail");
- }
-}
+++ /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
- */
-
-#include <dpm/restriction.h>
-
-#include "dpm-toolkit.h"
-
-int set_camera_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_camera_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_camera_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_camera_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_camera_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_microphone_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_microphone_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_microphone_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_microphone_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_microphone_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_location_state_handler(struct xtk_policy *self)
-{
- int state;
- int allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_location_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_location_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_location_state_handler(struct xtk_policy *self)
-{
- int state, ret;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- ret = dpm_restriction_get_location_state(handle, &state);
- if (ret == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_clipboard_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_clipboard_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_clipboard_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_clipboard_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_clipboard_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_usb_debugging_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_usb_debugging_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_usb_debugging_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_usb_debugging_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_usb_debugging_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_wifi_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_wifi_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_wifi_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_wifi_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_wifi_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_wifi_hotspot_state_handler(struct xtk_policy *self)
-{
- int state;
- int allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_wifi_hotspot_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_wifi_hotspot_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_wifi_hotspot_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_wifi_hotspot_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_bluetooth_tethering_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_bluetooth_tethering_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_tethering_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_bluetooth_tethering_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_tethering_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_usb_tethering_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_usb_tethering_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_usb_tethering_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_usb_tethering_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_usb_tethering_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_external_storage_state_handler(struct xtk_policy *self)
-{
- int index, state;
- device_policy_manager_h handle = NULL;
- const char* text[] = {
- "Disallow External Storage",
- "Allow External Storage"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to enforce handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_external_storage_state(handle, &state) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to query handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (state != index) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Policy was not setted properly");;
- return POLICY_RESULT_NONE;
- }
-
- xtk_open_message_popup(self, state ? "External Storage Allowed"
- : "External Storage Disallowed");
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_external_storage_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to query handle");
- return POLICY_RESULT_NONE;
- }
-
- xtk_open_message_popup(self, state ? "External Storage Allowed"
- : "External Storage Disallowed");
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_bluetooth_mode_change_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_bluetooth_mode_change_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_mode_change_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_bluetooth_mode_change_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_mode_change_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_bluetooth_desktop_connectivity_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_bluetooth_desktop_connectivity_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_desktop_connectivity_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_bluetooth_desktop_connectivity_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_desktop_connectivity_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_bluetooth_pairing_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_bluetooth_pairing_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_pairing_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_bluetooth_pairing_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_bluetooth_pairing_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_popimap_email_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_popimap_email_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_popimap_email_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_popimap_email_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_popimap_email_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_messaging_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_messaging_state(handle, "sim1", allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_messaging_state(handle, "sim1", &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_messaging_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_messaging_state(handle, "sim1", &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int set_browser_state_handler(struct xtk_policy *self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_set_browser_state(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_browser_state(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int get_browser_state_handler(struct xtk_policy *self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_restriction_get_browser_state(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-xtk_policy_t xtk_restriction_policy[] = {
- {
- .id = "SET_CAMERA_STATE",
- .handler = set_camera_state_handler
- },
- {
- .id = "GET_CAMERA_STATE",
- .handler = get_camera_state_handler
- },
- {
- .id = "SET_MICROPHONE_STATE",
- .handler = set_microphone_state_handler
- },
- {
- .id = "GET_MICROPHONE_STATE",
- .handler = get_microphone_state_handler
- },
- {
- .id = "SET_LOCATION_STATE",
- .handler = set_location_state_handler
- },
- {
- .id = "GET_LOCATION_STATE",
- .handler = get_location_state_handler
- },
- {
- .id = "SET_CLIPBOARD_STATE",
- .handler = set_clipboard_state_handler
- },
- {
- .id = "GET_CLIPBOARD_STATE",
- .handler = get_clipboard_state_handler
- },
- {
- .id = "SET_USB_DEBUGGING_STATE",
- .handler = set_usb_debugging_state_handler
- },
- {
- .id = "GET_USB_DEBUGGING_STATE",
- .handler = get_usb_debugging_state_handler
- },
- {
- .id = "SET_WIFI_STATE",
- .handler = set_wifi_state_handler
- },
- {
- .id = "GET_WIFI_STATE",
- .handler = get_wifi_state_handler
- },
- {
- .id = "SET_WIFI_HOTSPOT_STATE",
- .handler = set_wifi_hotspot_state_handler
- },
- {
- .id = "GET_WIFI_HOTSPOT_STATE",
- .handler = get_wifi_hotspot_state_handler
- },
- {
- .id = "SET_BLUETOOTH_TETHERING_STATE",
- .handler = set_bluetooth_tethering_state_handler
- },
- {
- .id = "GET_BLUETOOTH_TETHERING_STATE",
- .handler = get_bluetooth_tethering_state_handler
- },
- {
- .id = "SET_USB_TETHERING_STATE",
- .handler = set_usb_tethering_state_handler
- },
- {
- .id = "GET_USB_TETHERING_STATE",
- .handler = get_usb_tethering_state_handler
- },
- {
- .id = "SET_EXTERNAL_STORAGE_STATE",
- .handler = set_external_storage_state_handler
- },
- {
- .id = "GET_EXTERNAL_STORAGE_STATE",
- .handler = get_external_storage_state_handler
- },
- {
- .id = "SET_BLUETOOTH_MODE_CHANGE_STATE",
- .handler = set_bluetooth_mode_change_state_handler
- },
- {
- .id = "GET_BLUETOOTH_MODE_CHANGE_STATE",
- .handler = get_bluetooth_mode_change_state_handler
- },
- {
- .id = "SET_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE",
- .handler = set_bluetooth_desktop_connectivity_state_handler
- },
- {
- .id = "GET_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE",
- .handler = get_bluetooth_desktop_connectivity_state_handler
- },
- {
- .id = "SET_BLUETOOTH_PAIRING_STATE",
- .handler = set_bluetooth_pairing_state_handler
- },
- {
- .id = "GET_BLUETOOTH_PAIRING_STATE",
- .handler = get_bluetooth_pairing_state_handler
- },
- {
- .id = "SET_POPIMAP_EMAIL_STATE",
- .handler = set_popimap_email_state_handler
- },
- {
- .id = "GET_POPIMAP_EMAIL_STATE",
- .handler = get_popimap_email_state_handler
- },
- {
- .id = "SET_MESSAGING_STATE",
- .handler = set_messaging_state_handler
- },
- {
- .id = "GET_MESSAGING_STATE",
- .handler = get_messaging_state_handler
- },
- {
- .id = "SET_BROWSER_STATE",
- .handler = set_browser_state_handler
- },
- {
- .id = "GET_BROWSER_STATE",
- .handler = get_browser_state_handler
- }
-};
-
-xtk_policy_group_t restriction_policy_group = {
- .id = "RESTRICTION"
-};
-
-void __CONSTRUCTOR__ xtk_restriction_policy_constructor()
-{
- int ret = 0;
-
- dlog_print(DLOG_DEBUG, LOG_TAG, "restriction policy constructor");
-
- int nr = ARRAY_SIZE(xtk_restriction_policy);
- ret = xtk_init_policy(&restriction_policy_group, xtk_restriction_policy, nr);
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "restriction policy initialization fail");
- }
-}
+++ /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
- */
-
-#include <dpm/security.h>
-
-#include "dpm-toolkit.h"
-
-int lock_now_handler(struct xtk_policy* self)
-{
- device_policy_manager_h handle;
-
- if (xtk_open_confirm_popup(self, "This operation will lockout the screen") == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device policy manager");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_security_lockout_screen(handle) != DPM_ERROR_NONE) {
- xtk_open_message_popup(self, "Failed to lockout screen");
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int encrypt_device_handler(struct xtk_policy* self)
-{
- int index;
- device_policy_manager_h handle;
- const char *text[] = {
- "Encrypt Internal Storage",
- "Encrypt External Storage"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
- }
-
- dpm_manager_destroy(handle);
-
- xtk_open_message_popup(self, "Operation successfully triggerred, "
- "but product must provide encryption backend");
-
- return POLICY_RESULT_SUCCESS;
-}
-
-int decrypt_device_handler(struct xtk_policy* self)
-{
- int index;
- device_policy_manager_h handle;
- const char *text[] = {
- "Decrypt Internal Storage",
- "Decrypt External Storage"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
- } else if (index == 1) {
- if (dpm_security_set_external_storage_encryption(handle, FALSE) != DPM_ERROR_NONE) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
- }
-
- dpm_manager_destroy(handle);
-
- xtk_open_message_popup(self, "Operation successfully triggerred, "
- "but product must provide decryption backend");
-
- return POLICY_RESULT_SUCCESS;
-
-}
-
-int wipe_data_handler(struct xtk_policy* self)
-{
- int index;
- device_policy_manager_h handle;
- const char *text[] = {
- "Wipe Internal Storage",
- "Wipe External Storage"
- };
-
- if (xtk_open_radio_popup(self, text, ARRAY_SIZE(text), &index) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Selection canceled");
- return POLICY_RESULT_NONE;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "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);
- xtk_open_message_popup(self, "Failed to enforce policy");
- return POLICY_RESULT_FAIL;
- }
- }
-
- dpm_manager_destroy(handle);
-
- xtk_open_message_popup(self, "Operation successfully triggerred "
- "but it may take a long time to complete");
-
- return POLICY_RESULT_SUCCESS;
-}
-
-xtk_policy_t xtk_security_policy[] = {
- {
- .id = "LOCK_NOW",
- .handler = lock_now_handler
- },
- {
- .id = "WIPE_DATA",
- .handler = wipe_data_handler
- }
-};
-
-xtk_policy_group_t security_policy_group = {
- .id = "SECURITY"
-};
-
-void __CONSTRUCTOR__ xtk_security_policy_constructor()
-{
- int ret = 0;
-
- dlog_print(DLOG_DEBUG, LOG_TAG, "security policy constructor");
-
- int nr = ARRAY_SIZE(xtk_security_policy);
- ret = xtk_init_policy(&security_policy_group, xtk_security_policy, nr);
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "security policy initialization fail");
- }
-}
--- /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 "button.h"
+
+Button::Button(Widget* parent) :
+ Widget("Button", ::elm_button_add(Widget::evasObject(parent)))
+{
+ ::evas_object_smart_callback_add(evasObject(this),
+ "clicked",
+ dispatchEventHandler,
+ reinterpret_cast<void *>(this));
+}
+
+Button::~Button()
+{
+}
+
+void Button::dispatchEventHandler(void* data, Evas_Object* obj, void* event)
+{
+ Button* self = reinterpret_cast<Button *>(data);
+ self->clickEvent.emit();
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_BUTTON_H__
+#define __DPM_TOOLKIT_BUTTON_H__
+
+#include <functional>
+#include "widget.h"
+
+class Button : public Widget {
+public:
+ Button(Widget* parent);
+ virtual ~Button();
+
+public:
+ Signal<> clickEvent;
+
+private:
+ static void dispatchEventHandler(void* data, Evas_Object* obj, void* event_info);
+};
+
+#endif
--- /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 "confirm-box.h"
+
+ConfirmBox::ConfirmBox(Widget *parent, const std::string& title, const std::string& msg)
+ : Popup(parent, title), okayButton(nullptr), cancelButton(nullptr)
+{
+ setText(msg);
+}
+
+ConfirmBox::~ConfirmBox()
+{
+ if (okayButton)
+ delete okayButton;
+ else if (cancelButton)
+ delete cancelButton;
+}
+
+void ConfirmBox::onOkayButtonPressed()
+{
+ setStatus(Popup::Okay);
+}
+
+void ConfirmBox::onCancelButtonPressed()
+{
+ setStatus(Popup::Canceled);
+}
+
+bool ConfirmBox::createControl()
+{
+ okayButton = new Button(this);
+ okayButton->setText("OK");
+ okayButton->setStyle("bottom");
+ okayButton->clickEvent.connect(this, &ConfirmBox::onOkayButtonPressed);
+
+ cancelButton = new Button(this);
+ cancelButton->setText("Cancle");
+ cancelButton->setStyle("bottom");
+ cancelButton->clickEvent.connect(this, &ConfirmBox::onCancelButtonPressed);
+
+ setContent("button1", okayButton);
+ setContent("button2", cancelButton);
+
+ return true;
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_CONFIRM_BOX_H__
+#define __DPM_TOOLKIT_CONFIRM_BOX_H__
+
+#include "popup.h"
+#include "button.h"
+
+class ConfirmBox:public Popup {
+public:
+ ConfirmBox(Widget *parent, const std::string& title, const std::string& msg);
+ virtual ~ConfirmBox();
+
+protected:
+ virtual bool createControl();
+
+private:
+ void onOkayButtonPressed();
+ void onCancelButtonPressed();
+
+protected:
+ Button *okayButton;
+ Button *cancelButton;
+};
+
+#endif
--- /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 "conformant-window.h"
+
+ConformantWindow::ConformantWindow(const std::string& packageName) :
+ Window(packageName.c_str()), conformant(nullptr)
+{
+ conformant = new Conformant(this);
+}
+
+ConformantWindow::~ConformantWindow()
+{
+ if (conformant)
+ delete conformant;
+}
+
+int ConformantWindow::open()
+{
+ conformant->show();
+ this->show();
+ return 0;
+}
+
+void ConformantWindow::setContent(Widget* content)
+{
+ conformant->setContent(content);
+}
--- /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.
+ *
+ */
+#ifndef __DPM_TOOLKIT_CONFORMANT_WINDOW_H__
+#define __DPM_TOOLKIT_CONFORMANT_WINDOW_H__
+
+#include "window.h"
+#include "conformant.h"
+
+class ConformantWindow : public Window {
+public:
+ ConformantWindow(const std::string& packageName);
+ virtual ~ConformantWindow();
+
+ int open();
+ void setContent(Widget* content);
+
+ inline Conformant* getConformant()
+ {
+ return conformant;
+ }
+
+private:
+ Conformant* conformant;
+};
+
+#endif
--- /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 "conformant.h"
+
+Conformant::Conformant(Widget* parent) :
+ Widget("Conformant", ::elm_conformant_add(Widget::evasObject(parent)))
+{
+ ::elm_win_resize_object_add(Widget::evasObject(parent), evasObject(this));
+}
+
+Conformant::~Conformant()
+{
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_CONFORMANT_H__
+#define __DPM_TOOLKIT_CONFORMANT_H__
+
+#include "widget.h"
+#include "conformant.h"
+
+class Conformant : public Widget {
+public:
+ Conformant(Widget* parent);
+ virtual ~Conformant();
+};
+
+#endif
--- /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 "entry.h"
+
+TextEntry::TextEntry(Widget* parent) :
+ Widget("Entry", ::elm_entry_add(Widget::evasObject(parent)))
+{
+ ::elm_entry_single_line_set(evasObject(this), EINA_TRUE);
+ ::elm_entry_scrollable_set(evasObject(this), EINA_TRUE);
+
+ ::evas_object_size_hint_weight_set(evasObject(this), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ ::evas_object_size_hint_align_set(evasObject(this), EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ setStyle("center");
+ ::elm_object_part_content_set(evasObject(parent), "elm.swallow.content", evasObject(this));
+}
+
+void TextEntry::setEntryText(const std::string& text)
+{
+ ::elm_entry_entry_set(evasObject(this), text.c_str());
+}
+
+void TextEntry::setGuideText(const std::string& guide)
+{
+ setText("guide", guide.c_str());
+}
+
+std::string TextEntry::getEntryText()
+{
+ return std::string(::elm_entry_entry_get(evasObject(this)));
+}
+
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_ENTRY_H__
+#define __DPM_TOOLKIT_ENTRY_H__
+
+#include "widget.h"
+
+class TextEntry : public Widget {
+public:
+ TextEntry(Widget* parent);
+ virtual ~TextEntry() {}
+
+ void setEntryText(const std::string& text);
+ void setGuideText(const std::string& guide);
+ std::string getEntryText();
+};
+
+#endif
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_GENLIST_H__
+#define __DPM_TOOLKIT_GENLIST_H__
+
+#include <cstring>
+#include <memory>
+#include <vector>
+
+#include "widget.h"
+
+template<typename T>
+class Genlist;
+
+template<typename T>
+class GenlistContentProvider {
+public:
+ GenlistContentProvider() {}
+ virtual ~GenlistContentProvider() {}
+
+ virtual char* getLabel(const std::string& part, Evas_Object* obj, T* itemData) { return NULL; }
+ virtual Evas_Object* getObject(const std::string& part, Evas_Object* obj, T* itemData) { return NULL; }
+ virtual void addItems(Genlist<T>* genlist) = 0;
+};
+
+template<typename T>
+class GenlistItem {
+public:
+ virtual ~GenlistItem()
+ {
+ }
+
+ void setSelectMode(Elm_Object_Select_Mode mode)
+ {
+ ::elm_genlist_item_select_mode_set(item, mode);
+ }
+
+ void setDisabled(bool disable)
+ {
+ ::elm_object_item_disabled_set(item, disable);
+ }
+
+ friend class Genlist<T>;
+
+private:
+ GenlistItem(Elm_Object_Item *object) : item(object)
+ {
+ }
+
+private:
+ Elm_Object_Item *item;
+};
+
+template<typename T>
+class Genlist : public Widget {
+public:
+ enum Flags {
+ setCompressMode = (1 << 0),
+ setListScrollMode = (1 << 1),
+ setHomogeneous = (1 << 2),
+ };
+
+ Genlist(Widget* parent, int style);
+ virtual ~Genlist();
+
+ GenlistItem<T> append(const char* style, T* idata);
+
+ void setContentProvider(GenlistContentProvider<T>* provider);
+ GenlistContentProvider<T>* getContentProvider() const;
+
+private:
+ static char* dispatchLabel(void *data, Evas_Object *obj, const char *part);
+ static Evas_Object* dispatchContent(void *data, Evas_Object *obj, const char *part);
+ static void deleteData(void* data, Evas_Object* obj);
+ static void dispatchCallback(void* data, Evas_Object* obj, void* event);
+
+public:
+ Signal<Evas_Object*, T*, void*> itemSelectedEvent;
+
+private:
+ GenlistContentProvider<T>* contentProvider;
+};
+
+template<typename T>
+struct GenlistItemData {
+ GenlistItemData(Genlist<T>* parent, T* idata) :
+ genlist(parent), itemData(idata)
+ {
+ }
+
+ virtual ~GenlistItemData()
+ {
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "Genlist Item deleted");
+ }
+
+ Genlist<T>* genlist;
+ T* itemData;
+};
+
+template<typename T>
+Genlist<T>::Genlist(Widget* parent, int style) :
+ Widget("Genlist", ::elm_genlist_add(Widget::evasObject(parent))), contentProvider(nullptr)
+{
+ if (style & setCompressMode) {
+ ::elm_genlist_mode_set(evasObject(this), ELM_LIST_COMPRESS);
+ }
+
+ if (style & setListScrollMode) {
+ ::elm_genlist_mode_set(evasObject(this), ELM_LIST_SCROLL);
+ }
+
+ if (style & setHomogeneous) {
+ ::elm_genlist_homogeneous_set(evasObject(this), EINA_TRUE);
+ }
+}
+
+template<typename T>
+Genlist<T>::~Genlist()
+{
+}
+
+template<typename T>
+GenlistItem<T> Genlist<T>::append(const char* style, T* itemData)
+{
+ Elm_Genlist_Item_Class *klass = ::elm_genlist_item_class_new();
+ klass->item_style = style;
+ klass->func.text_get = &Genlist<T>::dispatchLabel;
+ klass->func.content_get = &Genlist<T>::dispatchContent;
+ klass->func.del = &Genlist<T>::deleteData;
+
+ GenlistItemData<T>* data = new GenlistItemData<T>(this, itemData);
+
+ GenlistItem<T> item(::elm_genlist_item_append(evasObject(this),
+ klass,
+ reinterpret_cast<void *>(data),
+ NULL,
+ ELM_GENLIST_ITEM_NONE,
+ dispatchCallback,
+ reinterpret_cast<void *>(data)));
+
+ ::elm_genlist_item_class_free(klass);
+
+ return item;
+}
+
+template<typename T>
+void Genlist<T>::setContentProvider(GenlistContentProvider<T>* provider)
+{
+ // contentProvider must be set before populating items
+ contentProvider = provider;
+ contentProvider->addItems(this);
+}
+
+template<typename T>
+char* Genlist<T>::dispatchLabel(void *data, Evas_Object *obj, const char *part)
+{
+ GenlistItemData<T>* self = reinterpret_cast<GenlistItemData<T> *>(data);
+ return self->genlist->contentProvider->getLabel(part, obj, self->itemData);
+}
+
+template<typename T>
+Evas_Object* Genlist<T>::dispatchContent(void *data, Evas_Object *obj, const char *part)
+{
+ GenlistItemData<T> *self = reinterpret_cast<GenlistItemData<T> *>(data);
+ return self->genlist->contentProvider->getObject(part, obj, self->itemData);
+}
+
+template<typename T>
+void Genlist<T>::deleteData(void* data, Evas_Object* obj)
+{
+ GenlistItemData<T>* item = reinterpret_cast<GenlistItemData<T> *>(data);
+ delete item;
+}
+
+template<typename T>
+void Genlist<T>::dispatchCallback(void* data, Evas_Object* obj, void* event)
+{
+ GenlistItemData<T>* self = reinterpret_cast<GenlistItemData<T> *>(data);
+ return self->genlist->itemSelectedEvent.emit(obj, self->itemData, event);
+}
+#endif
--- /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 "message-box.h"
+
+MessageBox::MessageBox(Widget* parent, const std::string& title, const std::string& msg)
+ : Popup(parent, title), okayButton(nullptr)
+{
+ setText(msg);
+}
+
+MessageBox::~MessageBox()
+{
+ if (okayButton)
+ delete okayButton;
+}
+
+void MessageBox::onOkayButtonPressed()
+{
+ setStatus(Popup::Okay);
+}
+
+bool MessageBox::createControl()
+{
+ okayButton = new Button(this);
+ okayButton->setText("OK");
+ okayButton->setStyle("bottom");
+ okayButton->clickEvent.connect(this, &MessageBox::onOkayButtonPressed);
+
+ setContent("button1", okayButton);
+
+ return true;
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_MESSAGE_BOX_H__
+#define __DPM_TOOLKIT_MESSAGE_BOX_H__
+
+#include "popup.h"
+#include "button.h"
+
+class MessageBox : public Popup {
+public:
+ MessageBox(Widget* parent, const std::string& title, const std::string& msg);
+ virtual ~MessageBox();
+
+protected:
+ virtual bool createControl();
+
+private:
+ void onOkayButtonPressed();
+
+protected:
+ Button *okayButton;
+};
+
+#endif
--- /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 "naviframe.h"
+
+struct NaviframeItemData {
+ NaviframeItemData(Naviframe *nf, Widget *widget):owner(nf), content(widget) {}
+
+ Naviframe *owner;
+ Widget *content;
+};
+
+namespace {
+
+static Eina_Bool naviframePopupCallback(void *data, Elm_Object_Item *it)
+{
+ NaviframeItemData *item = reinterpret_cast < NaviframeItemData *>(data);
+ item->owner->pagePopEvent.emit(item->content);
+ delete item;
+ return true;
+}
+} // namespace
+
+Naviframe::Naviframe(Widget *parent) :
+ Widget("Naviframe", elm_naviframe_add(Widget::evasObject(parent)))
+{
+ ::elm_naviframe_prev_btn_auto_pushed_set(evasObject(this), EINA_TRUE);
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_KEY_DOWN,
+ dispatchEvent,
+ reinterpret_cast < void *>(this));
+}
+
+Naviframe::~Naviframe()
+{
+}
+
+void Naviframe::handleEvent(void *event)
+{
+ Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event);
+ if (!strcmp(ev->keyname, "XF86Home") || !strcmp(ev->keyname, "XF86Back")) {
+ ::elm_naviframe_item_pop(evasObject(this));
+ }
+}
+
+void Naviframe::dispatchEvent(void *data, Evas *evas, Evas_Object *obj, void *event)
+{
+ Naviframe *nf = reinterpret_cast<Naviframe *>(data);
+ nf->handleEvent(event);
+}
+
+static Eina_Bool naviframeExitCallback(void *data, Elm_Object_Item *it)
+{
+ // Called when the main naviframe is popped.
+ NaviframeItemData *item = reinterpret_cast < NaviframeItemData *>(data);
+ item->owner->pagePopEvent.emit(item->content);
+ delete item;
+ ::ui_app_exit();
+ return EINA_FALSE;
+}
+
+void Naviframe::onMainPageExitButtonPressed(void)
+{
+ // Called after the back key is clicked on the main page.
+ ::ui_app_exit();
+}
+
+void Naviframe::setMainPage(const std::string& title, Widget *contents)
+{
+ // The setMainpage required for operation of app exit
+ Elm_Object_Item *nfitem;
+ Button *exitButton = new Button(this);
+ exitButton->setStyle("naviframe/end_btn/default");
+ exitButton->clickEvent.connect(this, &Naviframe::onMainPageExitButtonPressed);
+
+ nfitem =::elm_naviframe_item_push(evasObject(this), title.c_str(), evasObject(exitButton), NULL, evasObject(contents), NULL);
+
+ NaviframeItemData *data = new NaviframeItemData(this, contents);
+ ::elm_naviframe_item_pop_cb_set(nfitem, naviframeExitCallback, reinterpret_cast < void *>(data));
+}
+
+void Naviframe::pushPage(const std::string& title, Widget *content)
+{
+ Elm_Object_Item *nfitem;
+ nfitem =::elm_naviframe_item_push(evasObject(this), title.c_str(), nullptr, nullptr, evasObject(content), NULL);
+
+ NaviframeItemData *data = new NaviframeItemData(this, content);
+ ::elm_naviframe_item_pop_cb_set(nfitem, naviframePopupCallback, reinterpret_cast < void *>(data));
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_NAVIFRAME_H__
+#define __DPM_TOOLKIT_NAVIFRAME_H__
+
+#include "widget.h"
+#include "button.h"
+
+class Naviframe : public Widget {
+public:
+ Naviframe(Widget* parent);
+ virtual ~Naviframe();
+
+ void pushPage(const std::string& title, Widget* content);
+ void setMainPage(const std::string& title, Widget* contents);
+
+ virtual void handleEvent(void *data);
+
+ void onMainPageExitButtonPressed(void);
+
+public:
+ Signal<Widget *> pagePopEvent;
+
+private:
+ static void dispatchEvent(void* data, Evas* evas, Evas_Object* obj, void* event_info);
+};
+
+#endif
--- /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 "popup.h"
+
+Popup::Popup(Widget* parent, const std::string& title) :
+ Widget("Popup", ::elm_popup_add(Widget::evasObject(parent))), status(0)
+{
+ setAlign(1.0);
+ ::evas_object_size_hint_weight_set(evasObject(this), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ setTitle(title);
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_KEY_DOWN,
+ dispatchWidgetEvent,
+ reinterpret_cast<void *>(this));
+}
+
+Popup::~Popup()
+{
+}
+
+int Popup::open()
+{
+ if (createControl()) {
+ show();
+ waitForEvent();
+ return status;
+ }
+
+ return -1;
+}
+
+void Popup::waitForEvent()
+{
+ ::ecore_thread_main_loop_begin();
+ while (!*(volatile int *)(&status)) {
+ ::ecore_main_loop_iterate();
+ }
+
+ ::ecore_thread_main_loop_end();
+}
+
+void Popup::setAlign(double align)
+{
+ ::elm_popup_align_set(evasObject(this), ELM_NOTIFY_ALIGN_FILL, align);
+}
+
+void Popup::setTitle(const std::string &text)
+{
+ setText("title,text", text.c_str());
+ ::elm_object_item_part_text_translatable_set(evasObject(this), "title,text", EINA_TRUE);
+}
+
+void Popup::dispatchWidgetEvent(void *data, Evas *evas, Evas_Object *obj, void *event)
+{
+ Popup* self = reinterpret_cast<Popup *>(data);
+
+ Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event;
+ if (!strcmp(ev->keyname, "XF86Home") || !strcmp(ev->keyname, "XF86Back")) {
+ self->setStatus(Popup::Canceled);
+ }
+}
+
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_POPUP_H__
+#define __DPM_TOOLKIT_POPUP_H__
+
+#include <string>
+
+#include "widget.h"
+
+class Popup : public Widget {
+public:
+ enum {
+ Okay = 1 << 1,
+ Canceled = 1 << 2,
+ };
+
+ void setTitle(const std::string &text);
+ void setTimeout(double time);
+ void setAlign(double align);
+
+ int open();
+
+ inline int getResult() const
+ {
+ return status;
+ }
+
+protected:
+ Popup(Widget* parent, const std::string& title);
+ virtual ~Popup();
+
+ virtual bool createControl() = 0;
+
+ void waitForEvent();
+
+ inline void setStatus(int res)
+ {
+ status = res;
+ }
+
+private:
+ static void dispatchWidgetEvent(void *data, Evas *evas, Evas_Object *obj, void *event);
+
+private:
+ int status;
+};
+
+#endif
--- /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 "radio.h"
+
+Radio::Radio(Widget* parent, const std::string radioText[], int index) :
+ Widget("Radio")
+{
+ Evas_Object* box = ::elm_box_add(Widget::evasObject(parent));
+ ::elm_object_style_set(box, "center");
+ ::elm_object_part_content_set(Widget::evasObject(parent), "elm.swallow.content", box);
+
+ for (int i = 0; i < index; i++) {
+ Evas_Object* radio = ::elm_radio_add(box);
+ ::evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ ::elm_object_text_set(radio, radioText[i].c_str());
+ ::evas_object_show(radio);
+ ::elm_box_pack_end(box, radio);
+
+ ::elm_radio_state_value_set(radio, i);
+
+ if (i == 0) {
+ setObject(radio);
+ }
+
+ ::elm_radio_group_add(radio, evasObject(this));
+ }
+
+ ::evas_object_size_hint_align_set(evasObject(this), EVAS_HINT_FILL, EVAS_HINT_FILL);
+}
+
+Radio::~Radio()
+{
+}
+
+int Radio::getValue()
+{
+ return ::elm_radio_value_get(evasObject(this));
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_RADIO_H__
+#define __DPM_TOOLKIT_RADIO_H__
+
+#include "widget.h"
+
+class Radio : public Widget {
+public:
+ Radio(Widget* parent, const std::string radioText[], int index);
+ virtual ~Radio();
+
+ int getValue();
+};
+
+#endif
--- /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 "select-popup.h"
+
+SelectPopup::SelectPopup(Widget* parent, const std::string& title, const std::string radioText[], int nr) :
+ Popup(parent, title), okayButton(nullptr), cancelButton(nullptr), radio(nullptr)
+{
+ radio = new Radio(this, radioText, nr);
+}
+
+SelectPopup::~SelectPopup()
+{
+ if (okayButton)
+ delete okayButton;
+
+ if (cancelButton)
+ delete cancelButton;
+
+ if (radio)
+ delete radio;
+}
+
+int SelectPopup::getRadioValue()
+{
+ return radio->getValue();
+}
+
+void SelectPopup::onOkayButtonPressed()
+{
+ Popup::setStatus(Popup::Okay);
+}
+
+void SelectPopup::onCancelButtonPressed()
+{
+ Popup::setStatus(Popup::Canceled);
+}
+
+bool SelectPopup::createControl()
+{
+ okayButton = new Button(this);
+ okayButton->setText("OK");
+ okayButton->setStyle("bottom");
+ okayButton->clickEvent.connect(this, &SelectPopup::onOkayButtonPressed);
+ setContent("button1", okayButton);
+
+ cancelButton = new Button(this);
+ cancelButton->setText("CANCEL");
+ cancelButton->setStyle("bottom");
+ cancelButton->clickEvent.connect(this, &SelectPopup::onCancelButtonPressed);
+ setContent("button2", cancelButton);
+
+ return true;
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_SELECT_POPUP_H__
+#define __DPM_TOOLKIT_SELECT_POPUP_H__
+
+#include <string>
+
+#include "popup.h"
+#include "button.h"
+#include "radio.h"
+
+class SelectPopup : public Popup {
+public:
+ SelectPopup(Widget* parent, const std::string& title, const std::string radioText[], int nr);
+ virtual ~SelectPopup();
+ int getRadioValue();
+
+protected:
+ bool createControl();
+
+private:
+ void onOkayButtonPressed();
+ void onCancelButtonPressed();
+
+protected:
+ Button *okayButton;
+ Button *cancelButton;
+ Radio *radio;
+};
+
+#endif
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_SIGNAL_H__
+#define __DPM_TOOLKIT_SIGNAL_H__
+
+#include <unordered_map>
+#include <functional>
+#include "widget.h"
+
+template <typename... Args>
+class Signal {
+public:
+ Signal() : nextId_(0)
+ {
+ }
+
+ // copy creates new signal
+ Signal(Signal const& other) : nextId_(0)
+ {
+ }
+
+ // connects a member function to this Signal
+ template <typename T>
+ int connect(T *instance, void (T::*function)(Args...))
+ {
+ return insert([=](Args... args) { (instance->*function)(args...); });
+ }
+
+ // connects a const member function to this Signal
+ template <typename T>
+ int connect(T *instance, void (T::*function)(Args...) const)
+ {
+ return insert([=](Args... args) { (instance->*function)(args...); });
+ }
+
+ // connects a std::function to the signal. The returned
+ // value can be used to disconnect the function again
+ int insert(std::function<void(Args...)> const& slot)
+ {
+ int id = nextId_;
+ slots_.insert(std::make_pair(nextId_++, slot));
+ return id;
+ }
+
+ // disconnects a previously connected function
+ void disconnect(int id)
+ {
+ slots_.erase(id);
+ }
+
+ // disconnects all previously connected functions
+ void disconnectAll()
+ {
+ slots_.clear();
+ }
+
+ // calls all connected functions
+ void emit(Args... p)
+ {
+ for (auto it : slots_) {
+ it.second(p...);
+ }
+ }
+
+ // assignment creates new Signal
+ Signal& operator=(Signal const& other)
+ {
+ disconnectAll();
+ }
+
+private:
+ std::unordered_map<int, std::function<void(Args...)>> slots_;
+ int nextId_;
+};
+
+#endif
--- /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 "text-input-box.h"
+
+TextInputBox::TextInputBox(Widget *parent, const std::string& title, const std::string& msg, const std::string& guide) :
+ Popup(parent, title), okayButton(nullptr), cancelButton(nullptr), entry(nullptr)
+
+{
+ entry = new TextEntry(this);
+
+ if (msg.compare("") != 0)
+ entry->setEntryText(msg);
+ else if (guide.compare("") != 0)
+ entry->setGuideText(guide);
+ else
+ entry->setGuideText("Enter Value");
+}
+
+TextInputBox::~TextInputBox()
+{
+ if (okayButton)
+ delete okayButton;
+
+ if (cancelButton)
+ delete cancelButton;
+
+ if (entry)
+ delete entry;
+}
+
+std::string TextInputBox::getEntry()
+{
+ return entry->getEntryText();
+}
+
+void TextInputBox::onOkayButtonPressed()
+{
+ Popup::setStatus(Popup::Okay);
+}
+
+void TextInputBox::onCancelButtonPressed()
+{
+ Popup::setStatus(Popup::Canceled);
+}
+
+bool TextInputBox::createControl()
+{
+ okayButton = new Button(this);
+ okayButton->setText("OK");
+ okayButton->setStyle("bottom");
+ okayButton->clickEvent.connect(this, &TextInputBox::onOkayButtonPressed);
+ setContent("button1", okayButton);
+
+ cancelButton = new Button(this);
+ cancelButton->setText("CANCEL");
+ cancelButton->setStyle("bottom");
+ cancelButton->clickEvent.connect(this, &TextInputBox::onCancelButtonPressed);
+ setContent("button2", cancelButton);
+
+ return true;
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_TEXT_INPUT_BOX_H__
+#define __DPM_TOOLKIT_TEXT_INPUT_BOX_H__
+
+#include "popup.h"
+#include "button.h"
+#include "entry.h"
+
+class TextInputBox : public Popup {
+public:
+ TextInputBox(Widget *parent, const std::string& title, const std::string& msg, const std::string& guide);
+ virtual ~TextInputBox();
+ std::string getEntry();
+
+protected:
+ virtual bool createControl();
+
+private:
+ void onOkayButtonPressed();
+ void onCancelButtonPressed();
+
+protected:
+ Button* okayButton;
+ Button* cancelButton;
+ TextEntry* entry;
+};
+
+#endif
--- /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 "widget.h"
+
+Widget::Widget(const std::string& t, Evas_Object *obj)
+ : tag(t), object(obj), disposed(false)
+{
+ ::evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ ::evas_object_size_hint_align_set(object, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_SHOW,
+ dispatchShowHandler,
+ reinterpret_cast<void *>(this));
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_HIDE,
+ dispatchHideHandler,
+ reinterpret_cast<void *>(this));
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_FREE,
+ dispatchFreeHandler,
+ reinterpret_cast<void *>(this));
+}
+
+Widget::Widget(const std::string& t)
+ : tag(t), object(nullptr), disposed(false)
+{
+}
+
+Widget::~Widget()
+{
+ if (!disposed)
+ ::evas_object_del(object);
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "Widget(%s) destroyed", tag.c_str());
+}
+
+void Widget::setText(const std::string &text)
+{
+ ::elm_object_text_set(object, text.c_str());
+}
+
+void Widget::setText(const std::string &part, const std::string &text)
+{
+ ::elm_object_part_text_set(object, part.c_str(), text.c_str());
+}
+
+void Widget::setStyle(const std::string &style)
+{
+ ::elm_object_style_set(object, style.c_str());
+}
+
+void Widget::setContent(Widget* content)
+{
+ ::elm_object_content_set(object, content->object);
+}
+
+void Widget::setContent(const std::string &part, Widget* content)
+{
+ ::elm_object_part_content_set(object, part.c_str(), content->object);
+}
+
+void Widget::setFocus(bool enabled)
+{
+ ::elm_object_focus_set(object, enabled);
+}
+
+void Widget::show()
+{
+ ::evas_object_show(object);
+}
+
+void Widget::hide()
+{
+ ::evas_object_hide(object);
+}
+
+void Widget::dispose()
+{
+ // TODO: assertion
+ if (disposed)
+ return;
+
+ ::evas_object_del(object);
+ disposed = true;
+}
+
+void Widget::setObject(Evas_Object* obj)
+{
+ object = obj;
+ ::evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ ::evas_object_size_hint_align_set(object, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_SHOW,
+ dispatchShowHandler,
+ reinterpret_cast<void *>(this));
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_HIDE,
+ dispatchHideHandler,
+ reinterpret_cast<void *>(this));
+
+ ::evas_object_event_callback_add(evasObject(this),
+ EVAS_CALLBACK_FREE,
+ dispatchFreeHandler,
+ reinterpret_cast<void *>(this));
+}
+
+void Widget::dispatchShowHandler(void* data, Evas* e, Evas_Object* obj, void* event)
+{
+ Widget *self = reinterpret_cast<Widget *>(data);
+ self->onShow();
+}
+
+void Widget::dispatchHideHandler(void* data, Evas* e, Evas_Object* obj, void* event)
+{
+ Widget *self = reinterpret_cast<Widget *>(data);
+ self->onHide();
+}
+
+void Widget::dispatchFreeHandler(void* data, Evas* e, Evas_Object* obj, void* event)
+{
+ Widget *self = reinterpret_cast<Widget *>(data);
+ self->onFree();
+}
--- /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.
+ *
+ */
+
+#ifndef __DPM_TOOLKIT_WIDGET_H__
+#define __DPM_TOOLKIT_WIDGET_H__
+
+#include <app.h>
+#include <app_common.h>
+#include <bundle.h>
+#include <system_settings.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <app_control_internal.h>
+#include <efl_util.h>
+
+#include <string>
+
+#include "signal.h"
+
+class Widget {
+public:
+ virtual ~Widget();
+
+ void setText(const std::string& text);
+ void setText(const std::string& part, const std::string& text);
+ void setStyle(const std::string& style);
+ void setContent(Widget* content);
+ void setContent(const std::string& part, Widget* content);
+ void setFocus(bool enabled);
+ void show();
+ void hide();
+ void dispose();
+ void setObject(Evas_Object* obj);
+
+protected:
+ Widget(const std::string& t, Evas_Object *obj);
+ Widget(const std::string& t);
+
+ inline Evas_Object *evasObject(Widget *widget)
+ {
+ return widget ? widget->object : nullptr;
+ }
+
+ virtual void onShow()
+ {
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "%s::onShow", tag.c_str());
+ }
+
+ virtual void onHide()
+ {
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "%s::onHide", tag.c_str());
+ }
+
+ virtual void onFree()
+ {
+ ::dlog_print(DLOG_DEBUG, LOG_TAG, "%s::onFree", tag.c_str());
+ }
+
+private:
+ static void dispatchShowHandler(void* data, Evas* e, Evas_Object* obj, void* event);
+ static void dispatchHideHandler(void* data, Evas* e, Evas_Object* obj, void* event);
+ static void dispatchFreeHandler(void* data, Evas* e, Evas_Object* obj, void* event);
+
+private:
+ std::string tag;
+ Evas_Object *object;
+ bool disposed;
+};
+
+#endif /* __WIDGET_H__ */
--- /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 "window.h"
+
+Window::Window(const std::string& packageName) :
+ Widget("Window", ::elm_win_util_standard_add(packageName.c_str(), packageName.c_str()))
+{
+ ::elm_win_indicator_mode_set(evasObject(this), ELM_WIN_INDICATOR_SHOW);
+ ::elm_win_indicator_opacity_set(evasObject(this), ELM_WIN_INDICATOR_TRANSPARENT);
+ ::elm_win_conformant_set(evasObject(this), EINA_TRUE);
+ ::elm_win_autodel_set(evasObject(this), EINA_TRUE);
+
+ if (::elm_win_wm_rotation_supported_get(evasObject(this))) {
+ const int rots[4] = { 0, 90, 180, 270 };
+ ::elm_win_wm_rotation_available_rotations_set(evasObject(this), (const int *)&rots, 4);
+ }
+}
+
+Window::~Window()
+{
+}
--- /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.
+ *
+ */
+#ifndef __DPM_TOOLKIT_WINDOW_H__
+#define __DPM_TOOLKIT_WINDOW_H__
+
+#include "widget.h"
+
+class Window : public Widget {
+public:
+ Window(const std::string& packageName);
+ virtual ~Window();
+};
+
+#endif
+++ /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
- */
-
-#include <dpm/wifi.h>
-
-#include "dpm-toolkit.h"
-
-int wifi_set_profile_change_state_handler(struct xtk_policy* self)
-{
- int state, allow;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_set_profile_change_restriction(handle, allow) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_is_profile_change_restricted(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == allow) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int wifi_get_profile_change_state_handler(struct xtk_policy* self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_is_profile_change_restricted(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int wifi_set_network_access_restriction_handler(struct xtk_policy* self)
-{
- int state, enable;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_radio_popup(self, RESTRICTION_MODE_OPTIONS, &enable) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_set_network_access_restriction(handle, enable) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_is_network_access_restricted(handle, &state) != 0) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- }
-
- if (state == enable) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, RESTRICTION_MODE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int wifi_is_network_access_restricted_handler(struct xtk_policy* self)
-{
- int state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_is_network_access_restricted(handle, &state) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, RESTRICTION_MODE_MESSAGE(state));
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int wifi_add_ssid_to_blocklist_handler(struct xtk_policy* self)
-{
- char* entry = NULL;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_entry_popup(self, NULL, "SSID", &entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- return POLICY_RESULT_FAIL;
- };
-
- if (entry == NULL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get null string");
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_add_ssid_to_blocklist(handle, entry) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-int wifi_remove_ssid_from_blocklist_handler(struct xtk_policy* self)
-{
- char* entry = NULL;
- device_policy_manager_h handle = NULL;
-
- if (xtk_open_entry_popup(self, NULL, "SSID", &entry) == XTK_EVENT_CANCEL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get canceled");
- };
-
- if (entry == NULL) {
- dlog_print(DLOG_DEBUG, LOG_TAG, "Entry get null string");
- return POLICY_RESULT_FAIL;
- }
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- if (dpm_wifi_remove_ssid_from_blocklist(handle, entry) == 0) {
- dpm_manager_destroy(handle);
- xtk_open_message_popup(self, entry);
- return POLICY_RESULT_NONE;
- }
-
- dpm_manager_destroy(handle);
-
- return POLICY_RESULT_FAIL;
-}
-
-xtk_policy_t xtk_wifi_policy[] = {
- {
- .id = "WIFI_SET_PROFILE_CHANGE_STATE",
- .handler = wifi_set_profile_change_state_handler
- },
- {
- .id = "WIFI_GET_PROFILE_CHANGE_STATE",
- .handler = wifi_get_profile_change_state_handler
- },
- {
- .id = "WIFI_SET_NETWORK_ACCESS_RESTRICTION",
- .handler = wifi_set_network_access_restriction_handler
- },
- {
- .id = "WIFI_IS_NETWORK_ACCESS_RESTRICTED",
- .handler = wifi_is_network_access_restricted_handler
- },
- {
- .id = "WIFI_ADD_SSID_TO_BLOCKLIST",
- .handler = wifi_add_ssid_to_blocklist_handler
- },
- {
- .id = "WIFI_REMOVE_SSID_FROM_BLOCKLIST",
- .handler = wifi_remove_ssid_from_blocklist_handler
- },
-};
-
-xtk_policy_group_t wifi_policy_group = {
- .id = "WIFI"
-};
-
-void __CONSTRUCTOR__ xtk_wifi_policy_constructor()
-{
- int ret = 0;
-
- dlog_print(DLOG_ERROR, LOG_TAG, "wifi policy constructor");
-
- int nr = ARRAY_SIZE(xtk_wifi_policy);
- ret = xtk_init_policy(&wifi_policy_group, xtk_wifi_policy, nr);
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "wifi policy initialization fail");
- }
-}
+++ /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
- */
-
-#include <dpm/zone.h>
-
-#include "dpm-toolkit.h"
-
-int create_zone_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *wizappid = NULL;
- char *input_entry = NULL;
-
- wizappid = (char *)xmlGetProp(self->model, (xmlChar *) "wizappid");
- if (wizappid == NULL) {
- xtk_open_message_popup(self, "wizappid parameter not found");
- return POLICY_RESULT_FAIL;
- }
-
- if (xtk_open_entry_popup(self, NULL, "Zone name", &input_entry) == XTK_EVENT_CANCEL) {
- free(wizappid);
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device handle handle handle");
- free(wizappid);
- return POLICY_RESULT_FAIL;
- }
-
- int ret = dpm_zone_create(handle, input_entry, wizappid);
- dpm_manager_destroy(handle);
- free(wizappid);
-
- if (ret == DPM_ERROR_NONE) {
- return POLICY_RESULT_SUCCESS;
- }
-
- xtk_open_message_popup(self, "Failed to create the zone");
- return POLICY_RESULT_FAIL;
-}
-
-int destroy_zone_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle;
-
- char *input_entry = NULL;
- if (xtk_open_entry_popup(self, NULL, "Zone name", &input_entry) == XTK_EVENT_CANCEL) {
- return POLICY_RESULT_FAIL;
- };
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- int ret = dpm_zone_destroy(handle, input_entry);
- dpm_manager_destroy(handle);
-
- if (ret == DPM_ERROR_NONE) {
- return POLICY_RESULT_SUCCESS;
- }
-
- xtk_open_message_popup(self, "Failed to destroy the zone");
- return POLICY_RESULT_FAIL;
-}
-
-int get_zone_state_handler(struct xtk_policy *self)
-{
- dpm_zone_state_e state;
- const char *zone_state;
- device_policy_manager_h handle = NULL;
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- char *input_entry = NULL;
- if (xtk_open_entry_popup(self, NULL, "Zone name", &input_entry) == XTK_EVENT_CANCEL) {
- dpm_manager_destroy(handle);
- return POLICY_RESULT_FAIL;
- };
-
- int ret = dpm_zone_get_state(handle, input_entry, &state);
- dpm_manager_destroy(handle);
-
- switch (ret) {
- case DPM_ERROR_NONE:
- if (state & DPM_ZONE_STATE_RUNNING) {
- zone_state = "Running";
- } else if (state & DPM_ZONE_STATE_LOCKED) {
- zone_state = "Locked";
- } else {
- zone_state = "Undefined";
- }
-
- xtk_open_message_popup(self, zone_state);
- return POLICY_RESULT_NONE;
- case DPM_ERROR_NO_DATA:
- xtk_open_message_popup(self, "Not exists");
- return POLICY_RESULT_NONE;
- }
-
- xtk_open_message_popup(self, "Failed to get zone state");
- return POLICY_RESULT_NONE;
-}
-
-static int num_of_zone;
-static bool zone_list_cb(const char *name, void *user_data)
-{
- struct xtk_policy *self = (struct xtk_policy *)user_data;
- xtk_open_message_popup(self, name);
- num_of_zone++;
-
- return true;
-}
-
-int get_zone_list_handler(struct xtk_policy *self)
-{
- device_policy_manager_h handle = NULL;
- char string[256];
-
- handle = dpm_manager_create();
- if (handle == NULL) {
- xtk_open_message_popup(self, "Failed to create device handle handle handle");
- return POLICY_RESULT_FAIL;
- }
-
- num_of_zone = 0;
- int ret = dpm_zone_foreach_name(handle, DPM_ZONE_STATE_ALL, zone_list_cb, self);
- dpm_manager_destroy(handle);
-
- snprintf(string, sizeof(string), "%d zones are found", num_of_zone);
- xtk_open_message_popup(self, string);
-
- if (ret != DPM_ERROR_NONE) {
- xtk_open_message_popup(self, "Failed to get zone list");
- return POLICY_RESULT_FAIL;
- }
- return POLICY_RESULT_NONE;
-}
-
-xtk_policy_t xtk_zone_policy[] = {
- {
- .id = "CREATE_ZONE",
- .handler = create_zone_handler
- },
- {
- .id = "DESTROY_ZONE",
- .handler = destroy_zone_handler
- },
- {
- .id = "GET_ZONE_STATE",
- .handler = get_zone_state_handler
- },
- {
- .id = "GET_ZONE_LIST",
- .handler = get_zone_list_handler
- }
-};
-
-xtk_policy_group_t zone_policy_group = {
- .id = "ZONE"
-};
-
-void __CONSTRUCTOR__ xtk_zone_policy_constructor()
-{
- int ret = 0;
-
- dlog_print(DLOG_ERROR, LOG_TAG, "zone policy constructor");
-
- int nr = ARRAY_SIZE(xtk_zone_policy);
- ret = xtk_init_policy(&zone_policy_group, xtk_zone_policy, nr);
- if (ret < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "zone policy initialization fail");
- }
-}