Skip to content
Permalink
Browse files
[usb-moded] Set mode charging_fallback on user change. Fixes JB#50877
Bump version to 0.86.0+mer52
  • Loading branch information
salmelamike committed Feb 9, 2021
1 parent 42aa42b commit 5349e5b3c53624cf10d2694a38b4ae2943c1f17e
Showing with 311 additions and 16 deletions.
  1. +18 −0 .depend
  2. +3 −0 Makefile.custom
  3. +3 −3 config-static.h
  4. +1 −1 configure.ac
  5. +2 −1 rpm/usb-moded.spec
  6. +3 −1 src/Makefile.am
  7. +64 −10 src/usb_moded-control.c
  8. +1 −0 src/usb_moded-control.h
  9. +171 −0 src/usb_moded-user.c
  10. +33 −0 src/usb_moded-user.h
  11. +12 −0 src/usb_moded.c
18 .depend
@@ -488,6 +488,22 @@ src/usb_moded-worker.pic.o:\
src/usb_moded-worker.h\
src/usb_moded.h\

src/usb_moded-user.o:\
src/usb_moded-user.c\
src/usb_moded-user.h\
config-static.h\
src/usb_moded-log.h\
src/usb_moded-modes.h\
src/usb_moded-control.h\

src/usb_moded-user.pic.o:\
src/usb_moded-user.c\
src/usb_moded-user.h\
config-static.h\
src/usb_moded-log.h\
src/usb_moded-modes.h\
src/usb_moded-control.h\

src/usb_moded.o:\
src/usb_moded.c\
config-static.h\
@@ -514,6 +530,7 @@ src/usb_moded.o:\
src/usb_moded-trigger.h\
src/usb_moded-udev.h\
src/usb_moded-worker.h\
src/usb_moded-user.h\
src/usb_moded.h\

src/usb_moded.pic.o:\
@@ -542,6 +559,7 @@ src/usb_moded.pic.o:\
src/usb_moded-trigger.h\
src/usb_moded-udev.h\
src/usb_moded-worker.h\
src/usb_moded-user.h\
src/usb_moded.h\

utils/udev-search.o:\
@@ -204,6 +204,7 @@ usb_moded-OBJS += src/usb_moded-systemd.o
usb_moded-OBJS += src/usb_moded-trigger.o
usb_moded-OBJS += src/usb_moded-udev.o
usb_moded-OBJS += src/usb_moded-worker.o
usb_moded-OBJS += src/usb_moded-user.o

usb_moded-OBJS += dbus-gmain/dbus-gmain.o

@@ -273,6 +274,7 @@ CLEAN_SOURCES += src/usb_moded-trigger.c
CLEAN_SOURCES += src/usb_moded-udev.c
CLEAN_SOURCES += src/usb_moded-util.c
CLEAN_SOURCES += src/usb_moded-worker.c
CLEAN_SOURCES += src/usb_moded-user.c
CLEAN_SOURCES += src/usb_moded.c
CLEAN_SOURCES += utils/udev-search.c

@@ -302,6 +304,7 @@ CLEAN_HEADERS += src/usb_moded-systemd.h
CLEAN_HEADERS += src/usb_moded-trigger.h
CLEAN_HEADERS += src/usb_moded-udev.h
CLEAN_HEADERS += src/usb_moded-worker.h
CLEAN_HEADERS += src/usb_moded-user.h
CLEAN_HEADERS += src/usb_moded.h

# Files with whitespace issues
@@ -11,7 +11,7 @@
#define PACKAGE_NAME "usb_moded"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "usb_moded 0.86.0+mer51"
#define PACKAGE_STRING "usb_moded 0.86.0+mer52"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "usb_moded"
@@ -20,13 +20,13 @@
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "0.86.0+mer51"
#define PACKAGE_VERSION "0.86.0+mer52"

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Version number of package */
#define VERSION "0.86.0+mer51"
#define VERSION "0.86.0+mer52"

/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
@@ -1,4 +1,4 @@
AC_INIT([usb_moded], [0.86.0+mer51])
AC_INIT([usb_moded], [0.86.0+mer52])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AM_EXTRA_RECURSIVE_TARGETS([dbus-gmain])

@@ -1,5 +1,5 @@
Name: usb-moded
Version: 0.86.0+mer51
Version: 0.86.0+mer52
Release: 2
Summary: USB mode controller
License: LGPLv2
@@ -17,6 +17,7 @@ BuildRequires: pkgconfig(ssu-sysinfo)
BuildRequires: pkgconfig(dsme) >= 0.65.0
BuildRequires: pkgconfig(sailfishaccesscontrol)
BuildRequires: systemd
BuildRequires: libtool

Requires: lsof
Requires: usb-moded-configs
@@ -52,7 +52,9 @@ usb_moded_SOURCES = \
usb_moded-sigpipe.h \
usb_moded-sigpipe.c \
usb_moded-control.h \
usb_moded-control.c
usb_moded-control.c \
usb_moded-user.h \
usb_moded-user.c

if USE_MER_SSU
usb_moded_SOURCES += \
@@ -30,6 +30,7 @@
#include "usb_moded-log.h"
#include "usb_moded-modes.h"
#include "usb_moded-worker.h"
#include "usb_moded-user.h"

#include <string.h>
#include <stdlib.h>
@@ -52,6 +53,7 @@
* ------------------------------------------------------------------------- */

void control_rethink_usb_charging_fallback(void);
void control_user_changed (void);
const char *control_get_external_mode (void);
static void control_set_external_mode (const char *mode);
void control_clear_external_mode (void);
@@ -64,11 +66,14 @@ void control_clear_internal_mode (void);
void control_set_usb_mode (const char *mode);
void control_mode_switched (const char *mode);
void control_select_usb_mode (void);
void control_select_usb_mode_ex (bool user_changed);
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);
uid_t control_get_current_user (void);
uid_t control_get_user_for_mode (void);
void control_set_user_for_mode (uid_t uid);

/* ========================================================================= *
* Data
@@ -100,10 +105,56 @@ static char *control_internal_mode = NULL;
*/
static cable_state_t control_cable_state = CABLE_STATE_UNKNOWN;

/** Uid of the user that has set current USB mode
*/
static uid_t control_user_for_mode = UID_UNKNOWN;

/* ========================================================================= *
* Functions
* ========================================================================= */

/** Get uid of the user that set the current mode
*
* @return uid of user when current mode was set
*/
uid_t
control_get_user_for_mode(void)
{
return control_user_for_mode;
}

/** Set the uid of the user that set the current mode
*
* @param uid of current user
*/
void
control_set_user_for_mode(uid_t uid)
{
LOG_REGISTER_CONTEXT;

log_debug("control_user_for_mode: %d -> %d",
(int)control_user_for_mode, (int)uid);
control_user_for_mode = uid;
}

/** Check if we can/should enable charging fallback mode
*
* Called when user is changed
*/
void
control_user_changed(void)
{
LOG_REGISTER_CONTEXT;

/* Cable must be connected to a pc */
if( control_get_cable_state() != CABLE_STATE_PC_CONNECTED )
return;
bool user_changed = (control_get_current_user() != control_get_user_for_mode());
log_debug("control_user_changed: user_changed %d", user_changed);
if (user_changed)
control_select_usb_mode_ex(user_changed);
}

/** Check if we can/should leave charging fallback mode
*
* Called when device lock status, or device status (dsme)
@@ -281,6 +332,9 @@ void control_set_usb_mode(const char *mode)
/* Invalidate current mode for the duration of mode transition */
control_set_external_mode(MODE_BUSY);

/* Set mode owner to unknown until it has been changed */
control_set_user_for_mode(UID_UNKNOWN);

/* Propagate down to gadget config */
worker_request_hardware_mode(control_internal_mode);

@@ -307,6 +361,7 @@ void control_mode_switched(const char *mode)

/* Propagate up to D-Bus */
control_update_external_mode();
control_set_user_for_mode(control_get_current_user());

return;
}
@@ -316,7 +371,7 @@ void control_mode_switched(const char *mode)
* gauge what mode to enter and then call control_set_usb_mode()
*
*/
void control_select_usb_mode(void)
void control_select_usb_mode_ex(bool user_changed)
{
LOG_REGISTER_CONTEXT;

@@ -366,20 +421,25 @@ void control_select_usb_mode(void)
}
}

if( mode_to_set && usbmoded_can_export() ) {
if( mode_to_set && usbmoded_can_export() && !user_changed ) {
control_set_usb_mode(mode_to_set);
}
else {
/* config is corrupted or we do not have a mode configured, fallback to charging
* We also fall back here in case the device is locked and we do not
* export the system contents. Or if we are in acting dead mode.
* export the system contents, if we are in acting dead mode or changing user.
*/
control_set_usb_mode(MODE_CHARGING_FALLBACK);
}
EXIT:
free(mode_to_set);
}

void control_select_usb_mode(void)
{
control_select_usb_mode_ex(false);
}

/** set the usb connection status
*
* @param cable_state CABLE_STATE_DISCONNECTED, ...
@@ -463,11 +523,5 @@ bool control_get_connection_state(void)
*/
uid_t control_get_current_user(void)
{
#ifdef SAILFISH_ACCESS_CONTROL
uid_t uid = UID_UNKNOWN;
sd_seat_get_active("seat0", 0, &uid);
return uid;
#else
return 0;
#endif
return user_get_current_user();
}
@@ -37,6 +37,7 @@
* ------------------------------------------------------------------------- */

void control_rethink_usb_charging_fallback(void);
void control_user_changed (void);
const char *control_get_external_mode (void);
void control_clear_external_mode (void);
const char *control_get_target_mode (void);

0 comments on commit 5349e5b

Please sign in to comment.