power: add power.conf to support reboot options 68/104868/5
authortaeyoung <ty317.kim@samsung.com>
Wed, 14 Dec 2016 12:18:24 +0000 (21:18 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Wed, 21 Dec 2016 06:45:09 +0000 (22:45 -0800)
The poweroff and reboot options are handled by a list.
The list is from power.conf file. Vendors can add their
own reboot options by modifying the conf file.

Change-Id: I3f7d50c0f5e4e47374170730b94b6e799749cd21
Signed-off-by: taeyoung <ty317.kim@samsung.com>
CMakeLists.txt
packaging/deviced.spec
src/power/power-handler.c
src/power/power-handler.h
src/power/power.conf [new file with mode: 0644]

index 37c07c3..14ce0f6 100755 (executable)
@@ -257,6 +257,10 @@ IF(DISPLAY_MODULE STREQUAL on)
        INSTALL_CONF(src/display display)
 ENDIF()
 
+IF(POWER_MODULE STREQUAL on)
+       INSTALL_CONF(src/power power)
+ENDIF()
+
 # USB connection
 IF(${USB_MODULE} STREQUAL on)
        INSTALL_CONF(src/usb usb-operation)
index 7fd84cb..1b2de31 100644 (file)
@@ -279,6 +279,9 @@ systemctl daemon-reload
 %if %{?haptic_module} == on
 %config %{_sysconfdir}/deviced/haptic.conf
 %endif
+%if %{?power_module} == on
+%config %{_sysconfdir}/deviced/power.conf
+%endif
 %if %{?usb_module} == on
 %config %{_sysconfdir}/deviced/usb-operation.conf
 %if %{?sdb_prestart} == on
index b647d76..b94094c 100644 (file)
@@ -39,6 +39,7 @@
 #include "dd-deviced.h"
 #include "core/log.h"
 #include "core/launch.h"
+#include "core/config-parser.h"
 #include "core/device-notifier.h"
 #include "core/device-idler.h"
 #include "core/common.h"
@@ -63,6 +64,8 @@
 #define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF
 #define POWER_FLAG_REBOOT   "/run/"POWER_REBOOT
 
+#define POWER_CONF_FILE "/etc/deviced/power.conf"
+
 struct power_flag {
        enum poweroff_type type;
        const char *path;
@@ -73,6 +76,8 @@ struct power_flag {
 
 static struct timeval tv_start_poweroff;
 
+static dd_list *poweroff_options;
+
 static int telephony_off(enum poweroff_type type)
 {
        const struct device_ops *tele;
@@ -568,6 +573,65 @@ static const struct edbus_method edbus_methods[] = {
        /* Add methods here */
 };
 
+static int add_poweroff_option(enum poweroff_type type, char *option)
+{
+       struct power_option *opt;
+       static int index = 0;
+       char *name;
+
+       if (type == POWER_OFF_POPUP)
+               name = PWROFF_POPUP;
+       else if (type == POWER_OFF_DIRECT)
+               name = POWER_POWEROFF;
+       else if (type == POWER_OFF_RESTART)
+               name = POWER_REBOOT;
+       else {
+               _E("Invalid type (%d)", type);
+               return -EINVAL;
+       }
+
+       opt = calloc(1, sizeof(struct power_option));
+       if (!opt) {
+               _E("calloc() failed");
+               return -ENOMEM;
+       }
+
+       opt->type = type;
+       opt->name = strdup(name);
+       opt->option = (option ? strdup(option) : NULL);
+       opt->index = index++;
+
+       DD_LIST_APPEND(poweroff_options, opt);
+
+       _I("Add %s option (%s)", opt->name, opt->option);
+
+       return 0;
+}
+
+static int load_config(struct parse_result *result, void *user_data)
+{
+       enum poweroff_type type;
+       int ret;
+
+       if (MATCH(result->section, "Poweroff"))
+               type = POWER_OFF_DIRECT;
+       else if (MATCH(result->section, "Reboot"))
+               type = POWER_OFF_RESTART;
+       else
+               return 0;
+
+       if (!MATCH(result->name, "Option"))
+               return 0;
+
+       ret = add_poweroff_option(type, result->value);
+       if (ret < 0) {
+               _E("Failed to add %s option (%s)", result->section, result->value);
+               return ret;
+       }
+
+       return 0;
+}
+
 static void power_init(void *data)
 {
        int ret;
@@ -581,6 +645,14 @@ static void power_init(void *data)
        add_booting_done_handler(NULL);
 
        register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
+
+       add_poweroff_option(POWER_OFF_DIRECT, NULL);
+       add_poweroff_option(POWER_OFF_RESTART, NULL);
+       add_poweroff_option(POWER_OFF_POPUP, NULL);
+
+       ret = config_parse(POWER_CONF_FILE, load_config, NULL);
+       if (ret < 0)
+               _E("Failed to load power off config (%d)", ret);
 }
 
 static const struct device_ops power_device_ops = {
index c56242c..5100086 100644 (file)
@@ -35,6 +35,13 @@ enum poweroff_type {
        POWER_OFF_RESTART,
 };
 
+struct power_option {
+       enum poweroff_type type;
+       char *name;
+       char *option;
+       int index;
+};
+
 void powerdown_ap(void *data);
 void restart_ap(void *data);
 int check_power_flag(void);
diff --git a/src/power/power.conf b/src/power/power.conf
new file mode 100644 (file)
index 0000000..e99b94d
--- /dev/null
@@ -0,0 +1,5 @@
+[Reboot]
+Option=recovery
+Option=download
+Option=wdownload
+Option=debug