From 2bd6bb1cdd1a0564ac5f152315e690806b81fa3f Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Tue, 14 Jun 2016 17:24:20 +0900 Subject: [PATCH] Apply dpm policy Change-Id: Id2f6a6d96aa12b8e7606b072fa2fb779acd1f1bc Signed-off-by: Seonah Moon --- CMakeLists.txt | 2 +- include/mh_popup.h | 1 + packaging/ug-setting-mobileap-efl.spec | 5 ++- src/mh_popup.c | 40 ++++++++++++++++++++++ src/mh_view_main.c | 61 ++++++++++++++++++++++++++++++++++ ug-setting-mobileap-efl.xml | 1 + 6 files changed, 108 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 151f131..789b8cd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ ENDIF (TIZEN_FEATURE_DUALSIM_ENABLE) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -SET(dependents "elementary evas ui-gadget-1 capi-network-tethering capi-network-connection capi-network-wifi notification efl-extension") +SET(dependents "elementary evas ui-gadget-1 capi-network-tethering capi-network-connection capi-network-wifi notification aul bundle efl-extension dpm") SET(CMAKE_BUILD_TYPE "Release") diff --git a/include/mh_popup.h b/include/mh_popup.h index 36025ce..a576ec5 100644 --- a/include/mh_popup.h +++ b/include/mh_popup.h @@ -36,6 +36,7 @@ void _destroy_popup(mh_appdata_t *ad); void _teth_on(mh_appdata_t* ad); void _prepare_popup_type(int type); void _handle_mobile_data_onoff(mh_appdata_t *ad); +void _create_security_restriction_noti(tethering_type_e type); #ifdef __cplusplus } diff --git a/packaging/ug-setting-mobileap-efl.spec b/packaging/ug-setting-mobileap-efl.spec index 7da945a..7265fed 100755 --- a/packaging/ug-setting-mobileap-efl.spec +++ b/packaging/ug-setting-mobileap-efl.spec @@ -3,7 +3,7 @@ Name: ug-setting-mobileap-efl Summary: Tethering UI Gadget Library -Version: 1.0.139 +Version: 1.0.140 Release: 1 Group: App/Network License: Flora-1.1 @@ -23,7 +23,10 @@ BuildRequires: pkgconfig(capi-network-wifi) BuildRequires: pkgconfig(capi-network-tethering) BuildRequires: pkgconfig(capi-network-connection) BuildRequires: pkgconfig(notification) +BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(efl-extension) +BuildRequires: pkgconfig(dpm) BuildRequires: cmake BuildRequires: edje-bin BuildRequires: gettext-tools diff --git a/src/mh_popup.c b/src/mh_popup.c index c74ae96..cd4ed32 100755 --- a/src/mh_popup.c +++ b/src/mh_popup.c @@ -19,12 +19,17 @@ #include #include +#include +#include #include "mh_common_utility.h" #include "mobile_hotspot.h" #include "mh_popup.h" #include "mh_string.h" +#define MAX_BUF_SIZE (256u) +#define NETPOPUP "net.netpopup" + static mh_popup_type_e popup_type = MH_POPUP_NONE; static Evas_Object *popup_content = NULL; static char *popup_string = NULL; @@ -625,3 +630,38 @@ void _destroy_popup(mh_appdata_t *ad) return; } + +void _create_security_restriction_noti(tethering_type_e type) +{ + bundle *b = NULL; + char restricted_type[MAX_BUF_SIZE] = {0, }; + int ret; + + switch (type) { + case TETHERING_TYPE_WIFI: + g_strlcpy(restricted_type, "wifi tethering", MAX_BUF_SIZE - 1); + break; + case TETHERING_TYPE_USB: + g_strlcpy(restricted_type, "usb tethering", MAX_BUF_SIZE - 1); + break; + case TETHERING_TYPE_BT: + g_strlcpy(restricted_type, "bt tethering", MAX_BUF_SIZE - 1); + break; + default: + ERR("Invalid type.\n"); + return; + } + b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup"); + bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction"); + bundle_add(b, "_RESTRICTED_TYPE_", restricted_type); + + DBG("Launch security restriction alert network popup"); + ret = aul_launch_app(NETPOPUP, b); + if (ret < 0) + ERR("Fail to launch syspopup"); + + bundle_free(b); + return; +} diff --git a/src/mh_view_main.c b/src/mh_view_main.c index 6f2af60..0892e08 100755 --- a/src/mh_view_main.c +++ b/src/mh_view_main.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "mh_view_main.h" #include "mh_popup.h" @@ -573,11 +574,57 @@ void _update_main_view(mh_appdata_t *ad, tethering_type_e type) return; } +static int __is_allowed(tethering_type_e type) +{ + int state = 0; + dpm_context_h context = NULL; + dpm_restriction_policy_h policy = NULL; + + context = dpm_context_create(); + if (context == NULL) { + ERR("Failed to create dpm context!!"); + return 0; + } + + policy = dpm_context_acquire_restriction_policy(context); + if (policy == NULL) { + ERR("Failed to create policy handle"); + dpm_context_destroy(context); + return 0; + } + + switch(type) { + case TETHERING_TYPE_WIFI: + dpm_restriction_get_wifi_hotspot_state(policy, &state); + break; + case TETHERING_TYPE_USB: + dpm_restriction_get_usb_tethering_state(policy, &state); + break; + case TETHERING_TYPE_BT: + dpm_restriction_get_bluetooth_tethering_state(policy, &state); + break; + default: + break; + } + + dpm_context_release_restriction_policy(context, policy); + dpm_context_destroy(context); + + return state; +} + static void __wifi_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info) { __MOBILE_AP_FUNC_ENTER__; + if (!__is_allowed(TETHERING_TYPE_WIFI)) { + ERR("Wi-Fi tethering is restricted!!"); + elm_check_state_set(obj, EINA_FALSE); + _create_security_restriction_noti(TETHERING_TYPE_WIFI); + return; + } + if (data == NULL) { ERR("The param is NULL\n"); return; @@ -621,6 +668,13 @@ static void __bt_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info { __MOBILE_AP_FUNC_ENTER__; + if (!__is_allowed(TETHERING_TYPE_BT)) { + ERR("BT tethering is restricted!!"); + elm_check_state_set(obj, EINA_FALSE); + _create_security_restriction_noti(TETHERING_TYPE_BT); + return; + } + if (data == NULL) { ERR("The param is NULL\n"); return; @@ -669,6 +723,13 @@ static void __usb_onoff_changed_cb(void *data, Evas_Object *obj, void *event_inf { __MOBILE_AP_FUNC_ENTER__; + if (!__is_allowed(TETHERING_TYPE_USB)) { + ERR("USB tethering is restricted!!"); + elm_check_state_set(obj, EINA_FALSE); + _create_security_restriction_noti(TETHERING_TYPE_USB); + return; + } + if (data == NULL) { ERR("The param is NULL\n"); return; diff --git a/ug-setting-mobileap-efl.xml b/ug-setting-mobileap-efl.xml index a5a6724..a2b75ea 100644 --- a/ug-setting-mobileap-efl.xml +++ b/ug-setting-mobileap-efl.xml @@ -65,5 +65,6 @@ http://tizen.org/privilege/network.get http://tizen.org/privilege/network.set http://tizen.org/privilege/network.profile + http://tizen.org/privilege/appmanager.launch -- 2.7.4