From b30e331bf97057cb9907503e1aafc7159d09f967 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Thu, 30 Jun 2016 16:12:05 +0900 Subject: [PATCH] Apply keyguard on the zone Change-Id: I4a2eea507730d79362f04bfe65229ad913d8664e Signed-off-by: Sungbae Yoo --- packaging/device-policy-manager.spec | 4 +- server/zone/zone.cpp | 4 +- zone/apps/keyguard/CMakeLists.txt | 2 + zone/apps/keyguard/include/keyguard.h | 11 ++ zone/apps/keyguard/org.tizen.keyguard.xml | 4 + zone/apps/keyguard/src/main.c | 124 ++++++++++++++++++++- zone/apps/keyguard/src/ui.c | 12 +- zone/apps/keyguard/src/widget.c | 5 +- zone/apps/setup-wizard/CMakeLists.txt | 1 - zone/apps/setup-wizard/include/zone-setup.h | 2 +- .../setup-wizard/org.tizen.zone-setup-wizard.xml | 1 - zone/apps/setup-wizard/src/main.c | 57 ++-------- zone/apps/setup-wizard/src/widget.c | 17 +-- 13 files changed, 171 insertions(+), 73 deletions(-) diff --git a/packaging/device-policy-manager.spec b/packaging/device-policy-manager.spec index c786c21..ee86a95 100755 --- a/packaging/device-policy-manager.spec +++ b/packaging/device-policy-manager.spec @@ -213,7 +213,6 @@ BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(evas) BuildRequires: pkgconfig(notification) -BuildRequires: pkgconfig(shortcut) Requires: libzone = %{version}-%{release} %description -n org.tizen.zone-setup-wizard @@ -263,6 +262,8 @@ BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(evas) BuildRequires: pkgconfig(capi-ui-efl-util) +BuildRequires: pkgconfig(auth-fw) +BuildRequires: pkgconfig(shortcut) %description -n org.tizen.keyguard Tizen Krate keyguard interface for zone @@ -282,7 +283,6 @@ Summary: Tizen Zone Client library Group: Development/Libraries BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-package-manager) -BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(libtzplatform-config) Requires: %{name} = %{version}-%{release} Requires(post): /sbin/ldconfig diff --git a/server/zone/zone.cpp b/server/zone/zone.cpp index e9f766d..e161d1a 100644 --- a/server/zone/zone.cpp +++ b/server/zone/zone.cpp @@ -42,7 +42,7 @@ #define DEFAULT_SHELL "/bin/bash" -#define ZONE_DELEGATOR_APP "org.tizen.zone-setup-wizard" +#define ZONE_DELEGATOR_APP "org.tizen.keyguard" #define NOTIFICATION_SUB_ICON_PATH DATA_PATH "/zone_noti_list_sub_icon.png" namespace DevicePolicyManager { @@ -397,7 +397,7 @@ void notiProxyInsert(const runtime::User& owner, const runtime::User& user, int appId = strdup(""); } - zoneLauncherUri = "zone://" + user.getName() + "/" + appId; + zoneLauncherUri = "zone://enter/" + user.getName() + "/" + appId; app_control_get_uri(appControl, &uri); if (uri != NULL) { diff --git a/zone/apps/keyguard/CMakeLists.txt b/zone/apps/keyguard/CMakeLists.txt index 23ea4ae..bade657 100644 --- a/zone/apps/keyguard/CMakeLists.txt +++ b/zone/apps/keyguard/CMakeLists.txt @@ -13,6 +13,8 @@ PKG_CHECK_MODULES(keyguard_pkgs REQUIRED capi-appfw-application capi-ui-efl-util evas + auth-fw + shortcut ) INCLUDE_DIRECTORIES(${keyguard_pkgs_INCLUDE_DIRS} ${ZONE_LIBS}) diff --git a/zone/apps/keyguard/include/keyguard.h b/zone/apps/keyguard/include/keyguard.h index 2898138..2ff94be 100644 --- a/zone/apps/keyguard/include/keyguard.h +++ b/zone/apps/keyguard/include/keyguard.h @@ -29,7 +29,10 @@ #include #include #include +#include +#include #include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -40,6 +43,14 @@ #define PACKAGE "org.tizen.keyguard" #endif +#define KEYGUARD_PACKAGE "org.tizen.keyguard" +#define KASKIT_PACKAGE "org.tizen.kaskit" + void _create_keyguard_window(void); +void _launch_req_app(void); + +bool _has_password(void); +bool _check_password(const char* password); +unsigned int _get_left_attempts(void); #endif /* __ZONE_KEYGUARD_H__ */ diff --git a/zone/apps/keyguard/org.tizen.keyguard.xml b/zone/apps/keyguard/org.tizen.keyguard.xml index 006359f..45ab3f8 100644 --- a/zone/apps/keyguard/org.tizen.keyguard.xml +++ b/zone/apps/keyguard/org.tizen.keyguard.xml @@ -1,6 +1,10 @@ + + http://tizen.org/privilege/shortcut + http://tizen.org/privilege/appmanager.launch + diff --git a/zone/apps/keyguard/src/main.c b/zone/apps/keyguard/src/main.c index 835cafa..0fcc24f 100644 --- a/zone/apps/keyguard/src/main.c +++ b/zone/apps/keyguard/src/main.c @@ -19,10 +19,51 @@ #include "keyguard.h" #include "widget.h" +static app_control_h __req_app_control; + +void _launch_req_app() +{ + app_control_send_launch_request(__req_app_control, NULL, NULL); + app_control_destroy(__req_app_control); +} + +bool _check_password(const char* password) +{ + return true; +} + +bool _has_password() +{ + return true; +} + +unsigned int _get_left_attempts() +{ + return 10; +} + +static void __launch_zone_app(const char* zone_name, app_control_h app_control) +{ + zone_manager_h zone_mgr; + zone_app_proxy_h zone_app; + + zone_manager_create(&zone_mgr); + zone_app_proxy_create(zone_mgr, zone_name, &zone_app); + zone_app_proxy_send_launch_request(zone_app, app_control); + zone_app_proxy_destroy(zone_app); + zone_manager_destroy(zone_mgr); +} + +static void __add_shortcut(const char* zone_name) +{ + char uri[PATH_MAX]; + + snprintf(uri, sizeof(uri), "zone://enter/%s", zone_name); + shortcut_add_to_home(zone_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL); +} + static bool __app_create(void *data) { - elm_app_base_scale_set(1.8); - _create_keyguard_window(); return true; } @@ -43,7 +84,84 @@ static void __app_terminate(void *data) static void __app_control(app_control_h app_control, void *data) { - return; + char* uri, *tmp; + int ret = 0; + + ret = app_control_get_uri(app_control, &uri); + if (ret != APP_CONTROL_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get URI"); + ui_app_exit(); + return; + } + + if (strncmp(uri, "zone://", sizeof("zone://") - 1) != 0) { + dlog_print(DLOG_ERROR, LOG_TAG, "Mismatched URI"); + free(uri); + ui_app_exit(); + return; + } + + tmp = uri + sizeof("zone://") - 1; + + if (strncmp(tmp, "setup/", sizeof("setup/") - 1) == 0) { + char *zone_name; + + zone_name = tmp + sizeof("setup/") - 1; + __add_shortcut(zone_name); + ui_app_exit(); + return; + } else if (strncmp(tmp, "enter/", sizeof("enter/") - 1) == 0) { + char* zone_name, *launch_parameter; + char new_uri[PATH_MAX]; + + zone_name = tmp + sizeof("enter/") - 1; + launch_parameter = strchr(zone_name, '/'); + if (launch_parameter != NULL) { + *(launch_parameter++) = '\0'; + if (launch_parameter[0] == '\0') { + launch_parameter = KASKIT_PACKAGE; + } + } else { + launch_parameter = KASKIT_PACKAGE; + } + snprintf(new_uri, PATH_MAX, "zone://launch/%s", launch_parameter); + app_control_set_uri(app_control, new_uri); + app_control_set_app_id(app_control, PACKAGE); + + dlog_print(DLOG_ERROR, LOG_TAG, "Wow"); + dlog_print(DLOG_ERROR, LOG_TAG, PACKAGE); + dlog_print(DLOG_ERROR, LOG_TAG, new_uri); + dlog_print(DLOG_ERROR, LOG_TAG, zone_name); + + __launch_zone_app(zone_name, app_control); + ui_app_exit(); + return; + }else if (strncmp(tmp, "launch/", sizeof("launch/") - 1) == 0) { + char* app_id; + + app_id = tmp + sizeof("launch/") - 1; + uri = strchr(app_id, '?'); + if (uri != NULL) { + *(uri++) = '\0'; + if (strncmp(uri, "uri=", sizeof("uri=") - 1) == 0) { + tmp += sizeof("uri=") - 1; + } + } + app_control_clone(&__req_app_control, app_control); + app_control_set_uri(__req_app_control, uri); + app_control_set_app_id(__req_app_control, app_id); + + if (_has_password()) { + _create_keyguard_window(); + } else { + _launch_req_app(); + } + return; + } else { + dlog_print(DLOG_ERROR, LOG_TAG, "Invalid URI"); + ui_app_exit(); + } + free(uri); } int main(int argc, char *argv[]) diff --git a/zone/apps/keyguard/src/ui.c b/zone/apps/keyguard/src/ui.c index 18abd76..65ea827 100644 --- a/zone/apps/keyguard/src/ui.c +++ b/zone/apps/keyguard/src/ui.c @@ -34,10 +34,9 @@ static void __change_info_text(const char *text) static void __entry_change_cb(void *data, Evas_Object *obj, void *event_info) { - char text[PATH_MAX]; - int left_attempts = 10; /* [TBD] get left attempts number */ + char text[32]; - snprintf(text, PATH_MAX, "%d attempts left", left_attempts); + snprintf(text, 32, "%u attempts left", _get_left_attempts()); __change_info_text(text); } @@ -54,14 +53,17 @@ static void __checkbox_change_cb(void *data, Evas_Object *obj, void *event_info) static void __entry_activate_cb(void *data, Evas_Object *obj, void *event_info) { - char password[10] = "asdf"; /* [TBD] get krate password from dpm */ const char *input = elm_object_text_get(obj); - if (!strcmp(password, input)) { + if (_check_password(input)) { + _launch_req_app(); ui_app_exit(); } else { elm_entry_input_panel_hide(obj); __change_info_text("Incorrect Password. Try again."); + if (_get_left_attempts() == 0) { + ui_app_exit(); + } } } diff --git a/zone/apps/keyguard/src/widget.c b/zone/apps/keyguard/src/widget.c index d3d0d0b..8d6c682 100644 --- a/zone/apps/keyguard/src/widget.c +++ b/zone/apps/keyguard/src/widget.c @@ -26,7 +26,10 @@ static void __win_delete_request_cb(void *data , Evas_Object *obj , void *event_ Evas_Object *_create_win(const char *package) { - Evas_Object *win = elm_win_add(NULL, package, ELM_WIN_NOTIFICATION); + Evas_Object *win; + elm_app_base_scale_set(1.8); + + win = elm_win_add(NULL, package, ELM_WIN_NOTIFICATION); efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT); /* [TBD] enable : eext_win_keygrab_set(win, "XF86Home"); */ diff --git a/zone/apps/setup-wizard/CMakeLists.txt b/zone/apps/setup-wizard/CMakeLists.txt index 356fc0e..fce58a3 100644 --- a/zone/apps/setup-wizard/CMakeLists.txt +++ b/zone/apps/setup-wizard/CMakeLists.txt @@ -13,7 +13,6 @@ PKG_CHECK_MODULES(setup_pkgs REQUIRED capi-appfw-application evas notification - shortcut ) INCLUDE_DIRECTORIES(${setup_pkgs_INCLUDE_DIRS} ${ZONE_LIBS}) diff --git a/zone/apps/setup-wizard/include/zone-setup.h b/zone/apps/setup-wizard/include/zone-setup.h index 076142e..4dbf954 100644 --- a/zone/apps/setup-wizard/include/zone-setup.h +++ b/zone/apps/setup-wizard/include/zone-setup.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -44,6 +43,7 @@ #define PACKAGE "org.tizen.zone-setup-wizard" #endif +#define KEYGUARD_PACKAGE "org.tizen.keyguard" #define KASKIT_PACKAGE "org.tizen.kaskit" #define DPM_SYSPOPUP_ICON_PATH "/usr/share/icons/default/small/org.tizen.dpm-syspopup.png" diff --git a/zone/apps/setup-wizard/org.tizen.zone-setup-wizard.xml b/zone/apps/setup-wizard/org.tizen.zone-setup-wizard.xml index 78c0880..3f83b68 100644 --- a/zone/apps/setup-wizard/org.tizen.zone-setup-wizard.xml +++ b/zone/apps/setup-wizard/org.tizen.zone-setup-wizard.xml @@ -3,7 +3,6 @@ http://tizen.org/privilege/notification - http://tizen.org/privilege/shortcut http://tizen.org/privilege/appmanager.launch diff --git a/zone/apps/setup-wizard/src/main.c b/zone/apps/setup-wizard/src/main.c index 82ddac6..4773a30 100644 --- a/zone/apps/setup-wizard/src/main.c +++ b/zone/apps/setup-wizard/src/main.c @@ -34,19 +34,22 @@ static void __zone_request_done(const char *from, const char *info, void *user_d char uri[PATH_MAX]; appdata_s *ad = (appdata_s *) user_data; - ad->request_done = true; if (!strcmp(ad->mode, "create")) { - snprintf(uri, sizeof(uri), "zone://%s/" KASKIT_PACKAGE, ad->zone_name); - shortcut_add_to_home(ad->zone_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL); + app_control_create(&app_control); + app_control_set_app_id(app_control, KEYGUARD_PACKAGE); + snprintf(uri, sizeof(uri), "zone://setup/%s", ad->zone_name); + app_control_set_uri(app_control, uri); + app_control_send_launch_request(app_control, NULL, NULL); + app_control_destroy(app_control); app_control_create(&app_control); app_control_set_app_id(app_control, KASKIT_PACKAGE); __launch_zone_app(ad->zone_manager, ad->zone_name, app_control); app_control_destroy(app_control); - } + ad->request_done = true; } static bool __app_create(void *data) @@ -106,56 +109,11 @@ static void __set_zone_callback(appdata_s *ad) return; } -static int __parse_uri(app_control_h app_control, appdata_s *ad) -{ - char* uri, *zone_uri, *app_id, *zone_name; - int ret = 0; - - ret = app_control_get_uri(app_control, &uri); - if (ret != APP_CONTROL_ERROR_NONE || uri == NULL) { - dlog_print(DLOG_DEBUG, LOG_TAG, "No URI"); - return -1; - } - - if (strncmp(uri, "zone://", sizeof("zone://") - 1) != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Mismatched URI"); - free(uri); - return -1; - } - - zone_name = uri + sizeof("zone://") - 1; - - app_control_set_uri(app_control, NULL); - app_id = strchr(zone_name, '/'); - *(app_id++) = '\0'; - zone_uri = strchr(app_id, '?'); - if (zone_uri != NULL) { - *(zone_uri++) = '\0'; - if (strncmp(uri, "uri=", sizeof("uri=") - 1) == 0) { - zone_uri += sizeof("uri=") - 1; - app_control_set_uri(app_control, zone_uri); - } - } - - app_control_set_app_id(app_control, app_id); - __launch_zone_app(ad->zone_manager, zone_name, app_control); - - free(uri); - - return 0; -} - static void __app_control(app_control_h app_control, void *data) { appdata_s *ad = (appdata_s *) data; int ret = 0; - ret = __parse_uri(app_control, ad); - if (ret == 0) { - ui_app_exit(); - return; - } - ret = app_control_get_extra_data(app_control, "mode", &ad->mode); if (ret != APP_CONTROL_ERROR_NONE) { dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get mode"); @@ -184,7 +142,6 @@ static void __app_control(app_control_h app_control, void *data) return; } - elm_app_base_scale_set(1.8); _create_base_window(ad); return; diff --git a/zone/apps/setup-wizard/src/widget.c b/zone/apps/setup-wizard/src/widget.c index 2bc64c0..75b8ee9 100644 --- a/zone/apps/setup-wizard/src/widget.c +++ b/zone/apps/setup-wizard/src/widget.c @@ -26,15 +26,18 @@ static void __win_delete_request_cb(void *data , Evas_Object *obj , void *event_ Evas_Object *_create_win(const char *package) { - Evas_Object *win = elm_win_util_standard_add(package, package); - elm_win_conformant_set(win, EINA_TRUE); - elm_win_autodel_set(win, EINA_TRUE); + Evas_Object *win; - evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL); - elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW); - elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSPARENT); + elm_app_base_scale_set(1.8); - return win; + win = elm_win_util_standard_add(package, package); + elm_win_conformant_set(win, EINA_TRUE); + elm_win_autodel_set(win, EINA_TRUE); + elm_win_alpha_set(win, EINA_TRUE); + + evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL); + + return win; } Evas_Object *_create_conformant(Evas_Object *parent) -- 2.7.4