Skip to content

Commit

Permalink
[charging fallback] introduce charging fallback mode. Fixes JB#22320
Browse files Browse the repository at this point in the history
Identify if we fell back to charging or it was a user conscious decision.
This helps us to know if we should set a mode if the device lock gets
unlocked or not.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 26, 2014
1 parent 907513c commit 147dcc5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/usb_moded-devicelock.c
Expand Up @@ -140,6 +140,7 @@ static DBusHandlerResult devicelock_unlocked_cb(DBusConnection *conn, DBusMessag
if(ret == 0 && get_usb_connection_state() == 1 )
{
log_debug("usb_mode %s\n", get_usb_mode());
/* if the mode is MODE_CHARGING_FALLBACK we know the user has not selected any mode */
if(!strcmp(get_usb_mode(), MODE_UNDEFINED) || !strcmp(get_usb_mode(), MODE_CHARGING)) {
log_debug("set_usb");
set_usb_connected_state();
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-modes.h
Expand Up @@ -24,6 +24,7 @@
#define MODE_MASS_STORAGE "mass_storage"
#define MODE_OVI_SUITE "ovi_suite"
#define MODE_CHARGING "charging_only"
#define MODE_CHARGING_FALLBACK "charging_only_fallback"
#define MODE_UNDEFINED "undefined"
#define MODE_ASK "ask"
#define MODE_DEVELOPER "developer_mode"
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-modesetting.c
Expand Up @@ -533,7 +533,7 @@ int usb_moded_mode_cleanup(const char *module)
{
/* no clean-up needs to be done when we come from charging mode. We need
to check since we use fake mass-storage for charging */
if(!strcmp(MODE_CHARGING, get_usb_mode()))
if(!strcmp(MODE_CHARGING, get_usb_mode()) || !strcmp(MODE_CHARGING_FALLBACK, get_usb_mode()))
return 0;
unset_mass_storage_mode(NULL);
}
Expand Down
16 changes: 9 additions & 7 deletions src/usb_moded.c
Expand Up @@ -158,7 +158,8 @@ static gboolean set_disconnected(gpointer data)
/* signal usb disconnected */
usb_moded_send_signal(USB_DISCONNECTED);
/* unload modules and general cleanup if not charging */
if(strcmp(get_usb_mode(), MODE_CHARGING))
if(strcmp(get_usb_mode(), MODE_CHARGING) ||
strcmp(get_usb_mode(), MODE_CHARGING_FALLBACK))
usb_moded_mode_cleanup(get_usb_module());
/* Nothing else as we do not need to do anything for cleaning up charging mode */
usb_moded_module_cleanup(get_usb_module());
Expand All @@ -177,7 +178,8 @@ if(!get_usb_connection_state())
{
log_debug("Resetting connection data after HUP\n");
/* unload modules and general cleanup if not charging */
if(strcmp(get_usb_mode(), MODE_CHARGING))
if(strcmp(get_usb_mode(), MODE_CHARGING) ||
strcmp(get_usb_mode(), MODE_CHARGING_FALLBACK))
usb_moded_mode_cleanup(get_usb_module());
/* Nothing else as we do not need to do anything for cleaning up charging mode */
usb_moded_module_cleanup(get_usb_module());
Expand Down Expand Up @@ -285,7 +287,7 @@ void set_usb_connected_state(void)
We also fall back here in case the device is locked and we do not
export the system contents. Or if we are in acting dead mode.
*/
set_usb_mode(MODE_CHARGING);
set_usb_mode(MODE_CHARGING_FALLBACK);
}
end:
free((void *)mode_to_set);
Expand Down Expand Up @@ -322,7 +324,7 @@ void set_usb_mode(const char *mode)

log_debug("Setting %s\n", mode);

if(!strcmp(mode, MODE_CHARGING))
if(!strcmp(mode, MODE_CHARGING) || !strcmp(mode, MODE_CHARGING_FALLBACK))
{
check_module_state(MODULE_MASS_STORAGE);
/* for charging we use a fake file_storage (blame USB certification for this insanity */
Expand Down Expand Up @@ -394,8 +396,8 @@ void set_usb_mode(const char *mode)
int valid_mode(const char *mode)
{

/* MODE_ASK and MODE_CHARGER are not modes that are settable seen their special status */
if(!strcmp(MODE_CHARGING, mode))
/* MODE_ASK and MODE_CHARGER_FALLBACK are not modes that are settable seen their special status */
if(!strcmp(MODE_CHARGING_FALLBACK, mode))
return(0);
else
{
Expand Down Expand Up @@ -580,7 +582,7 @@ static gboolean charging_fallback(gpointer data)
if(strcmp(get_usb_mode(), MODE_ASK) != 0)
return FALSE;

set_usb_mode(MODE_CHARGING);
set_usb_mode(MODE_CHARGING_FALLBACK);
/* since this is the fallback, we keep an indication
for the UI, as we are not really in charging mode.
*/
Expand Down

0 comments on commit 147dcc5

Please sign in to comment.