Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable display blanking and locking in MALF
Enable the automatic display blanking in MALF mode. Also protect the MALF mode
from MCE crashes by using intermediate files.
  • Loading branch information
Irina Bezruk authored and Santtu Lakkala committed Aug 11, 2011
1 parent c42aba9 commit 126abed
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 22 deletions.
6 changes: 6 additions & 0 deletions mce.h
Expand Up @@ -71,6 +71,10 @@

/** Persistent lock file for backups */
#define MCE_SETTINGS_LOCK_FILE_PATH G_STRINGIFY(MCE_RUN_DIR) "/restored"
/** Path for system MALF state indicator file */
#define MALF_FILENAME "/var/malf"
/** Path for MCE MALF state indicator file */
#define MCE_MALF_FILENAME G_STRINGIFY(MCE_RUN_DIR) "/malf"

/** Module information */
typedef struct {
Expand Down Expand Up @@ -138,6 +142,8 @@ typedef gint submode_t;
#define MCE_POCKET_SUBMODE (1 << 7)
/** Touchscreen/Keypad lock is enabled based on proximity state */
#define MCE_PROXIMITY_TKLOCK_SUBMODE (1 << 8)
/** Device is in MALF state */
#define MCE_MALF_SUBMODE (1 << 9)

/** System state */
typedef enum {
Expand Down
26 changes: 26 additions & 0 deletions modetransition.c
Expand Up @@ -201,12 +201,38 @@ gboolean mce_mode_init(void)

(void)mce_write_string_to_file(MCE_BOOTUP_FILENAME,
ENABLED_STRING);

if (g_access(MALF_FILENAME, F_OK) == 0) {
mce_add_submode_int32(MCE_MALF_SUBMODE);
mce_log(LL_DEBUG, "Malf mode enabled");
if (g_access(MCE_MALF_FILENAME, F_OK) == -1) {
if (errno != ENOENT) {
mce_log(LL_CRIT,
"access() failed: %s. Exiting.",
g_strerror(errno));
goto EXIT;
}

(void)mce_write_string_to_file(MCE_MALF_FILENAME,
ENABLED_STRING);
}
}
} else {
mce_log(LL_CRIT,
"access() failed: %s. Exiting.",
g_strerror(errno));
goto EXIT;
}
} else {
if (g_access(MALF_FILENAME, F_OK) == 0) {
if (g_access(MCE_MALF_FILENAME, F_OK) == 0) {
mce_add_submode_int32(MCE_MALF_SUBMODE);
mce_log(LL_DEBUG, "Malf mode enabled");
}
} else if ((errno == ENOENT) &&
(g_access(MCE_MALF_FILENAME, F_OK) == 0)) {
g_remove(MCE_MALF_FILENAME);
}
}

status = TRUE;
Expand Down
37 changes: 27 additions & 10 deletions modules/display.c
Expand Up @@ -486,12 +486,13 @@ static gboolean is_dismiss_low_power_mode_enabled(void)
call_state_t call_state = datapipe_get_gint(call_state_pipe);
submode_t submode = mce_get_submode_int32();

return ((((use_low_power_mode == TRUE) &&
return (((((use_low_power_mode == TRUE) &&
((call_state == CALL_STATE_RINGING) ||
(call_state == CALL_STATE_ACTIVE))) &&
(((submode & MCE_PROXIMITY_TKLOCK_SUBMODE) != 0) ||
(((submode & MCE_TKLOCK_SUBMODE) == 0) &&
((submode & MCE_PROXIMITY_TKLOCK_SUBMODE) == 0)))) ? TRUE : FALSE);
((submode & MCE_PROXIMITY_TKLOCK_SUBMODE) == 0)))) ||
((submode & MCE_MALF_SUBMODE) != 0)) ? TRUE : FALSE);
}

/**
Expand Down Expand Up @@ -1464,13 +1465,24 @@ static void setup_adaptive_dimming_timeout(void)
*/
static gboolean dim_timeout_cb(gpointer data)
{
submode_t submode = mce_get_submode_int32();

(void)data;

dim_timeout_cb_id = 0;

(void)execute_datapipe(&display_state_pipe,
GINT_TO_POINTER(MCE_DISPLAY_DIM),
USE_INDATA, CACHE_INDATA);
if ((submode & MCE_MALF_SUBMODE) == 0) {
(void)execute_datapipe(&display_state_pipe,
GINT_TO_POINTER(MCE_DISPLAY_DIM),
USE_INDATA, CACHE_INDATA);
} else {
/* If device is in MALF state skip dimming since systemui
* isn't working yet
*/
(void)execute_datapipe(&display_state_pipe,
GINT_TO_POINTER(MCE_DISPLAY_OFF),
USE_INDATA, CACHE_INDATA);
}

return FALSE;
}
Expand Down Expand Up @@ -1501,7 +1513,7 @@ static void setup_dim_timeout(void)
cancel_dim_timeout();

if ((dimming_inhibited == TRUE) ||
(system_state == MCE_STATE_ACTDEAD))
(system_state == MCE_STATE_ACTDEAD))
return;

if (adaptive_dimming_enabled == TRUE) {
Expand Down Expand Up @@ -2410,6 +2422,11 @@ static gboolean desktop_startup_dbus_cb(DBusMessage *const msg)

mce_rem_submode_int32(MCE_BOOTUP_SUBMODE);

mce_rem_submode_int32(MCE_MALF_SUBMODE);
if (g_access(MCE_MALF_FILENAME, F_OK) == 0) {
g_remove(MCE_MALF_FILENAME);
}

/* Restore normal inactivity timeout */
(void)execute_datapipe(&inactivity_timeout_pipe,
GINT_TO_POINTER(disp_dim_timeout +
Expand Down Expand Up @@ -2487,8 +2504,8 @@ static gpointer display_state_filter(gpointer data)
((display_state != MCE_DISPLAY_LPM_OFF) &&
(display_state != MCE_DISPLAY_OFF)) &&
((system_state == MCE_STATE_UNDEF) ||
((submode & MCE_TRANSITION_SUBMODE) &&
(((system_state == MCE_STATE_SHUTDOWN) ||
((submode & MCE_TRANSITION_SUBMODE) &&
(((system_state == MCE_STATE_SHUTDOWN) ||
(system_state == MCE_STATE_REBOOT)) ||
((system_state == MCE_STATE_ACTDEAD) &&
((alarm_ui_state != MCE_ALARM_UI_VISIBLE_INT32) &&
Expand All @@ -2499,8 +2516,8 @@ static gpointer display_state_filter(gpointer data)
display_state);
display_state = cached_display_state;
} else if ((use_low_power_mode == FALSE) ||
(low_power_mode_supported == FALSE) ||
(is_dismiss_low_power_mode_enabled() == TRUE)) {
(low_power_mode_supported == FALSE) ||
(is_dismiss_low_power_mode_enabled() == TRUE)) {
/* If we don't use low power mode, use OFF instead */
if ((display_state == MCE_DISPLAY_LPM_OFF) ||
(display_state == MCE_DISPLAY_LPM_ON))
Expand Down
4 changes: 4 additions & 0 deletions powerkey.c
Expand Up @@ -160,6 +160,10 @@ static void generic_powerkey_handler(poweraction_t action,
execute_datapipe(&tk_lock_pipe,
GINT_TO_POINTER(LOCK_ON),
USE_INDATA, CACHE_INDATA);
} else if ((submode & MCE_MALF_SUBMODE) != 0) {
execute_datapipe(&tk_lock_pipe,
GINT_TO_POINTER(LOCK_OFF),
USE_INDATA, CACHE_INDATA);
}

break;
Expand Down
49 changes: 37 additions & 12 deletions tklock.c
Expand Up @@ -250,6 +250,18 @@ static gboolean is_tklock_enabled(void)
return ((mce_get_submode_int32() & MCE_TKLOCK_SUBMODE) != 0);
}

/**
* Query whether the device is in the MALF state
*
* @return TRUE if the malf state is enabled,
* FALSE if the malf state is disabled
*/
static gboolean is_malf_state_enabled(void) G_GNUC_PURE;
static gboolean is_malf_state_enabled(void)
{
return ((mce_get_submode_int32() & MCE_MALF_SUBMODE) != 0);
}

/**
* Query the visual touchscreen/keypad lock status
*
Expand Down Expand Up @@ -608,7 +620,8 @@ static void ts_kp_disable_policy(void)
goto EXIT;
}

if (system_state != MCE_STATE_USER) {
if ((system_state != MCE_STATE_USER) ||
(is_malf_state_enabled() == TRUE)){
ts_disable();
kp_disable();
} else if (((display_state == MCE_DISPLAY_OFF) ||
Expand Down Expand Up @@ -1034,11 +1047,15 @@ static gboolean enable_tklock(void)
{
gboolean status = FALSE;

if (open_tklock_ui(TKLOCK_ENABLE_LPM_UI) == FALSE)
if ((is_malf_state_enabled() == FALSE) &&
(open_tklock_ui(TKLOCK_ENABLE_LPM_UI) == FALSE))
goto EXIT;

enable_tklock_raw();
mce_add_submode_int32(MCE_VISUAL_TKLOCK_SUBMODE);

if (is_malf_state_enabled() == FALSE) {
mce_add_submode_int32(MCE_VISUAL_TKLOCK_SUBMODE);
}

status = TRUE;

Expand Down Expand Up @@ -1306,9 +1323,10 @@ static gboolean enable_eveater(void)
/* If we're in acting dead and no alarm is visible,
* don't activate the event eater
*/
if ((system_state == MCE_STATE_ACTDEAD) &&
((alarm_ui_state != MCE_ALARM_UI_VISIBLE_INT32) ||
(alarm_ui_state != MCE_ALARM_UI_RINGING_INT32)))
if (((system_state == MCE_STATE_ACTDEAD) &&
((alarm_ui_state != MCE_ALARM_UI_VISIBLE_INT32) ||
(alarm_ui_state != MCE_ALARM_UI_RINGING_INT32))) ||
(is_malf_state_enabled() == TRUE))
goto EXIT;

/* If we're already showing a tklock UI, exit */
Expand Down Expand Up @@ -1456,8 +1474,11 @@ static gboolean enable_autokeylock(void)
submode_t submode = datapipe_get_gint(submode_pipe);
gboolean status = TRUE;

/* Don't enable automatic tklock during bootup */
if ((submode & MCE_BOOTUP_SUBMODE) != 0)
/* Don't enable automatic tklock during bootup, except when in MALF
* state
*/
if (((submode & MCE_BOOTUP_SUBMODE) != 0) &&
(is_malf_state_enabled() == FALSE))
goto EXIT;

if ((system_state == MCE_STATE_USER) &&
Expand Down Expand Up @@ -1503,9 +1524,10 @@ static void set_tklock_state(lock_state_t lock_state)
case LOCK_ON:
case LOCK_ON_DIMMED:
case LOCK_ON_PROXIMITY:
if ((submode & MCE_BOOTUP_SUBMODE) != 0)
if (((submode & MCE_BOOTUP_SUBMODE) != 0) &&
(is_malf_state_enabled() == FALSE)){
goto EXIT;

}
default:
break;
}
Expand Down Expand Up @@ -1598,7 +1620,8 @@ static void trigger_visual_tklock(gboolean powerkey)
display_state_t display_state = datapipe_get_gint(display_state_pipe);
submode_t submode = mce_get_submode_int32();

if ((is_tklock_enabled() == FALSE) ||
if ((is_malf_state_enabled() == TRUE) ||
(is_tklock_enabled() == FALSE) ||
(is_autorelock_enabled() == FALSE) ||
(system_state != MCE_STATE_USER) ||
(alarm_ui_state == MCE_ALARM_UI_VISIBLE_INT32) ||
Expand Down Expand Up @@ -2272,7 +2295,9 @@ static void display_state_trigger(gconstpointer data)
ts_kp_disable_policy();
} else if ((alarm_ui_state != MCE_ALARM_UI_RINGING_INT32) &&
(is_tklock_enabled() == TRUE)) {
(void)open_tklock_ui(TKLOCK_ENABLE_VISUAL);
if (is_malf_state_enabled() == FALSE) {
(void)open_tklock_ui(TKLOCK_ENABLE_VISUAL);
}
ts_kp_disable_policy();
} else {
(void)enable_autokeylock();
Expand Down

0 comments on commit 126abed

Please sign in to comment.