Skip to content

Commit

Permalink
[usbmode] Do not assume "busy" means connected. Fixes JB#42976
Browse files Browse the repository at this point in the history
MCE uses general rule with usb modes: Apart from select modes known to
imply "disconnected" state, everything is assumed to mean "connected".
This misfires with recently introduced "busy" mode, which can occur also
when cable is physically detached from the device.

Use symbolic mode names from usb-moded devel package.

Add all known transient and stable modes to the lookup table.

Do not take "busy" and some other modes into account when evaluating
cable connected state.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 18, 2018
1 parent 93aa972 commit 16a54b3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -344,6 +344,7 @@ MODULE_PKG_NAMES += glib-2.0
MODULE_PKG_NAMES += gmodule-2.0
MODULE_PKG_NAMES += dbus-1
MODULE_PKG_NAMES += dbus-glib-1
MODULE_PKG_NAMES += usb_moded

MODULE_PKG_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(MODULE_PKG_NAMES))
MODULE_PKG_LDLIBS := $(shell $(PKG_CONFIG) --libs $(MODULE_PKG_NAMES))
Expand Down
56 changes: 40 additions & 16 deletions modules/usbmode.c
Expand Up @@ -28,6 +28,9 @@

#include <gmodule.h>

#include <usb_moded-dbus.h>
#include <usb_moded-modes.h>

/* ========================================================================= *
* CABLE_STATE
* ========================================================================= */
Expand Down Expand Up @@ -88,22 +91,40 @@ static const struct
usb_cable_state_t state;
} mode_lut[] =
{
{ "undefined", USB_CABLE_DISCONNECTED },
{ "USB disconnected", USB_CABLE_DISCONNECTED },
{ "charger_disconnected", USB_CABLE_DISCONNECTED },

{ "mass_storage", USB_CABLE_CONNECTED },
{ "data_in_use", USB_CABLE_CONNECTED },
{ "mtp_mode", USB_CABLE_CONNECTED },
{ "pc_suite", USB_CABLE_CONNECTED },
{ "USB connected", USB_CABLE_CONNECTED },
{ "charger_connected", USB_CABLE_CONNECTED },
{ "developer_mode", USB_CABLE_CONNECTED },
{ "charging_only", USB_CABLE_CONNECTED },
{ "dedicated_charger", USB_CABLE_CONNECTED },

{ "mode_requested_show_dialog", USB_CABLE_ASK_USER },
{ "ask", USB_CABLE_ASK_USER },
/* No cable attached */
{ MODE_UNDEFINED, USB_CABLE_DISCONNECTED },

/* Attach / detach dedicated charger */
{ CHARGER_CONNECTED, USB_CABLE_CONNECTED },
{ MODE_CHARGER, USB_CABLE_CONNECTED },
{ CHARGER_DISCONNECTED, USB_CABLE_DISCONNECTED },

/* Attach / detach pc cable */
{ USB_CONNECTED, USB_CABLE_CONNECTED },
{ MODE_CHARGING_FALLBACK, USB_CABLE_CONNECTED },
{ USB_CONNECTED_DIALOG_SHOW, USB_CABLE_ASK_USER },
{ MODE_ASK, USB_CABLE_ASK_USER },
{ MODE_MASS_STORAGE, USB_CABLE_CONNECTED },
{ MODE_MTP, USB_CABLE_CONNECTED },
{ MODE_PC_SUITE, USB_CABLE_CONNECTED },
{ MODE_DEVELOPER, USB_CABLE_CONNECTED },
{ MODE_CHARGING, USB_CABLE_CONNECTED },
{ MODE_HOST, USB_CABLE_CONNECTED },
{ MODE_CONNECTION_SHARING, USB_CABLE_CONNECTED },
{ MODE_DIAG, USB_CABLE_CONNECTED },
{ MODE_ADB, USB_CABLE_CONNECTED },
{ USB_DISCONNECTED, USB_CABLE_DISCONNECTED },

/* Busy can occur both on connect / after disconnect */
{ MODE_BUSY, USB_CABLE_UNDEF },

/* Events ignored while evaluating cable state */
{ DATA_IN_USE, USB_CABLE_UNDEF },
{ USB_REALLY_DISCONNECT, USB_CABLE_UNDEF },
{ USB_PRE_UNMOUNT, USB_CABLE_UNDEF },
{ RE_MOUNT_FAILED, USB_CABLE_UNDEF },
{ MODE_SETTING_FAILED, USB_CABLE_UNDEF },
{ UMOUNT_ERROR, USB_CABLE_UNDEF },
};

/** Map reported usb mode to usb_cable_state_t used within mce
Expand Down Expand Up @@ -154,6 +175,9 @@ usbmode_cable_state_update(const char *mode)
usb_cable_state_t prev = datapipe_get_gint(usb_cable_state_pipe);
usb_cable_state_t curr = usbmode_cable_state_lookup(mode);

if( curr == USB_CABLE_UNDEF )
goto EXIT;

if( prev == curr )
goto EXIT;

Expand Down
1 change: 1 addition & 0 deletions rpm/mce.spec
Expand Up @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(libngf0) >= 0.24
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: kernel-headers >= 2.6.32
BuildRequires: systemd
BuildRequires: pkgconfig(usb_moded)
# systemd has /etc/rpm/macros.systemd
# Automatically genereted libglib-2.0.so.0 dependency is not enough
Requires: glib2 >= 2.36.0
Expand Down

0 comments on commit 16a54b3

Please sign in to comment.