Commit ad9208f8 authored by spiiroin's avatar spiiroin

[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: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 41b29f86
...@@ -98,16 +98,14 @@ static gboolean devicelock_is_available = FALSE; ...@@ -98,16 +98,14 @@ static gboolean devicelock_is_available = FALSE;
/** Checks if the device is locked. /** 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); gboolean unlocked = (device_lock_state == DEVICE_LOCK_UNLOCKED);
// FIXME: this is reverse from what function name makes to expect return unlocked;
return unlocked ? 0 : 1;
} }
/* ========================================================================= * /* ========================================================================= *
......
...@@ -26,6 +26,6 @@ ...@@ -26,6 +26,6 @@
*/ */
/*============================================================================= */ /*============================================================================= */
int usb_moded_get_export_permission(void); gboolean usb_moded_get_export_permission(void);
gboolean start_devicelock_listener(void); gboolean start_devicelock_listener(void);
void stop_devicelock_listener(void); void stop_devicelock_listener(void);
...@@ -211,7 +211,7 @@ static void udev_parse(struct udev_device *dev) ...@@ -211,7 +211,7 @@ static void udev_parse(struct udev_device *dev)
if(!strcmp(tmp, trigger)) if(!strcmp(tmp, trigger))
{ {
#if defined MEEGOLOCK #if defined MEEGOLOCK
if(!usb_moded_get_export_permission()) if(usb_moded_get_export_permission())
#endif /* MEEGOLOCK */ #endif /* MEEGOLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0) if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{ {
...@@ -230,7 +230,7 @@ static void udev_parse(struct udev_device *dev) ...@@ -230,7 +230,7 @@ static void udev_parse(struct udev_device *dev)
/* for triggers without trigger value */ /* for triggers without trigger value */
{ {
#if defined MEEGOLOCK #if defined MEEGOLOCK
if(!usb_moded_get_export_permission()) if(usb_moded_get_export_permission())
#endif /* MEEGOLOCK */ #endif /* MEEGOLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0) if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{ {
......
...@@ -258,9 +258,6 @@ void set_charger_connected(gboolean state) ...@@ -258,9 +258,6 @@ void set_charger_connected(gboolean state)
void set_usb_connected_state(void) void set_usb_connected_state(void)
{ {
char *mode_to_set; char *mode_to_set;
#ifdef MEEGOLOCK
int export = 1; /* assume locked */
#endif /* MEEGOLOCK */
if(rescue_mode) if(rescue_mode)
{ {
...@@ -284,10 +281,10 @@ void set_usb_connected_state(void) ...@@ -284,10 +281,10 @@ void set_usb_connected_state(void)
#ifdef MEEGOLOCK #ifdef MEEGOLOCK
/* check if we are allowed to export system contents 0 is unlocked */ /* 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. /* 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 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 #else
if(mode_to_set) if(mode_to_set)
#endif /* MEEGOLOCK */ #endif /* MEEGOLOCK */
...@@ -337,11 +334,6 @@ void set_usb_mode(const char *mode) ...@@ -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 */ /* set return to 1 to be sure to error out if no matching mode is found either */
int ret=1, net=0; 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); log_debug("Setting %s\n", mode);
/* CHARGING AND FALLBACK CHARGING are always ok to set, so this can be done /* 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) ...@@ -377,9 +369,9 @@ void set_usb_mode(const char *mode)
/* In ACTDEAD export is always ok */ /* In ACTDEAD export is always ok */
if(is_in_user_state()) 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"); log_debug("Secondary device lock check failed. Not setting mode!\n");
goto end; goto end;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment