From 2491faa94414d224000f1d13aaa26928b3d835b2 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Tue, 21 Jun 2016 16:05:32 +0900 Subject: [PATCH] Implement DPM restriction function on BT UI Change-Id: I37ee30341e9384453e7e5ad72a006a21f945f0c7 Signed-off-by: DoHyun Pyun --- CMakeLists.txt | 1 + include/bt-main-ug.h | 4 ++ include/bt-util.h | 7 +++ packaging/ug-bluetooth-efl.spec | 1 + src/libraries/bt-util.c | 135 ++++++++++++++++++++++++++++++++++++++++ src/ui/bt-main-ug.c | 2 + src/ui/bt-main-view.c | 12 ++++ 7 files changed, 162 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b331d1..b5de9e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ SET(PKG_MODULES efl-extension glib-2.0 gio-2.0 + dpm ) INCLUDE(FindPkgConfig) diff --git a/include/bt-main-ug.h b/include/bt-main-ug.h index 0b6ae0a..ec72f82 100644 --- a/include/bt-main-ug.h +++ b/include/bt-main-ug.h @@ -207,6 +207,10 @@ typedef struct { ************************ */ bt_profile_view_data *profile_vd; bt_confirm_req_t confirm_req; + + void *dpm_handle; + void *dpm_policy_handle; + int dpm_callback_id; } bt_ug_data; diff --git a/include/bt-util.h b/include/bt-util.h index 2255873..5906eda 100644 --- a/include/bt-util.h +++ b/include/bt-util.h @@ -103,6 +103,13 @@ gboolean _bt_util_is_space_str(const char *name_str); void _bt_util_max_len_reached_cb(void *data, Evas_Object *obj, void *event_info); +int _bt_util_create_dpm_context(void *ug_data); + +void _bt_util_destroy_dpm_context(void *ug_data); + +gboolean _bt_util_is_dpm_restricted(void *handle); + + #ifdef __cplusplus } #endif diff --git a/packaging/ug-bluetooth-efl.spec b/packaging/ug-bluetooth-efl.spec index 71a4829..885304b 100644 --- a/packaging/ug-bluetooth-efl.spec +++ b/packaging/ug-bluetooth-efl.spec @@ -38,6 +38,7 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(dpm) %description UI gadget about the bluetooth diff --git a/src/libraries/bt-util.c b/src/libraries/bt-util.c index 5bf54a2..eb74ab8 100644 --- a/src/libraries/bt-util.c +++ b/src/libraries/bt-util.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "bt-main-ug.h" #include "bt-util.h" @@ -637,3 +638,137 @@ int _bt_util_check_any_profile_connected(bt_dev_t *dev) done: return connected; } + +static void __bt_util_dpm_policy_changed_cb(const char *name, const char *value, void *user_data) +{ + FN_START; + + bt_ug_data *ugd = NULL; + + ret_if(user_data == NULL); + ret_if(name == NULL); + ret_if(value == NULL); + + ugd = (bt_ug_data *)user_data; + + BT_DBG("policy name: %s", name); + BT_DBG("policy value: %s", value); + + if (strcmp(name, "bluetooth") != 0) { + BT_ERR("Not bluetooth policy"); + return; + } + + if (!strcmp(value, "disallowed")) { + BT_DBG("BT policy is restricted"); + + if (ugd->onoff_item) + elm_object_item_disabled_set(ugd->onoff_item, EINA_TRUE); + + if (ugd->onoff_btn) + elm_object_disabled_set(ugd->onoff_btn, EINA_TRUE); + } else if (!strcmp(value, "allowed")) { + BT_DBG("BT policy is allowed"); + + if (ugd->onoff_item) + elm_object_item_disabled_set(ugd->onoff_item, EINA_FALSE); + + if (ugd->onoff_btn) + elm_object_disabled_set(ugd->onoff_btn, EINA_FALSE); + } else { + BT_ERR("Unknown string value"); + } + + FN_END; +} + +int _bt_util_create_dpm_context(void *ug_data) +{ + FN_START; + + int ret; + dpm_context_h handle = NULL; + dpm_restriction_policy_h policy_handle = NULL; + bt_ug_data *ugd = NULL; + + retv_if(ug_data == NULL, BT_UG_FAIL); + + ugd = (bt_ug_data *)ug_data; + + handle = dpm_context_create(); + + if (handle == NULL) { + BT_ERR("Fail to create dpm context"); + return BT_UG_FAIL; + } + + ret = dpm_context_add_policy_changed_cb(handle, "bluetooth", + __bt_util_dpm_policy_changed_cb, + (void *)ugd, &ugd->dpm_callback_id); + if (ret != DPM_ERROR_NONE) + BT_ERR("Fail to destroy dpm context [%d]", ret); + + ugd->dpm_handle = (void *)handle; + + policy_handle = dpm_context_acquire_restriction_policy(handle); + if (policy_handle == NULL) + BT_ERR("Fail to acquire restriction policy handle"); + + ugd->dpm_policy_handle = policy_handle; + + FN_END; + return BT_UG_ERROR_NONE; +} + +void _bt_util_destroy_dpm_context(void *ug_data) +{ + FN_START; + + int ret; + bt_ug_data *ugd = NULL; + + ret_if(ug_data == NULL); + + ugd = (bt_ug_data *)ug_data; + + ret = dpm_context_release_restriction_policy(ugd->dpm_handle, ugd->dpm_policy_handle); + if (ret != DPM_ERROR_NONE) + BT_ERR("Fail to release policy handle [%d]", ret); + + ret = dpm_context_remove_policy_changed_cb(ugd->dpm_handle, ugd->dpm_callback_id); + if (ret != DPM_ERROR_NONE) + BT_ERR("Fail to remove callback [%d]", ret); + + ret = dpm_context_destroy(ugd->dpm_handle); + if (ret != DPM_ERROR_NONE) + BT_ERR("Fail to destroy dpm context [%d]", ret); + + ugd->dpm_handle = NULL; + ugd->dpm_policy_handle = NULL; + ugd->dpm_callback_id = 0; + + FN_END; +} + +gboolean _bt_util_is_dpm_restricted(void *handle) +{ + FN_START; + + int ret; + int dpm_state = 1; + + retv_if(handle == NULL, FALSE); + + ret = dpm_restriction_get_bluetooth_mode_change_state((dpm_restriction_policy_h)handle, + &dpm_state); + if (ret != DPM_ERROR_NONE) { + BT_ERR("Fail to destroy dpm context [%d]", ret); + return FALSE; + } + + BT_DBG("BT dpm state: %d", dpm_state); + + FN_END; + return (dpm_state == 0) ? TRUE : FALSE; +} + diff --git a/src/ui/bt-main-ug.c b/src/ui/bt-main-ug.c index 168efb4..3eb3cff 100644 --- a/src/ui/bt-main-ug.c +++ b/src/ui/bt-main-ug.c @@ -879,6 +879,8 @@ static void __on_destroy(ui_gadget_h ug, app_control_h service, void *priv) if (err != BT_UG_ERROR_NONE) BT_ERR("_bt_ipc_unregister_popup_event_signal failed: %d", err); + _bt_util_destroy_dpm_context(ugd); + __bt_ug_release_memory(ugd); #ifndef __TIZEN_OPEN__ diff --git a/src/ui/bt-main-view.c b/src/ui/bt-main-view.c index 46a3a77..d5c5608 100644 --- a/src/ui/bt-main-view.c +++ b/src/ui/bt-main-view.c @@ -148,6 +148,10 @@ static Evas_Object *__bt_main_onoff_icon_get(void *data, Evas_Object *obj, ugd->onoff_btn = btn; } + + if (_bt_util_is_dpm_restricted(ugd->dpm_policy_handle) == TRUE) + elm_object_disabled_set(btn, EINA_TRUE); + evas_object_show(btn); } @@ -2385,6 +2389,9 @@ static Evas_Object *__bt_main_add_genlist_dialogue(Evas_Object *parent, ugd->onoff_item = git; + if (_bt_util_is_dpm_restricted(ugd->dpm_policy_handle) == TRUE) + elm_object_item_disabled_set(ugd->onoff_item, EINA_TRUE); + _bt_main_add_device_name_item(ugd, genlist); _bt_main_add_visible_item(ugd, genlist); @@ -4442,6 +4449,7 @@ void _bt_main_init_status(bt_ug_data *ugd, void *data) FN_START; app_control_h service = NULL; + int ret; int remain_time = 0; bool status = false; bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED; @@ -4466,6 +4474,10 @@ void _bt_main_init_status(bt_ug_data *ugd, void *data) if (bt_initialize() != BT_ERROR_NONE) BT_ERR("bt_initialize() failed"); + ret = _bt_util_create_dpm_context(ugd); + if (ret != BT_UG_ERROR_NONE) + BT_ERR("_bt_util_create_dpm_context failed: %d", ret); + if (bt_adapter_get_state(&bt_state) != BT_ERROR_NONE) BT_ERR("bt_adapter_get_state() failed"); -- 2.7.4