Skip to content
Permalink
Browse files
[devicelock] Switch export permission predicate to positive
It is confusing to have a function called usb_moded_get_export_permission()
that returns true when exporting is *not* permitted.

Flip the return value to increase code readability.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 14, 2017
1 parent 41b29f8 commit ad9208f80cb2726d0afa3e2401819aff996c18d6
Showing with 10 additions and 20 deletions.
  1. +3 −5 src/usb_moded-devicelock.c
  2. +1 −1 src/usb_moded-lock.h
  3. +2 −2 src/usb_moded-trigger.c
  4. +4 −12 src/usb_moded.c
@@ -98,16 +98,14 @@ static gboolean devicelock_is_available = FALSE;

/** Checks if the device is locked.
*
* @return 0 for unlocked, 1 for locked
* @return TRUE for unlocked, FALSE for locked
*
*/
int usb_moded_get_export_permission(void)
gboolean usb_moded_get_export_permission(void)
{
gboolean unlocked = (device_lock_state == DEVICE_LOCK_UNLOCKED);

// FIXME: this is reverse from what function name makes to expect

return unlocked ? 0 : 1;
return unlocked;
}

/* ========================================================================= *
@@ -26,6 +26,6 @@
*/

/*============================================================================= */
int usb_moded_get_export_permission(void);
gboolean usb_moded_get_export_permission(void);
gboolean start_devicelock_listener(void);
void stop_devicelock_listener(void);
@@ -211,7 +211,7 @@ static void udev_parse(struct udev_device *dev)
if(!strcmp(tmp, trigger))
{
#if defined MEEGOLOCK
if(!usb_moded_get_export_permission())
if(usb_moded_get_export_permission())
#endif /* MEEGOLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{
@@ -230,7 +230,7 @@ static void udev_parse(struct udev_device *dev)
/* for triggers without trigger value */
{
#if defined MEEGOLOCK
if(!usb_moded_get_export_permission())
if(usb_moded_get_export_permission())
#endif /* MEEGOLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{
@@ -258,9 +258,6 @@ void set_charger_connected(gboolean state)
void set_usb_connected_state(void)
{
char *mode_to_set;
#ifdef MEEGOLOCK
int export = 1; /* assume locked */
#endif /* MEEGOLOCK */

if(rescue_mode)
{
@@ -284,10 +281,10 @@ void set_usb_connected_state(void)

#ifdef MEEGOLOCK
/* check if we are allowed to export system contents 0 is unlocked */
export = usb_moded_get_export_permission();
gboolean can_export = usb_moded_get_export_permission();
/* We check also if the device is in user state or not.
If not we do not export anything. We presume ACT_DEAD charging */
if(mode_to_set && !export && is_in_user_state())
if(mode_to_set && can_export && is_in_user_state())
#else
if(mode_to_set)
#endif /* MEEGOLOCK */
@@ -337,11 +334,6 @@ void set_usb_mode(const char *mode)
/* set return to 1 to be sure to error out if no matching mode is found either */
int ret=1, net=0;

#ifdef MEEGOLOCK
/* Do a second check in case timer suspend causes a race issue */
int export = 1;
#endif

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

/* CHARGING AND FALLBACK CHARGING are always ok to set, so this can be done
@@ -377,9 +369,9 @@ void set_usb_mode(const char *mode)
/* In ACTDEAD export is always ok */
if(is_in_user_state())
{
export = usb_moded_get_export_permission();
gboolean can_export = usb_moded_get_export_permission();

if(export && !rescue_mode)
if(!can_export && !rescue_mode)
{
log_debug("Secondary device lock check failed. Not setting mode!\n");
goto end;

0 comments on commit ad9208f

Please sign in to comment.