Commit f8d0985c authored by spiiroin's avatar spiiroin

[usb_moded] Expose mode switch as "busy" during transition

Especially switch to mtp_mode can take a long time to finish.

Use transitional "busy" mode as an enabler for ui showing a spinner when
mode change takes long enough to cause confusion for users.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 041d46de
......@@ -47,6 +47,7 @@
# define MODE_ADB "adb_mode"
# define MODE_PC_SUITE "pc_suite"
# define MODE_CHARGING "charging_only"
# define MODE_BUSY "busy"
/**
*
......
......@@ -182,6 +182,7 @@ const char *usbmoded_get_hardware_mode (void);
static void usbmoded_update_hardware_mode (void);
const char *usbmoded_get_external_mode (void);
static void usbmoded_set_external_mode (const char *mode);
static void usbmoded_update_external_mode (void);
const char *usbmoded_get_usb_mode (void);
......@@ -690,19 +691,16 @@ const char *usbmoded_get_external_mode(void)
return current_mode.external_mode ?: MODE_UNDEFINED;
}
static void usbmoded_update_external_mode(void)
static void usbmoded_set_external_mode(const char *mode)
{
const char *internal_mode = usbmoded_get_usb_mode();
const char *external_mode = usbmoded_map_mode_to_external(internal_mode);
gchar *previous = current_mode.external_mode;
if( !g_strcmp0(previous, external_mode) )
if( !g_strcmp0(previous, mode) )
goto EXIT;
log_debug("external_mode: %s -> %s",
previous, external_mode);
previous, mode);
current_mode.external_mode = g_strdup(external_mode);
current_mode.external_mode = g_strdup(mode);
g_free(previous);
// DO THE DBUS BROADCAST
......@@ -719,6 +717,14 @@ EXIT:
return;
}
static void usbmoded_update_external_mode(void)
{
const char *internal_mode = usbmoded_get_usb_mode();
const char *external_mode = usbmoded_map_mode_to_external(internal_mode);
usbmoded_set_external_mode(external_mode);
}
/** get the usb mode
*
* @return the currently set mode
......@@ -745,6 +751,9 @@ void usbmoded_set_usb_mode(const char *mode)
current_mode.internal_mode = g_strdup(mode);
g_free(previous);
/* Invalidate current mode for the duration of mode transition */
usbmoded_set_external_mode(MODE_BUSY);
// PROPAGATE DOWN TO GADGET CONFIG
usbmoded_update_hardware_mode();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment