Skip to content
Permalink
Browse files
[usb_moded] Use accessor functions for rescue mode toggle
Makes it easier to differentiate between value use and value modify.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 5, 2018
1 parent 545aa27 commit 4873888f99cf534d6f5bffda369b4072d12494fe
Showing with 38 additions and 17 deletions.
  1. +1 −1 src/usb_moded-control.c
  2. +3 −3 src/usb_moded-dbus.c
  3. +32 −5 src/usb_moded.c
  4. +2 −8 src/usb_moded.h
@@ -231,7 +231,7 @@ void control_select_usb_mode(void)
{
char *mode_to_set = 0;

if( usbmoded_rescue_mode ) {
if( usbmoded_get_rescue_mode() ) {
log_debug("Entering rescue mode!\n");
control_set_usb_mode(MODE_DEVELOPER);
goto EXIT;
@@ -236,8 +236,8 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
usbmoded_set_init_done(true);

/* Auto-disable rescue mode when bootup is finished */
if( usbmoded_rescue_mode ) {
usbmoded_rescue_mode = FALSE;
if( usbmoded_get_rescue_mode() ) {
usbmoded_set_rescue_mode(false);
log_debug("init done reached - rescue mode disabled");
}
}
@@ -446,7 +446,7 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
}
else if(!strcmp(member, USB_MODE_RESCUE_OFF))
{
usbmoded_rescue_mode = FALSE;
usbmoded_set_rescue_mode(false);
log_debug("Rescue mode off\n ");
reply = dbus_message_new_method_return(msg);
}
@@ -104,6 +104,8 @@

/* -- usbmoded -- */

bool usbmoded_get_rescue_mode (void);
void usbmoded_set_rescue_mode (bool rescue_mode);
bool usbmoded_get_diag_mode (void);
void usbmoded_set_diag_mode (bool diag_mode);
void usbmoded_set_cable_connection_delay(int delay_ms);
@@ -129,7 +131,7 @@ static void usbmoded_parse_options (int argc, char *argv[]);
GList *usbmoded_modelist = 0;
static int usbmoded_exitcode = EXIT_FAILURE;
static GMainLoop *usbmoded_mainloop = NULL;
bool usbmoded_rescue_mode = false;

static bool usbmoded_hw_fallback = false;
#ifdef SYSTEMD
static bool usbmoded_systemd_notify = false;
@@ -139,6 +141,31 @@ static bool usbmoded_systemd_notify = false;
* Functions
* ========================================================================= */

/* ------------------------------------------------------------------------- *
* RESCUE_MODE
* ------------------------------------------------------------------------- */

/** Rescue mode flag
*
* When enabled, usb-moded allows developer_mode etc when device is
* booted up with cable connected without requiring device unlock.
* Which can be useful if UI for some reason does not come up.
*/
static bool usbmoded_rescue_mode = false;

bool usbmoded_get_rescue_mode(void)
{
return usbmoded_rescue_mode;
}

void usbmoded_set_rescue_mode(bool rescue_mode)
{
if( usbmoded_rescue_mode != rescue_mode ) {
log_info("rescue_mode: %d -> %d", usbmoded_rescue_mode, rescue_mode);
usbmoded_rescue_mode = rescue_mode;
}
}

/* ------------------------------------------------------------------------- *
* DIAG_MODE
* ------------------------------------------------------------------------- */
@@ -292,7 +319,7 @@ bool usbmoded_can_export(void)
devicelock_have_export_permission());

/* Having bootup rescue mode active is an exception */
if( usbmoded_rescue_mode )
if( usbmoded_get_rescue_mode() )
can_export = true;
#endif

@@ -404,8 +431,8 @@ static bool usbmoded_init(void)
goto EXIT;
}

if( usbmoded_rescue_mode && usbmoded_init_done_p() ) {
usbmoded_rescue_mode = false;
if( usbmoded_get_rescue_mode() && usbmoded_init_done_p() ) {
usbmoded_set_rescue_mode(false);
log_warning("init done passed; rescue mode ignored");
}

@@ -730,7 +757,7 @@ static void usbmoded_parse_options(int argc, char* argv[])
exit(EXIT_SUCCESS);

case 'r':
usbmoded_rescue_mode = true;
usbmoded_set_rescue_mode(true);
break;
#ifdef SYSTEMD
case 'n':
@@ -60,14 +60,6 @@
* Data
* ========================================================================= */

/** Rescue mode flag
*
* When enabled, usb-moded allows developer_mode etc when device is
* booted up with cable connected without requiring device unlock.
* Which can be useful if UI for some reason does not come up.
*/
extern bool usbmoded_rescue_mode;

extern GList *usbmoded_modelist;

/* ========================================================================= *
@@ -76,6 +68,8 @@ extern GList *usbmoded_modelist;

/* -- usbmoded -- */

bool usbmoded_get_rescue_mode (void);
void usbmoded_set_rescue_mode (bool rescue_mode);
bool usbmoded_get_diag_mode (void);
void usbmoded_set_diag_mode (bool diag_mode);
void usbmoded_set_cable_connection_delay(int delay_ms);

0 comments on commit 4873888

Please sign in to comment.