Skip to content

Commit

Permalink
[worker] Fallback to undefined on cable disconnect. Fixes JB#43781
Browse files Browse the repository at this point in the history
Cable disconnect during mode transition is handled via the code same path as
errors in mode setting actions - which leads to usb-moded declaring charging
mode despite not having any usb connection.

Check the latest requested usb mode on failures and use it to choose between
charging and undefined fallback modes.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 13, 2018
1 parent 29d2f61 commit 3b2cb9c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/usb_moded-worker.c
Expand Up @@ -574,7 +574,20 @@ worker_switch_to_mode(const char *mode)
worker_set_usb_mode_data(NULL);
}

override = MODE_CHARGING;
/* From usb configuration point of view MODE_UNDEFINED and
* MODE_CHARGING are the same, but for the purposes of exposing
* a sane state over D-Bus we need to differentiate between
* "failure to set mode" and "aborting mode setting due to cable
* disconnect" by inspecting whether target mode has been
* switched to undefined.
*/
WORKER_LOCKED_ENTER;
const char *requested = worker_get_requested_mode_locked();
if( !g_strcmp0(requested, MODE_UNDEFINED) )
override = MODE_UNDEFINED;
else
override = MODE_CHARGING;
WORKER_LOCKED_LEAVE;
log_warning("mode setting failed, try %s", override);

CHARGE:
Expand All @@ -597,8 +610,9 @@ worker_switch_to_mode(const char *mode)

WORKER_LOCKED_ENTER;
if( override ) {
worker_set_activated_mode_locked(override);
worker_set_requested_mode_locked(override);
override = common_map_mode_to_hardware(override);
worker_set_activated_mode_locked(override);
}
else {
worker_set_activated_mode_locked(mode);
Expand Down

0 comments on commit 3b2cb9c

Please sign in to comment.