if (launched_poweroff == 1) {
_I("Will be foreced power off.");
- power_execute(POWER_STATE_POWEROFF);
+ power_execute(DEVICE_POWER_STATE_POWEROFF);
return 0;
}
static int battery_power_off_act(void *data)
{
CRITICAL_LOG("Low battery power off.");
- return power_execute(POWER_STATE_POWEROFF);
+ return power_execute(DEVICE_POWER_STATE_POWEROFF);
}
int battery_charge_err_cf_act(void *data)
retval = hal_device_board_get_boot_reason(bc.reason, sizeof(bc.reason));
if (retval != 0) {
_I("Failed to get BootReason, %d. Default change state to normal.", retval);
- power_request_change_state_strict(POWER_STATE_START, POWER_STATE_NORMAL, 1, NULL);
+ power_request_change_state_strict(DEVICE_POWER_STATE_START, DEVICE_POWER_STATE_NORMAL, 1, NULL);
return;
}
g_variant_get(param, "(t)", &next);
- for (index = POWER_STATE_MIN_INDEX; index < POWER_STATE_MAX_INDEX; ++index)
+ for (index = DEVICE_POWER_STATE_MIN_INDEX; index < DEVICE_POWER_STATE_MAX_INDEX; ++index)
if (next == (1UL << index))
break;
- if (index == POWER_STATE_MAX_INDEX) {
+ if (index == DEVICE_POWER_STATE_MAX_INDEX) {
_E("Invalid next state=%#lx", (long) index);
ret = -EINVAL;
goto out;
_I("Pid=%d(%s) sent request for PowerChangeState to %s", pid, comm, state_name(next));
- power_request_change_state_strict(POWER_STATE_ALL, next, 0, NULL);
+ power_request_change_state_strict(DEVICE_POWER_STATE_ALL, next, 0, NULL);
out:
return g_variant_new("(i)", ret);
if (!is_poweroff_state(state))
return;
- if (state == POWER_STATE_POWEROFF)
+ if (state == DEVICE_POWER_STATE_POWEROFF)
systemd_method = "PowerOff";
- else if (state == POWER_STATE_REBOOT)
+ else if (state == DEVICE_POWER_STATE_REBOOT)
systemd_method = "Reboot";
- else if (state == POWER_STATE_EXIT)
+ else if (state == DEVICE_POWER_STATE_EXIT)
systemd_method = "Exit";
CRITICAL_LOG("Requested %s via systemd.", systemd_method);
int poweroff_check_revived(void)
{
if (access(POWEROFF_OPTPATH_POWEROFF, F_OK) == 0) {
- return POWER_STATE_POWEROFF;
+ return DEVICE_POWER_STATE_POWEROFF;
}
if (access(POWEROFF_OPTPATH_REBOOT, F_OK) == 0) {
- return POWER_STATE_REBOOT;
+ return DEVICE_POWER_STATE_REBOOT;
}
if (access(POWEROFF_OPTPATH_EXIT, F_OK) == 0) {
- return POWER_STATE_EXIT;
+ return DEVICE_POWER_STATE_EXIT;
}
- return POWER_STATE_NORMAL;
+ return DEVICE_POWER_STATE_NORMAL;
}
static void mark_poweroff_option(uint64_t state, const char *option)
ssize_t len;
const char *optpath;
- if (state == POWER_STATE_POWEROFF)
+ if (state == DEVICE_POWER_STATE_POWEROFF)
optpath = POWEROFF_OPTPATH_POWEROFF;
- else if (state == POWER_STATE_REBOOT)
+ else if (state == DEVICE_POWER_STATE_REBOOT)
optpath = POWEROFF_OPTPATH_REBOOT;
- else if (state == POWER_STATE_EXIT)
+ else if (state == DEVICE_POWER_STATE_EXIT)
optpath = POWEROFF_OPTPATH_EXIT;
else
return;
mark_poweroff_option(state, option);
- if (state == POWER_STATE_POWEROFF)
+ if (state == DEVICE_POWER_STATE_POWEROFF)
vconf = VCONFKEY_SYSMAN_POWER_OFF_DIRECT;
- else if (state == POWER_STATE_REBOOT)
+ else if (state == DEVICE_POWER_STATE_REBOOT)
vconf = VCONFKEY_SYSMAN_POWER_OFF_RESTART;
vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, vconf);
get_command(ret, comm, sizeof(comm));
if (strncmp(type, "poweroff", sizeof("poweroff")) == 0)
- next = POWER_STATE_POWEROFF;
+ next = DEVICE_POWER_STATE_POWEROFF;
else if (strncmp(type, "reboot", sizeof("reboot")) == 0)
- next = POWER_STATE_REBOOT;
+ next = DEVICE_POWER_STATE_REBOOT;
else if (strncmp(type, "exit", sizeof("exit")) == 0)
- next = POWER_STATE_EXIT;
+ next = DEVICE_POWER_STATE_EXIT;
else {
ret = -EINVAL;
goto out;
}
CRITICAL_LOG("Poweroff pid=%d(%s) requests %s.", ret, comm, type);
- power_request_change_state_strict(POWER_STATE_ALL, next, 9000, NULL);
+ power_request_change_state_strict(DEVICE_POWER_STATE_ALL, next, 9000, NULL);
out:
g_free(type);
get_command(ret, comm, sizeof(comm));
if (strncmp(type, "poweroff", sizeof("poweroff")) == 0)
- next = POWER_STATE_POWEROFF;
+ next = DEVICE_POWER_STATE_POWEROFF;
else if (strncmp(type, "reboot", sizeof("reboot")) == 0)
- next = POWER_STATE_REBOOT;
+ next = DEVICE_POWER_STATE_REBOOT;
else if (strncmp(type, "exit", sizeof("exit")) == 0)
- next = POWER_STATE_EXIT;
+ next = DEVICE_POWER_STATE_EXIT;
else {
ret = -EINVAL;
goto out;
}
CRITICAL_LOG("Poweroff pid=%d(%s) requests type=%s option=%s.", ret, comm, type, option);
- power_request_change_state_strict(POWER_STATE_ALL, next, 9000, option);
+ power_request_change_state_strict(DEVICE_POWER_STATE_ALL, next, 9000, option);
out:
g_free(type);
#define MAX_DESC_LEN 256
static int delayed_init_done = 0;
-static uint64_t current = POWER_STATE_START; /* current power state */
+static uint64_t current = DEVICE_POWER_STATE_START; /* current power state */
static int max_wait_timeout = DEFAULT_MAX_WAIT_SECOND;
static GQueue *transition_queue;
static struct {
};
static const uint64_t transient_scenario_suspending[] = {
- POWER_STATE_TRANSIENT_SUSPENDING_EARLY,
- POWER_STATE_TRANSIENT_SUSPENDING,
- POWER_STATE_TRANSIENT_SUSPENDING_LATE,
+ DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_EARLY,
+ DEVICE_POWER_STATE_TRANSIENT_SUSPENDING,
+ DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_LATE,
};
static const uint64_t transient_scenario_resuming[] = {
- POWER_STATE_TRANSIENT_RESUMING_EARLY,
- POWER_STATE_TRANSIENT_RESUMING,
- POWER_STATE_TRANSIENT_RESUMING_LATE,
+ DEVICE_POWER_STATE_TRANSIENT_RESUMING_EARLY,
+ DEVICE_POWER_STATE_TRANSIENT_RESUMING,
+ DEVICE_POWER_STATE_TRANSIENT_RESUMING_LATE,
};
static const struct {
int max_step;
const uint64_t *scenario;
-} transient[POWER_STATE_MAX_INDEX][POWER_STATE_MAX_INDEX] = {
- [POWER_STATE_NORMAL_INDEX][POWER_STATE_SLEEP_INDEX] = {
+} transient[DEVICE_POWER_STATE_MAX_INDEX][DEVICE_POWER_STATE_MAX_INDEX] = {
+ [DEVICE_POWER_STATE_NORMAL_INDEX][DEVICE_POWER_STATE_SLEEP_INDEX] = {
.max_step = ARRAY_SIZE(transient_scenario_suspending),
.scenario = transient_scenario_suspending,
},
- [POWER_STATE_SLEEP_INDEX][POWER_STATE_NORMAL_INDEX] = {
+ [DEVICE_POWER_STATE_SLEEP_INDEX][DEVICE_POWER_STATE_NORMAL_INDEX] = {
.max_step = ARRAY_SIZE(transient_scenario_resuming),
.scenario = transient_scenario_resuming,
},
static void power_action_normal(void *data);
static void power_action_sleep(void *data);
static void power_action_poweroff(void *data);
-static void (*const action_on_state[POWER_STATE_MAX_INDEX]) (void *) = {
- [POWER_STATE_NORMAL_INDEX] = power_action_normal,
- [POWER_STATE_SLEEP_INDEX] = power_action_sleep,
- [POWER_STATE_POWEROFF_INDEX] = power_action_poweroff,
- [POWER_STATE_REBOOT_INDEX] = power_action_poweroff,
- [POWER_STATE_EXIT_INDEX] = power_action_poweroff,
+static void (*const action_on_state[DEVICE_POWER_STATE_MAX_INDEX]) (void *) = {
+ [DEVICE_POWER_STATE_NORMAL_INDEX] = power_action_normal,
+ [DEVICE_POWER_STATE_SLEEP_INDEX] = power_action_sleep,
+ [DEVICE_POWER_STATE_POWEROFF_INDEX] = power_action_poweroff,
+ [DEVICE_POWER_STATE_REBOOT_INDEX] = power_action_poweroff,
+ [DEVICE_POWER_STATE_EXIT_INDEX] = power_action_poweroff,
};
uint64_t power_get_state(void)
static void power_action_sleep(void *udata)
{
- /* for POWER_STATE_NORMAL, POWER_STATE_POWEROFF, do not wake unlock */
- if (current != POWER_STATE_SLEEP) {
+ /* for DEVICE_POWER_STATE_NORMAL, DEVICE_POWER_STATE_POWEROFF, do not wake unlock */
+ if (current != DEVICE_POWER_STATE_SLEEP) {
_E("Ignore sleep wait done, current=%s", state_name(current));
return;
}
uint64_t next = get_next_state();
- if (next == POWER_STATE_START)
+ if (next == DEVICE_POWER_STATE_START)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_START;
- else if (next == POWER_STATE_NORMAL)
+ else if (next == DEVICE_POWER_STATE_NORMAL)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_NORMAL;
- else if (next == POWER_STATE_SLEEP)
+ else if (next == DEVICE_POWER_STATE_SLEEP)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_SLEEP;
- else if (next == POWER_STATE_POWEROFF)
+ else if (next == DEVICE_POWER_STATE_POWEROFF)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_POWEROFF;
- else if (next == POWER_STATE_REBOOT)
+ else if (next == DEVICE_POWER_STATE_REBOOT)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_REBOOT;
- else if (next == POWER_STATE_EXIT)
+ else if (next == DEVICE_POWER_STATE_EXIT)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_EXIT;
- else if (next == POWER_STATE_TRANSIENT_SUSPENDING_EARLY)
+ else if (next == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_EARLY)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_SUSPENDING_EARLY;
- else if (next == POWER_STATE_TRANSIENT_SUSPENDING)
+ else if (next == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_SUSPENDING;
- else if (next == POWER_STATE_TRANSIENT_SUSPENDING_LATE)
+ else if (next == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_LATE)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_SUSPENDING_LATE;
- else if (next == POWER_STATE_TRANSIENT_RESUMING_EARLY)
+ else if (next == DEVICE_POWER_STATE_TRANSIENT_RESUMING_EARLY)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_RESUMING_EARLY;
- else if (next == POWER_STATE_TRANSIENT_RESUMING)
+ else if (next == DEVICE_POWER_STATE_TRANSIENT_RESUMING)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_RESUMING;
- else if (next == POWER_STATE_TRANSIENT_RESUMING_LATE)
+ else if (next == DEVICE_POWER_STATE_TRANSIENT_RESUMING_LATE)
signame = DEVICED_SIGNAL_POWER_CHANGE_STATE_TO_RESUMING_LATE;
else
return;
static char *state_abbr_name(uint64_t state)
{
- if (state == POWER_STATE_START)
+ if (state == DEVICE_POWER_STATE_START)
return "START";
- if (state == POWER_STATE_NORMAL)
+ if (state == DEVICE_POWER_STATE_NORMAL)
return "NORMAL";
- if (state == POWER_STATE_SLEEP)
+ if (state == DEVICE_POWER_STATE_SLEEP)
return "SLEEP";
- if (state == POWER_STATE_POWEROFF)
+ if (state == DEVICE_POWER_STATE_POWEROFF)
return "POWEROFF";
- if (state == POWER_STATE_REBOOT)
+ if (state == DEVICE_POWER_STATE_REBOOT)
return "REBOOT";
- if (state == POWER_STATE_EXIT)
+ if (state == DEVICE_POWER_STATE_EXIT)
return "EXIT";
- if (state == POWER_STATE_TRANSIENT_SUSPENDING_EARLY)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_EARLY)
return "SUSPENDING_EARLY";
- if (state == POWER_STATE_TRANSIENT_SUSPENDING)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING)
return "SUSPENDING";
- if (state == POWER_STATE_TRANSIENT_SUSPENDING_LATE)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_LATE)
return "SUSPENDING_LATE";
- if (state == POWER_STATE_TRANSIENT_RESUMING_EARLY)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_RESUMING_EARLY)
return "RESUMING_EARLY";
- if (state == POWER_STATE_TRANSIENT_RESUMING)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_RESUMING)
return "RESUMING";
- if (state == POWER_STATE_TRANSIENT_RESUMING_LATE)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_RESUMING_LATE)
return "RESUMING_LATE";
return "INVALID";
t = l->data;
// check invalid next state
- if (__builtin_popcountll(t->next & POWER_STATE_ALL) != 1) {
+ if (__builtin_popcountll(t->next & DEVICE_POWER_STATE_ALL) != 1) {
_E("Invalid next state, curr=%"PRIx64", next=%"PRIx64", reason=%d", t->curr, t->next, t->reason);
return 0;
}
/* Take the first transition.
*
- * It is determined by bootreason and bootmode to which state to transition, POWER_STATE_NORMAL
- * or POWER_STATE_SLEEP. it may stay in POWER_STATE_START if there is no defined action for the
+ * It is determined by bootreason and bootmode to which state to transition, DEVICE_POWER_STATE_NORMAL
+ * or DEVICE_POWER_STATE_SLEEP. it may stay in DEVICE_POWER_STATE_START if there is no defined action for the
* matching bootreason and bootmode.
*/
initial_transition_by_boot_condition();
static inline uint64_t convert_action_string_to_power_state(const char *str)
{
if (MATCH(str, "start"))
- return POWER_STATE_START;
+ return DEVICE_POWER_STATE_START;
else if (MATCH(str, "sleep"))
- return POWER_STATE_SLEEP;
+ return DEVICE_POWER_STATE_SLEEP;
else if (MATCH(str, "normal"))
- return POWER_STATE_NORMAL;
+ return DEVICE_POWER_STATE_NORMAL;
else if (MATCH(str, "poweroff"))
- return POWER_STATE_POWEROFF;
+ return DEVICE_POWER_STATE_POWEROFF;
else if (MATCH(str, "reboot"))
- return POWER_STATE_REBOOT;
+ return DEVICE_POWER_STATE_REBOOT;
else if (MATCH(str, "exit"))
- return POWER_STATE_EXIT;
+ return DEVICE_POWER_STATE_EXIT;
else if (MATCH(str, "current"))
- return POWER_STATE_ALL;
+ return DEVICE_POWER_STATE_ALL;
_W("Invalid power state=%s", str);
static inline const char *state_name(uint64_t state)
{
- if (state == POWER_STATE_START)
+ if (state == DEVICE_POWER_STATE_START)
return "POWER_STATE_START";
- if (state == POWER_STATE_NORMAL)
+ if (state == DEVICE_POWER_STATE_NORMAL)
return "POWER_STATE_NORMAL";
- if (state == POWER_STATE_SLEEP)
+ if (state == DEVICE_POWER_STATE_SLEEP)
return "POWER_STATE_SLEEP";
- if (state == POWER_STATE_POWEROFF)
+ if (state == DEVICE_POWER_STATE_POWEROFF)
return "POWER_STATE_POWEROFF";
- if (state == POWER_STATE_REBOOT)
+ if (state == DEVICE_POWER_STATE_REBOOT)
return "POWER_STATE_REBOOT";
- if (state == POWER_STATE_EXIT)
+ if (state == DEVICE_POWER_STATE_EXIT)
return "POWER_STATE_EXIT";
- if (state == POWER_STATE_TRANSIENT_SUSPENDING_EARLY)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_EARLY)
return "POWER_STATE_TRANSIENT_SUSPENDING_EARLY";
- if (state == POWER_STATE_TRANSIENT_SUSPENDING)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING)
return "POWER_STATE_TRANSIENT_SUSPENDING";
- if (state == POWER_STATE_TRANSIENT_SUSPENDING_LATE)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_SUSPENDING_LATE)
return "POWER_STATE_TRANSIENT_SUSPENDING_LATE";
- if (state == POWER_STATE_TRANSIENT_RESUMING_EARLY)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_RESUMING_EARLY)
return "POWER_STATE_TRANSIENT_RESUMING_EARLY";
- if (state == POWER_STATE_TRANSIENT_RESUMING)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_RESUMING)
return "POWER_STATE_TRANSIENT_RESUMING";
- if (state == POWER_STATE_TRANSIENT_RESUMING_LATE)
+ if (state == DEVICE_POWER_STATE_TRANSIENT_RESUMING_LATE)
return "POWER_STATE_TRANSIENT_RESUMING_LATE";
- if (state == POWER_STATE_ALL)
+ if (state == DEVICE_POWER_STATE_ALL)
return "POWER_STATE_ALL";
return "POWER_STATE_INVALID";
static inline int is_poweroff_state(uint64_t state)
{
- return !!(state & (POWER_STATE_POWEROFF | POWER_STATE_REBOOT | POWER_STATE_EXIT));
+ return !!(state & (DEVICE_POWER_STATE_POWEROFF | DEVICE_POWER_STATE_REBOOT | DEVICE_POWER_STATE_EXIT));
}
static inline void power_request_change_state_strict(uint64_t curr, uint64_t next, int reason, void *udata)
static inline void power_request_change_state(uint64_t next, int reason)
{
- power_request_change_state_strict(POWER_STATE_ALL, next, reason, NULL);
+ power_request_change_state_strict(DEVICE_POWER_STATE_ALL, next, reason, NULL);
}
uint64_t power_get_state(void);