4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include <sys/reboot.h>
30 #include <sys/mount.h>
31 #include "dd-deviced.h"
35 #include "device-handler.h"
36 #include "device-node.h"
37 #include "predefine.h"
38 #include "proc/proc-handler.h"
41 #include "display/poll.h"
42 #include "display/setting.h"
44 #include "battery/battery.h"
45 #include "edbus-handler.h"
47 #define VCONFKEY_SYSMAN_FACTORY_MODE "memory/sysman/factory_mode"
49 #define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/"
50 #define PREDEF_CALL "call"
51 #define PREDEF_FACTORY_MODE "factorymode"
53 #define CALL_EXEC_PATH PREFIX"/bin/call"
55 #define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup"
57 #define HDMI_NOTI_EXEC_PATH PREFIX"/bin/hdmi_connection_noti"
60 static int bFactoryMode = 0;
62 int predefine_get_pid(const char *execpath)
65 struct dirent *dentry;
71 dp = opendir("/proc");
73 _E("FAIL: open /proc");
77 while ((dentry = readdir(dp)) != NULL) {
78 if (!isdigit(dentry->d_name[0]))
81 pid = atoi(dentry->d_name);
83 snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
84 fd = open(buf, O_RDONLY);
87 ret = read(fd, buf2, PATH_MAX);
90 if (ret < 0 || ret >=PATH_MAX)
95 if (!strcmp(buf2, execpath)) {
107 int call_predefine_action(int argc, char **argv)
115 snprintf(argstr, sizeof(argstr), "-t MT -n %s -i %s", argv[0], argv[1]);
116 pid = launch_if_noexist(CALL_EXEC_PATH, argstr);
118 _E("call predefine action failed");
125 void predefine_pm_change_state(unsigned int s_bits)
127 if (is_factory_mode() == 1)
128 _D("skip LCD control for factory mode");
130 pm_change_internal(getpid(), s_bits);
133 int is_factory_mode(void)
137 int set_factory_mode(int bOn)
140 if ( bOn==1 || bOn==0 ) {
142 /* For USB-server to refer the value */
143 ret = vconf_set_int(VCONFKEY_SYSMAN_FACTORY_MODE, bOn);
145 _E("FAIL: vconf_set_int()");
151 int factory_mode_action(int argc, char **argv)
154 if (argc != 1 || argv[0] == NULL) {
155 _E("Factory Mode Set predefine action failed");
159 bOn = set_factory_mode(bOn);
164 static void action_entry_load_from_sodir()
167 struct dirent *dentry;
172 dp = opendir(PREDEFINE_SO_DIR);
174 _E("fail open %s", PREDEFINE_SO_DIR);
178 msg = malloc(sizeof(struct sysnoti));
187 while ((dentry = readdir(dp)) != NULL) {
188 if ((ext = strstr(dentry->d_name, ".so")) == NULL)
191 snprintf(tmp, sizeof(tmp), "%s/%s", PREDEFINE_SO_DIR,
195 msg->type = &(dentry->d_name[3]);
203 static DBusMessage *dbus_factory_mode(E_DBus_Object *obj, DBusMessage *msg)
206 DBusMessageIter iter;
214 dbus_error_init(&err);
216 if (!dbus_message_get_args(msg, &err,
217 DBUS_TYPE_STRING, &type_str,
218 DBUS_TYPE_INT32, &argc,
219 DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) {
220 _E("there is no message");
226 _E("message is invalid!");
231 pid = get_edbus_sender_pid(msg);
232 if (kill(pid, 0) == -1) {
233 _E("%d process does not exist, dbus ignored!", pid);
238 ret = set_factory_mode(atoi(argv));
240 reply = dbus_message_new_method_return(msg);
241 dbus_message_iter_init_append(reply, &iter);
242 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
247 static const struct edbus_method edbus_methods[] = {
248 { PREDEF_FACTORY_MODE, "sis", "i", dbus_factory_mode },
251 static void predefine_init(void *data)
253 /* telephony initialize */
256 ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods));
258 _E("fail to init edbus method(%d)", ret);
260 register_action(PREDEF_CALL, call_predefine_action, NULL, NULL);
262 register_action(PREDEF_FACTORY_MODE, factory_mode_action, NULL, NULL);
264 action_entry_load_from_sodir();
267 static const struct device_ops predefine_device_ops = {
268 .priority = DEVICE_PRIORITY_NORMAL,
270 .init = predefine_init,
273 DEVICE_OPS_REGISTER(&predefine_device_ops)