added privacy-guard setting menu 58/73958/2 accepted/tizen/mobile/20160613.123323 submit/tizen/20160613.014313
authorKyoungyong Lee <bluevox@naver.com>
Fri, 10 Jun 2016 07:49:06 +0000 (16:49 +0900)
committerKyoungyong Lee <bluevox@naver.com>
Fri, 10 Jun 2016 07:54:28 +0000 (16:54 +0900)
Change-Id: If2be58e12f40e22610ba5e0ac4afbe7bd2b3d17d

packaging/org.tizen.privacy-setting.spec [changed mode: 0644->0755]
packaging/org.tizen.privacy-setting.xml [changed mode: 0644->0755]
ui/CMakeLists.txt [changed mode: 0644->0755]
ui/include/privacy_setting.h [changed mode: 0644->0755]
ui/include/privacy_view.h [changed mode: 0644->0755]
ui/src/privacy_guard_list_view.c [new file with mode: 0755]
ui/src/privacy_guard_package_list_view.c [new file with mode: 0755]
ui/src/privacy_menu_view.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index c81f7f5..643d1c2
@@ -27,6 +27,7 @@ BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(security-privilege-manager)
 BuildRequires: pkgconfig(security-manager)
 BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(privacy-guard-client)
 
 %description
 Privacy setting ui gadget
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 0e91bc9..e789739
@@ -1,7 +1,7 @@
 INCLUDE(FindPkgConfig)
 SET(pkg_name "org.tizen.privacy-setting")
 
-pkg_check_modules(${pkg_name} REQUIRED glib-2.0 ui-gadget-1 evas elementary edje eina efl-extension security-privilege-manager icu-i18n dlog security-manager pkgmgr-info)
+pkg_check_modules(${pkg_name} REQUIRED glib-2.0 ui-gadget-1 evas elementary edje eina efl-extension security-privilege-manager icu-i18n dlog security-manager pkgmgr-info privacy-guard-client)
 
 SET(SRCS
        ${CMAKE_SOURCE_DIR}/common/src/common_utils.c
@@ -9,6 +9,8 @@ SET(SRCS
        src/privacy_menu_view.c
        src/privacy_list_view.c
        src/privacy_package_list_view.c
+       src/privacy_guard_list_view.c
+       src/privacy_guard_package_list_view.c
 )
 
 FOREACH(flag ${${pkg_name}_CFLAGS})
old mode 100644 (file)
new mode 100755 (executable)
index c6d2a79..263ad50
@@ -22,6 +22,7 @@
 
 #ifndef __UI_PRIVACY_SETTING_H__
 #define __UI_PRIVACY_SETTING_H__
+
 #include <Elementary.h>
 #include <ui-gadget.h>
 #include <ui-gadget-module.h>
@@ -29,7 +30,7 @@
 #include <app.h>
 
 #define PRIVACY_MENU_SETTING "Privacy Setting"
-#define PRIVACY_MENU_GUARD "Privacy Guard"
+#define PRIVACY_MENU_GUARD_SETTING "Privacy Guard Setting"
 
 struct app_data_s {
        Evas_Object *parent_layout;
old mode 100644 (file)
new mode 100755 (executable)
index 8f229d9..9567a3b
@@ -44,8 +44,28 @@ typedef struct item_data {
        bool status;
 } item_data_s;
 
+typedef struct {
+       char* pkg_id;
+       int count;
+       int monitor_policy;
+} pg_data_s;
+
+typedef struct {
+       int index;
+       char *title;
+       uid_t user_id;
+       char *pkg_id;
+       char *privacy_id;
+       bool status;
+} pg_item_data_s;
+
 void create_privacy_package_list_view(struct app_data_s *ad, item_data_s *selected_id);
 
 void create_privacy_list_view(struct app_data_s *ad);
 
 void create_privacy_menu_view(struct app_data_s *ad);
+
+void create_privacy_guard_list_view(struct app_data_s *ad);
+
+void create_privacy_guard_package_list_view(struct app_data_s *ad);
+
diff --git a/ui/src/privacy_guard_list_view.c b/ui/src/privacy_guard_list_view.c
new file mode 100755 (executable)
index 0000000..5c6badb
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2016 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.
+ */
+/*
+ * @file       privacy_guard_list_view.c
+ * @author     Kyoungyong Lee (k.y.lee@samsung.com)
+ * @version    1.0
+ * @brief
+ */
+
+#include <efl_extension.h>
+#include "common_utils.h"
+#include "privacy_setting.h"
+#include "privacy_view.h"
+
+static char* gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+       item_data_s *id = data;
+       lreturn_if(!strcmp(part, "elm.text"), , strdup(id->title), "privacy = %s", id->title);
+       return "FAIL";
+}
+static void gl_del_cb(void *data, Evas_Object *obj)
+{
+       /* Unrealized callback can be called after this. */
+       /* Accessing item_data_s can be dangerous on unrealized callback. */
+       item_data_s *id = data;
+       free(id);
+}
+
+static void _privacy_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       /* Get selected privacy */
+       Elm_Object_Item *ei = event_info;
+       item_data_s *selected_id = elm_object_item_data_get(ei);
+       LOGD("%s is selected, index = %d", selected_id->title, selected_id->index);
+
+       /* Unhighlight selected item */
+       elm_genlist_item_selected_set(ei, EINA_FALSE);
+
+       struct app_data_s *ad = (struct app_data_s *)data;
+       return_if(ad == NULL, , , "ad is null");
+
+       ad->privacy = (char*)selected_id->title;
+
+       create_privacy_guard_package_list_view(ad);
+}
+
+/*Privacy List*/
+void create_privacy_guard_list_view(struct app_data_s *ad)
+{
+       Evas_Object *genlist = common_genlist_add(ad->nf);
+
+       evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+       Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
+       itc->item_style = "default";
+       itc->func.text_get = gl_text_get_cb;
+       itc->func.del = gl_del_cb;
+       Elm_Object_Item *it = NULL;
+       int i = 0;
+       for (i = 0; i < (int)g_list_length(ad->privacy_list); ++i) {
+               item_data_s *id = calloc(sizeof(item_data_s), 1);
+               id->index = i;
+               id->title = (char*)g_list_nth_data(ad->privacy_list, i);
+               it = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, _privacy_selected_cb, ad);
+               log_if(it == NULL, 1, "Error in elm_genlist_item_append");
+       }
+       elm_genlist_item_class_free(itc);
+       evas_object_show(genlist);
+
+       /* Change "Privacy Setting" to proper DID : use dgettext() */
+       Elm_Object_Item *nf_it = elm_naviframe_item_push(ad->nf, "Privacy Guard Setting", common_back_btn_add(ad), NULL, genlist, NULL);
+
+       elm_object_item_domain_text_translatable_set(nf_it, PACKAGE, EINA_TRUE);
+}
+
diff --git a/ui/src/privacy_guard_package_list_view.c b/ui/src/privacy_guard_package_list_view.c
new file mode 100755 (executable)
index 0000000..4a43233
--- /dev/null
@@ -0,0 +1,199 @@
+/**
+ * Copyright (c) 2016 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.
+ */
+/*
+ * @file       privacy_guard_package_list_view.c
+ * @author     Kyoungyong Lee (k.y.lee@samsung.com)
+ * @version    1.0
+ * @brief
+ */
+
+#include <efl_extension.h>
+#include <glib.h>
+#include <pkgmgr-info.h>
+#include <privacy_guard_client.h>
+#include "common_utils.h"
+#include "privacy_setting.h"
+#include "privacy_view.h"
+
+static GList* pg_data_list;
+
+static void _gl_del_cb(void *data, Evas_Object *obj)
+{
+       /* Unrealized callback can be called after this. */
+       /* Accessing item_data_s can be dangerous on unrealized callback. */
+       item_data_s *id = data;
+       free(id);
+}
+
+static void _privacy_package_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       Elm_Object_Item *ei = event_info;
+
+       /* Unhighlight selected item */
+       elm_genlist_item_selected_set(ei, EINA_FALSE);
+}
+static char* _gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+       item_data_s *id = data;
+       lreturn_if(!strcmp(part, "elm.text"), , strdup(id->title), "privacy-package item = %s", id->title);
+       return "FAIL";
+}
+
+static void _privacy_package_check_changed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       pg_item_data_s *id = (pg_item_data_s*)data;
+
+       LOGD("current policy: [%d]", id->status);
+
+       int res = privacy_guard_client_update_monitor_policy(id->user_id, id->pkg_id, id->privacy_id, !id->status);
+       log_if(res != PRIV_GUARD_ERROR_SUCCESS, 1, "privacy_guard_client_update_monitor_policy() is failed. [%d]", res);
+       id->status = !id->status;
+}
+
+static Evas_Object* _gl_content_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+       Evas_Object *check;
+       pg_item_data_s *id = (pg_item_data_s*)data;
+       Eina_Bool status = id->status;
+
+       if (strcmp(part, "elm.swallow.end"))
+               return NULL;
+
+       check = elm_check_add(obj);
+
+       elm_object_style_set(check, "on&off");
+       elm_check_state_set(check, status);
+       evas_object_repeat_events_set(check, EINA_FALSE);
+       evas_object_propagate_events_set(check, EINA_FALSE);
+       evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_smart_callback_add(check, "changed", _privacy_package_check_changed_cb, data);
+       evas_object_show(check);
+
+       return check;
+}
+
+static bool _privacy_package_info_cb(const char *package_id, const int count, const int monitor_policy, void *user_data)
+{
+       pg_data_s *data = (pg_data_s *)malloc(sizeof(pg_data_s));
+       data->pkg_id = strdup(package_id);
+       data->count = count;
+       data->monitor_policy = monitor_policy;
+
+       pg_data_list = g_list_append(pg_data_list, data);
+
+       GList *l;
+       for (l = pg_data_list; l != NULL; l = l->next) {
+               pg_data_s *item = (pg_data_s*)l->data;
+       }
+
+       return true;
+}
+
+void create_privacy_guard_package_list_view(struct app_data_s* ad)
+
+{
+       /* Add genlist */
+       Evas_Object *genlist = common_genlist_add(ad->nf);
+
+       evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+       /* Set itc */
+       Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
+       itc->item_style = "default";
+       itc->func.content_get = _gl_content_get_cb;
+       itc->func.text_get = _gl_text_get_cb;
+       itc->func.del = _gl_del_cb;
+
+       /* Get privacy guard data (pkg, count, policy) list by a privacy */
+       if (pg_data_list!= NULL) {
+               g_list_free(pg_data_list);
+               pg_data_list = NULL;
+       }
+
+       // user ID
+       uid_t user_id = getuid();
+
+       // get package_id, count, policy using a privacy
+       int res = privacy_guard_client_foreach_package_info_by_privacy_id(user_id, ad->privacy, _privacy_package_info_cb, NULL);
+       log_if(res != PRIV_GUARD_ERROR_SUCCESS, 1, "privacy_guard_client_foreach_package_info_by_privacy_id() is failed. [%d]", res);
+
+       /* Append privacy related package as genlist item */
+       GList* l;
+       int i = 0;
+       Elm_Object_Item *it = NULL;
+       for (l = pg_data_list; l != NULL; l = l->next) {
+               pg_data_s* data = (pg_data_s*)l->data;
+               pg_item_data_s *item = calloc(sizeof(pg_item_data_s), 1);
+               char temp[256] = {'\0',};
+               char *label = NULL;
+               pkgmgrinfo_pkginfo_h handle;
+
+               // index
+               item->index = i++;
+
+               // package ID
+               item->pkg_id = strdup(data->pkg_id);
+
+               // package label
+               res = pkgmgrinfo_pkginfo_get_pkginfo(item->pkg_id, &handle);
+               if (res != PMINFO_R_OK) {
+                       LOGE("Failed to operate pkgmgrinfo_pkginfo_get_pkginfo [%d]", res);
+                       LOGE("So replace the label to package ID");
+                       label = item->pkg_id;
+               } else {
+                       res = pkgmgrinfo_pkginfo_get_label(handle, &label);
+                       if (res != PMINFO_R_OK) {
+                               LOGE("Failed to operate pkgmgrinfo_pkginfo_get_label [%d]", res);
+                               LOGE("So replace the label to package ID");
+                               label = item->pkg_id;
+                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                       }
+               }
+
+               // title.. "label (count)" ==> privacyapp (0)
+               snprintf(temp, sizeof(temp), "%s (%d)", label, data->count);
+               item->title = strdup(temp);
+
+               // user ID
+               item->user_id = user_id;
+
+               // privacy ID
+               item->privacy_id = strdup(ad->privacy);
+
+               // status
+               item->status = ((data->monitor_policy == 1) ? EINA_TRUE : EINA_FALSE);
+
+               // append to the genlist
+               it = elm_genlist_item_append(genlist, itc, item, NULL, ELM_GENLIST_ITEM_NONE, _privacy_package_selected_cb, item);
+               log_if(it == NULL, 1, "Error in elm_genlist_item_append");
+
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       }
+
+       elm_genlist_item_class_free(itc);
+       evas_object_show(genlist);
+
+       /* TODO: change nf_it_title to proper DID : use dgettext() */
+       char nf_it_title[256];
+       snprintf(nf_it_title, sizeof(nf_it_title), "%s", ad->privacy);
+
+       /* Push naviframe item */
+       Elm_Object_Item *nf_it = elm_naviframe_item_push(ad->nf, nf_it_title, common_back_btn_add(ad), NULL, genlist, NULL);
+
+       elm_object_item_domain_text_translatable_set(nf_it, PACKAGE, EINA_TRUE);
+}
old mode 100644 (file)
new mode 100755 (executable)
index 94a74fd..e86e216
@@ -67,12 +67,13 @@ static void menu_selected_cb(void *data, Evas_Object *obj, void *event_info)
        struct app_data_s *ad = (struct app_data_s *)data;
        return_if(ad == NULL, , , "ad is null");
 
+       int ret = privilege_info_get_privacy_list(&(ad->privacy_list));
+       log_if(ret != PRVMGR_ERR_NONE, 1, "Failed to get privacy_list");
+
        if (strstr(selected_id->title, PRIVACY_MENU_SETTING) != NULL) {
-               int ret = privilege_info_get_privacy_list(&(ad->privacy_list));
-               log_if(ret != PRVMGR_ERR_NONE, 1, "Failed to get privacy_list");
                create_privacy_list_view(ad);
-       } else if (strstr(selected_id->title, PRIVACY_MENU_GUARD) != NULL) {/* privacy guard */
-               /* TBD: Call privacy guard view */
+       } else if (strstr(selected_id->title, PRIVACY_MENU_GUARD_SETTING) != NULL) {/* privacy guard */
+               create_privacy_guard_list_view(ad);
        } else {
                LOGE("selected_id->title = %s, no matching menu", selected_id->title);
        }
@@ -89,7 +90,7 @@ void create_privacy_menu_view(struct app_data_s *ad)
        /* Set privacy menu list */
        privacy_menu_list = NULL;
        privacy_menu_list = g_list_append(privacy_menu_list, PRIVACY_MENU_SETTING);
-       privacy_menu_list = g_list_append(privacy_menu_list, PRIVACY_MENU_GUARD);
+       privacy_menu_list = g_list_append(privacy_menu_list, PRIVACY_MENU_GUARD_SETTING);
 
        Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
        itc->item_style = "default";