Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[udev] Suppress repetitive property warnings. Fixes JB#40394
Usb-moded expects to see POWER_SUPPLY_PRESENT and POWER_SUPPLY_TYPE
properties defined for usb power-supply devices. When this is not
the case, it emits warnings and applies various fallbacks. Since the
properties get re-evaluated periodically, this also leads to the
same warnings being repeated.

Refactor the code so that in default verbosity the property warnings
are emitted only during what looks like cable connect / disconnect.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Dec 1, 2017
1 parent 9919b0f commit 0d5a10b
Showing 1 changed file with 49 additions and 25 deletions.
74 changes: 49 additions & 25 deletions src/usb_moded-udev.c
Expand Up @@ -379,33 +379,55 @@ static void schedule_cable_connection_timeout(void)

static void udev_parse(struct udev_device *dev, bool initial)
{
const char *tmp = 0;
/* udev properties we are interested in */
const char *power_supply_present = 0;
const char *power_supply_online = 0;
const char *power_supply_type = 0;

/* Assume there is no usb connection until proven otherwise */
bool connected = false;

/* Unless debug logging has been request via command line,
* suppress warnings about potential property issues and/or
* fallback strategies applied (to avoid spamming due to the
* code below seeing the same property values over and over
* again also in stable states).
*/
bool warnings = log_p(LOG_DEBUG);

/*
* Check for present first as some drivers use online for when charging
* is enabled
*/
tmp = udev_device_get_property_value(dev, "POWER_SUPPLY_PRESENT");
if (!tmp) {
tmp = udev_device_get_property_value(dev, "POWER_SUPPLY_ONLINE");
log_warning("Using online property\n");
power_supply_present = udev_device_get_property_value(dev, "POWER_SUPPLY_PRESENT");
if (!power_supply_present) {
power_supply_present =
power_supply_online = udev_device_get_property_value(dev, "POWER_SUPPLY_ONLINE");
}

if (!tmp) {
if (!power_supply_present) {
log_err("No usable power supply indicator\n");
/* TRY AGAIN?
return; */
exit(1);
}

if (!strcmp(power_supply_present, "1"))
connected = true;

/* Transition period = Connection status derived from udev
* events disagrees with usb-moded side bookkeeping. */
if (connected != get_usb_connection_state()) {
/* Enable udev property diagnostic logging */
warnings = true;
/* Block suspend briefly */
delay_suspend();
}

/* disconnect */
if (strcmp(tmp, "1")) {
if (!connected) {
log_debug("DISCONNECTED");

/* Block suspend briefly on connection state change */
if (get_usb_connection_state())
delay_suspend();

cancel_cable_connection_timeout();

if (charger) {
Expand All @@ -422,41 +444,43 @@ static void udev_parse(struct udev_device *dev, bool initial)
charger = 0;
}
else {
/* Block suspend briefly on connection state change */
if (!get_usb_connection_state())
delay_suspend();
if (warnings && power_supply_online)
log_warning("Using online property\n");

tmp = udev_device_get_property_value(dev, "POWER_SUPPLY_TYPE");
power_supply_type = udev_device_get_property_value(dev, "POWER_SUPPLY_TYPE");
/*
* Power supply type might not exist also :(
* Send connected event but this will not be able
* to discriminate between charger/cable.
*/
if (!tmp) {
log_warning("Fallback since cable detection might not be accurate. "
"Will connect on any voltage on charger.\n");
if (!power_supply_type) {
if( warnings )
log_warning("Fallback since cable detection might not be accurate. "
"Will connect on any voltage on charger.\n");
schedule_cable_connection_timeout();
goto cleanup;
}

log_debug("CONNECTED - POWER_SUPPLY_TYPE = %s", tmp);
log_debug("CONNECTED - POWER_SUPPLY_TYPE = %s", power_supply_type);

if (!strcmp(tmp, "USB") || !strcmp(tmp, "USB_CDP")) {
if (!strcmp(power_supply_type, "USB") ||
!strcmp(power_supply_type, "USB_CDP")) {
if( initial )
setup_cable_connection();
else
schedule_cable_connection_timeout();
}
else if (!strcmp(tmp, "USB_DCP") ||
!strcmp(tmp, "USB_HVDCP") ||
!strcmp(tmp, "USB_HVDCP_3")) {
else if (!strcmp(power_supply_type, "USB_DCP") ||
!strcmp(power_supply_type, "USB_HVDCP") ||
!strcmp(power_supply_type, "USB_HVDCP_3")) {
setup_charger_connection();
}
else if( !strcmp(tmp, "Unknown")) {
else if( !strcmp(power_supply_type, "Unknown")) {
// nop
}
else {
log_warning("unhandled power supply type: %s", tmp);
if (warnings)
log_warning("unhandled power supply type: %s", power_supply_type);
}
}

Expand Down

0 comments on commit 0d5a10b

Please sign in to comment.