Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[control] Limit available modes with last seen user
Add method to set last seen user. Use that information to limit the
implicitly set modes. If no user has been seen yet, fallback to
charging only mode.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Jan 16, 2020
1 parent b7af2d3 commit 8abafa0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/usb_moded-control.c
Expand Up @@ -58,6 +58,7 @@ void control_set_cable_state (cable_state_t cable_state);
cable_state_t control_get_cable_state (void);
void control_clear_cable_state (void);
bool control_get_connection_state (void);
void control_set_last_seen_user (uid_t uid);

/* ========================================================================= *
* Data
Expand Down Expand Up @@ -89,6 +90,12 @@ static char *control_internal_mode = NULL;
*/
static cable_state_t control_cable_state = CABLE_STATE_UNKNOWN;

/** Last user seen
*
* Defaults to invalid user which has no rights.
*/
static uid_t control_last_seen_user = (uid_t)-1;

/* ========================================================================= *
* Functions
* ========================================================================= */
Expand Down Expand Up @@ -337,12 +344,17 @@ void control_select_usb_mode(void)
/* If there is only one allowed mode, use it without
* going through ask-mode */
if( !strcmp(MODE_ASK, mode_to_set) ) {
// FIXME free() vs g_free() conflict
gchar *available = common_get_mode_list(AVAILABLE_MODES_LIST, 0);
if( *available && !strchr(available, ',') ) {
free(mode_to_set), mode_to_set = available, available = 0;
if( control_last_seen_user == (uid_t)-1 ) {
/* Use charging only if no user has been seen */
free(mode_to_set), mode_to_set = 0;
} else {
// FIXME free() vs g_free() conflict
gchar *available = common_get_mode_list(AVAILABLE_MODES_LIST, control_last_seen_user);
if( *available && !strchr(available, ',') ) {
free(mode_to_set), mode_to_set = available, available = 0;
}
g_free(available);
}
g_free(available);
}

if( mode_to_set && usbmoded_can_export() ) {
Expand Down Expand Up @@ -431,3 +443,12 @@ bool control_get_connection_state(void)
}
return connected;
}

/** Set the last seen user
*
* @param uid of last seen user, controls implicitly set modes
*/
void control_set_last_seen_user(uid_t uid)
{
control_last_seen_user = uid;
}
1 change: 1 addition & 0 deletions src/usb_moded-control.h
Expand Up @@ -49,5 +49,6 @@ void control_set_cable_state (cable_state_t cable_state);
cable_state_t control_get_cable_state (void);
void control_clear_cable_state (void);
bool control_get_connection_state (void);
void control_set_last_seen_user (uid_t uid);

#endif /* USB_MODED_CONTROL_H_ */

0 comments on commit 8abafa0

Please sign in to comment.