Implement DPM restriction function on BT UI 28/75728/2 accepted/tizen/common/20160621.184621 accepted/tizen/ivi/20160622.021657 accepted/tizen/mobile/20160622.021610 accepted/tizen/tv/20160622.021623 accepted/tizen/wearable/20160622.021641 submit/tizen/20160621.071537
authorDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 21 Jun 2016 07:05:32 +0000 (16:05 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 21 Jun 2016 07:08:53 +0000 (16:08 +0900)
Change-Id: I37ee30341e9384453e7e5ad72a006a21f945f0c7
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
CMakeLists.txt
include/bt-main-ug.h
include/bt-util.h
packaging/ug-bluetooth-efl.spec
src/libraries/bt-util.c
src/ui/bt-main-ug.c
src/ui/bt-main-view.c

index 6b331d1..b5de9e5 100644 (file)
@@ -49,6 +49,7 @@ SET(PKG_MODULES
        efl-extension
        glib-2.0
        gio-2.0
+       dpm
 )
 
 INCLUDE(FindPkgConfig)
index 0b6ae0a..ec72f82 100644 (file)
@@ -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;
 
 
index 2255873..5906eda 100644 (file)
@@ -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
index 71a4829..885304b 100644 (file)
@@ -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
index 5bf54a2..eb74ab8 100644 (file)
@@ -25,6 +25,7 @@
 #include <vconf.h>
 #include <aul.h>
 #include <notification.h>
+#include <dpm/restriction.h>
 
 #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;
+}
+
index 168efb4..3eb3cff 100644 (file)
@@ -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__
index 46a3a77..d5c5608 100644 (file)
@@ -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");