2 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * This file is part of <phone-lock>
5 * Written by <Seungtaek Chung> <seungtaek.chung@samsung.com>, <Mi-Ju Lee> <miju52.lee@samsung.com>, <Xi Zhichan> <zhichan.xi@samsung.com>
7 * PROPRIETARY/CONFIDENTIAL
9 * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
10 * You shall not disclose such Confidential Information and shall use it only in accordance
11 * with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
12 * SAMSUNG make no representations or warranties about the suitability of the software,
13 * either express or implied, including but not limited to the implied warranties of merchantability,
14 * fitness for a particular purpose, or non-infringement.
15 * SAMSUNG shall not be liable for any damages suffered by licensee as a result of using,
16 * modifying or distributing this software or its derivatives.
22 #include <appcore-common.h>
24 #include <Elementary.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
32 #include "phone-lock-util.h"
35 #define MAXFILELEN 1048576
36 #define PHONE_LOCK_SOCK_PREFIX "/tmp/phlock"
37 #define PHONE_LOCK_SOCK_MAXBUFF 65535
39 static void _phone_lock_win_del(void *data, Evas_Object * obj, void *event)
44 inline static void _phone_lock_set_sock_option(int fd, int cli)
47 struct timeval tv = { 1, 200 * 1000 };
49 size = PHONE_LOCK_SOCK_MAXBUFF;
50 setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
51 setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
53 setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
56 static int _phone_lock_create_sock(void)
58 struct sockaddr_un saddr;
62 _DBG("func=%s", __func__);
64 fd = socket(AF_UNIX, SOCK_STREAM, 0);
66 _DBG("errno=%s", errno);
67 if (errno == EINVAL) {
68 fd = socket(AF_UNIX, SOCK_STREAM, 0);
70 _DBG("second chance - socket create error");
79 bzero(&saddr, sizeof(saddr));
80 saddr.sun_family = AF_UNIX;
82 strncpy(saddr.sun_path, PHONE_LOCK_SOCK_PREFIX,
83 strlen(PHONE_LOCK_SOCK_PREFIX));
84 saddr.sun_path[strlen(PHONE_LOCK_SOCK_PREFIX)] = 0;
86 _DBG("saddr.sun_path = %s", saddr.sun_path);
89 if (connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
90 _DBG("maybe peer not launched or peer daed\n");
99 _phone_lock_set_sock_option(fd, 1);
104 void phone_lock_log_t(char *fmt, ...)
108 char buf[LINEMAX] = { 0, };
109 char debugString[LINEMAX] = { 0, };
112 vsnprintf(buf, sizeof(buf), fmt, ap);
116 time_t current_time = 0;
117 bzero((char *)&debugString, LINEMAX);
119 gmtime_r(¤t_time, &local_t);
120 int len = snprintf(debugString, sizeof(debugString),
121 "[%d-%02d-%02d, %02d:%02d:%02d]: ",
122 local_t.tm_year + 1900, local_t.tm_mon + 1,
123 local_t.tm_mday, local_t.tm_hour, local_t.tm_min,
128 debugString[len] = '\0';
130 len = g_strlcat(debugString, buf, LINEMAX);
131 if (len >= LINEMAX) {
134 debugString[len] = '\n';
136 if ((fd = fopen(LOGFILE, "at+")) == NULL) {
138 ("File fopen fail for writing Pwlock information");
141 if (fwrite(debugString, strlen(debugString), 1, fd) < 1) {
143 ("File fwrite fail for writing Pwlock information");
145 if ((pid = fork()) < 0) {
146 } else if (pid == 0) {
147 execl("/bin/rm", "rm", "-f", LOGFILE,
151 fseek(fd, 0l, SEEK_END);
153 if (fileLen > MAXFILELEN) {
155 if ((pid = fork()) < 0) {
157 } else if (pid == 0) {
158 execl("/bin/rm", "rm", "-f", LOGFILE,
167 Evas_Object *phone_lock_create_win(const char *name)
172 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
174 elm_win_title_set(eo, name);
175 elm_win_borderless_set(eo, EINA_TRUE);
176 evas_object_smart_callback_add(eo, "delete,request",
177 _phone_lock_win_del, NULL);
178 ecore_x_window_size_get(ecore_x_window_root_first_get(),
180 evas_object_resize(eo, w, h);
186 int phone_lock_send_cmd(const char *cmd)
192 fd = _phone_lock_create_sock();
194 _DBG("phonelock create sock failed..!!");
199 datalen = strlen(cmd);
200 if ((len = send(fd, cmd, datalen, 0)) != datalen) {
201 _DBG("send() failed %d %d, errno:%d", len, datalen,