Launch w-clock-viewer 52/113952/2 accepted/tizen/common/20170210.170245 accepted/tizen/mobile/20170210.083054 accepted/tizen/wearable/20170210.083113 submit/tizen/20170210.022139
authorjunkyu han <junkyu.han@samsung.com>
Thu, 9 Feb 2017 10:46:14 +0000 (19:46 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Thu, 9 Feb 2017 11:05:56 +0000 (20:05 +0900)
Change-Id: Ie22d0745f8c411ed5ec083e763fc81fca301b18a

src/wearable/clock_mgr.c

index 5485fdd..7bd9725 100644 (file)
@@ -25,6 +25,7 @@
 #include "process_mgr.h"
 
 #define PM_UNLOCK_TIMER_SEC 0.3
+#define W_CLOCK_VIEWER "org.tizen.w-clock-viewer"
 
 
 
@@ -35,6 +36,93 @@ static struct {
        .reserved_apps_list = NULL,
        .reserved_popup_app_id = NULL,
 };
+static int pid_of_w_clock_viewer = 0;
+
+
+
+static int _launch_app(char *pkgname, bundle *b)
+{
+       _D("Clock mgr launch app: %s", pkgname);
+       int result = AUL_R_OK;
+
+       result = aul_launch_app(pkgname, b);
+
+       if (result < 0) {
+               _E("Failed to launch [%s] result=[%d]", pkgname, result);
+       }
+
+       return result;
+}
+
+
+
+static void _check_ambient_state_and_launch(void)
+{
+       int ambient_mode = 0;
+
+       if (vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_mode) < 0) {
+               _E("Failed to get vconfkey: %s", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
+               ambient_mode = 0;
+       }
+
+       if (ambient_mode) {
+               pid_of_w_clock_viewer = _launch_app(W_CLOCK_VIEWER, NULL);
+       }
+}
+
+
+
+static int _w_clock_viewer_dead_cb(int pid, void *data)
+{
+       _D("W_CLOCK_VIEWER_DEAD_CB is called(pid : %d)", pid);
+
+       if (pid == pid_of_w_clock_viewer) {
+               _E("W_CLOCK_VIEWER(%d) is destoryed.", pid);
+               _check_ambient_state_and_launch();
+       }
+       return 0;
+}
+
+
+
+static void _ambient_mode_setting_changed_cb(keynode_t* node, void *data)
+{
+       int ambient_mode = 0;
+
+       ambient_mode = vconf_keynode_get_bool(node);
+       _D("ambient mode is changed to [%d]", ambient_mode);
+
+       if (ambient_mode) {
+               _D("Launch W_CLOCK_VIEWER");
+               pid_of_w_clock_viewer = _launch_app(W_CLOCK_VIEWER, NULL);
+       } else {
+               _D("Kill W_CLOCK_VIEWER[%d]", pid_of_w_clock_viewer);
+               if (pid_of_w_clock_viewer > 0) {
+                       aul_kill_pid(pid_of_w_clock_viewer);
+                       pid_of_w_clock_viewer = 0;
+               }
+       }
+}
+
+
+
+static void _ambient_mode_init(void)
+{
+       aul_listen_app_dead_signal(_w_clock_viewer_dead_cb, NULL);
+       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, _ambient_mode_setting_changed_cb, NULL) < 0) {
+               _E("Failed to add VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL changed callback", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
+       }
+       _check_ambient_state_and_launch();
+}
+
+
+
+static void _ambient_mode_fini(void)
+{
+       if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, _ambient_mode_setting_changed_cb) < 0) {
+               _E("Failed to ignore VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL changed callback", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
+       }
+}
 
 
 
@@ -45,10 +133,10 @@ static int _check_reserved_popup_status(void)
 
        val = status_passive_get()->starter_reserved_apps_status;
        tmp = val & 0x10;
-       if(tmp == 0x10){
-               if(aul_app_is_running(s_clock_mgr.reserved_popup_app_id) == 1){
+       if (tmp == 0x10) {
+               if (aul_app_is_running(s_clock_mgr.reserved_popup_app_id) == 1) {
                        return TRUE;
-               } else{
+               } else {
                        _E("%s is not running now.", s_clock_mgr.reserved_popup_app_id);
                        s_clock_mgr.reserved_popup_app_id = NULL;
                        val = val ^ 0x10;
@@ -70,7 +158,7 @@ static int _check_reserved_apps_status(void)
        val = status_passive_get()->starter_reserved_apps_status;
        _W("Current reserved apps status : %x", val);
 
-       if(val > 0){
+       if (val > 0) {
                return TRUE;
        }
 
@@ -79,7 +167,8 @@ static int _check_reserved_apps_status(void)
 
 
 
-static Eina_Bool _pm_unlock_timer_cb(void *data){
+static Eina_Bool _pm_unlock_timer_cb(void *data)
+{
        /* PM_SLEEP_MARGIN : If the current status is lcd off, deviced reset timer to 1 second. */
        display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
        return ECORE_CALLBACK_CANCEL;
@@ -108,7 +197,7 @@ static void _on_lcd_changed_receive(void *data, DBusMessage *msg)
                _D("lcd off source : %s", lcd_off_source);
                free(lcd_off_source);
 
-               if(_check_reserved_popup_status() > 0){
+               if (_check_reserved_popup_status() > 0) {
                        _W("reserved popup is on top. do nothing");
                        return;
                }
@@ -118,14 +207,14 @@ static void _on_lcd_changed_receive(void *data, DBusMessage *msg)
                        return;
                }
 
-               EINA_LIST_FOREACH(s_clock_mgr.reserved_apps_list, l, info){
-                       if(aul_app_is_running(info) == 1){
+               EINA_LIST_FOREACH(s_clock_mgr.reserved_apps_list, l, info) {
+                       if (aul_app_is_running(info) == 1) {
                                // STAY_CUR_STATE : State is not changed directly and phone stay current state until timeout expired.
                                display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
                                process_mgr_must_open(info, NULL, NULL);
                                ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, NULL);
                                break;
-                       } else{
+                       } else {
                                _W("%s is not running now", info);
                                s_clock_mgr.reserved_apps_list = eina_list_remove_list(s_clock_mgr.reserved_apps_list, l);
                                continue;
@@ -133,7 +222,7 @@ static void _on_lcd_changed_receive(void *data, DBusMessage *msg)
                }
 
                count = eina_list_count(s_clock_mgr.reserved_apps_list);
-               if(count == 0){
+               if (count == 0) {
                        _W("there is no reserved app.");
                        vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, 0);
                }
@@ -148,12 +237,14 @@ void clock_mgr_init(void)
        _W("clock_mgr_init");
 
        dbus_util_receive_lcd_status(_on_lcd_changed_receive, NULL);
+       _ambient_mode_init();
 }
 
 
 
 void clock_mgr_fini(void)
 {
+       _ambient_mode_fini();
 }