tizen_2.0_build
[apps/home/starter.git] / lock-mgr / src / lockd-process-mgr.c
index 0acccea..179fced 100755 (executable)
@@ -1,20 +1,17 @@
 /*
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved 
+ * Copyright 2012  Samsung Electronics Co., Ltd
  *
- * This file is part of <starter>
- * Written by <Seungtaek Chung> <seungtaek.chung@samsung.com>, <Mi-Ju Lee> <miju52.lee@samsung.com>, <Xi Zhichan> <zhichan.xi@samsung.com>
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * PROPRIETARY/CONFIDENTIAL
- *
- * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
- * You shall not disclose such Confidential Information and shall use it only in accordance
- * with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
- * SAMSUNG make no representations or warranties about the suitability of the software,
- * either express or implied, including but not limited to the implied warranties of merchantability,
- * fitness for a particular purpose, or non-infringement.
- * SAMSUNG shall not be liable for any damages suffered by licensee as a result of using,
- * modifying or distributing this software or its derivatives.
+ *  http://www.tizenopensource.org/license
  *
+ * 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.
  */
 
 #include <vconf.h>
 
 #include "lockd-debug.h"
 #include "lockd-process-mgr.h"
+#include "starter-vconf.h"
+
+#define LOCKD_DEFAULT_PKG_NAME "org.tizen.draglock"
+#define LOCKD_DEFAULT_LOCKSCREEN "org.tizen.draglock"
+#define RETRY_MAXCOUNT 30
+#define RELAUNCH_INTERVAL 100*1000
+
+static char *_lockd_process_mgr_get_pkgname(void)
+{
+       char *pkgname = NULL;
+
+       pkgname = vconf_get_str(VCONF_PRIVATE_LOCKSCREEN_PKGNAME);
+
+       LOCKD_DBG("pkg name is %s", pkgname);
+
+       if (pkgname == NULL) {
+               return LOCKD_DEFAULT_PKG_NAME;
+       }
 
-#define LOCKD_PHONE_LOCK_PKG_NAME "org.tizen.phone-lock"
+       return pkgname;
+}
 
-int lockd_process_mgr_start_phone_lock(void)
+int lockd_process_mgr_restart_lock(void)
 {
-       int pid = 0;
+       char *lock_app_path = NULL;
+       int pid;
        bundle *b = NULL;
 
+       lock_app_path = _lockd_process_mgr_get_pkgname();
+
        b = bundle_create();
 
-       bundle_add(b, "pwlock_type", "running_lock");
-       bundle_add(b, "window_type", "alpha");
+       bundle_add(b, "mode", "normal");
 
-       pid = aul_launch_app(LOCKD_PHONE_LOCK_PKG_NAME, b);
-       LOCKD_DBG("aul_launch_app(%s, b), pid = %d", LOCKD_PHONE_LOCK_PKG_NAME,
+       pid = aul_launch_app(lock_app_path, b);
+
+       LOCKD_DBG("Reset : aul_launch_app(%s, NULL), pid = %d", lock_app_path,
                  pid);
+
        if (b)
                bundle_free(b);
 
        return pid;
 }
 
-void lockd_process_mgr_terminate_phone_lock(int phone_lock_pid)
+int
+lockd_process_mgr_start_lock(void *data, int (*dead_cb) (int, void *))
 {
-       LOCKD_DBG("Terminate Phone Lock(pid : %d)", phone_lock_pid);
-       aul_terminate_pid(phone_lock_pid);
+       char *lock_app_path = NULL;
+       int pid;
+       bundle *b = NULL;
+
+       lock_app_path = _lockd_process_mgr_get_pkgname();
+
+       b = bundle_create();
+
+       bundle_add(b, "mode", "normal");
+
+       int i;
+       for (i=0; i<RETRY_MAXCOUNT; i++)
+       {
+               pid = aul_launch_app(lock_app_path, b);
+
+               LOCKD_DBG("aul_launch_app(%s, NULL), pid = %d", lock_app_path, pid);
+
+               if (pid == AUL_R_ECOMM) {
+                       LOCKD_DBG("Relaunch lock application [%d]times", i);
+                       usleep(RELAUNCH_INTERVAL);
+               } else if (pid == AUL_R_ERROR) {
+                       LOCKD_DBG("launch[%s] is failed, launch default lock screen", lock_app_path);
+                       pid = aul_launch_app(LOCKD_DEFAULT_LOCKSCREEN, b);
+                       if (pid >0) {
+                               aul_listen_app_dead_signal(dead_cb, data);
+                               if (b)
+                                       bundle_free(b);
+                               return pid;
+                       }
+               } else {
+                       /* set listen and dead signal */
+                       aul_listen_app_dead_signal(dead_cb, data);
+                       if (b)
+                               bundle_free(b);
+                       return pid;
+               }
+       }
+       LOCKD_DBG("Relaunch lock application failed..!!");
+       return pid;
+}
+
+void
+lockd_process_mgr_terminate_lock_app(int lock_app_pid, int state)
+{
+       LOCKD_DBG
+           ("lockd_process_mgr_terminate_lock_app,  state:%d\n",
+            state);
+
+       if (state == 1) {
+               if (lock_app_pid != 0) {
+                       LOCKD_DBG("Terminate Lock app(pid : %d)", lock_app_pid);
+                       aul_terminate_pid(lock_app_pid);
+               }
+       }
 }
 
 int lockd_process_mgr_check_lock(int pid)
 {
        char buf[128];
        LOCKD_DBG("%s, %d", __func__, __LINE__);
+
        if (aul_app_get_pkgname_bypid(pid, buf, sizeof(buf)) < 0) {
                LOCKD_DBG("no such pkg by pid %d\n", pid);
        } else {
-               LOCKD_DBG("lock screen pkgname = %s, pid = %d\n", buf, pid);
+               LOCKD_DBG("app pkgname = %s, pid = %d\n", buf, pid);
                if (aul_app_is_running(buf) == TRUE) {
                        LOCKD_DBG("%s [pid = %d] is running\n", buf, pid);
                        return TRUE;