Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #18 from nemomobile/22320
[usb] Make sure the dialog shows after unlocking the devicelock
  • Loading branch information
philippedeswert committed Aug 27, 2014
2 parents a889b66 + 39440bf commit 175c784
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/usb_moded-dbus.c
Expand Up @@ -76,6 +76,9 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
{
const char *mode = get_usb_mode();

/* To the outside we want to keep CHARGING and CHARGING_FALLBACK the same */
if(!strcmp(MODE_CHARGING_FALLBACK, mode))
mode = strdup(MODE_CHARGING);
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
}
Expand Down
11 changes: 7 additions & 4 deletions src/usb_moded-devicelock.c
Expand Up @@ -117,6 +117,7 @@ int stop_devicelock_listener(void)

static DBusHandlerResult devicelock_unlocked_cb(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
/* regardless what happens, we want that other programs get a chance to process this */
DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
const char *interface = dbus_message_get_interface(msg);
const char *member = dbus_message_get_member(msg);
Expand All @@ -140,13 +141,15 @@ static DBusHandlerResult devicelock_unlocked_cb(DBusConnection *conn, DBusMessag
if(ret == 0 && get_usb_connection_state() == 1 )
{
log_debug("usb_mode %s\n", get_usb_mode());
if(!strcmp(get_usb_mode(), MODE_UNDEFINED) || !strcmp(get_usb_mode(), MODE_CHARGING)) {
log_debug("set_usb");
set_usb_connected_state();
/* if the mode is MODE_CHARGING_FALLBACK we know the user has not selected any mode, in case it
things are still undefined it cannot hurt to try again to set a mode */
if(!strcmp(get_usb_mode(), MODE_UNDEFINED) || !strcmp(get_usb_mode(), MODE_CHARGING_FALLBACK))
{
log_debug("set_usb");
set_usb_connected_state();
}
}
}
result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

cleanup:
return result;
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-modes.h
Expand Up @@ -24,6 +24,7 @@
#define MODE_MASS_STORAGE "mass_storage"
#define MODE_OVI_SUITE "ovi_suite"
#define MODE_CHARGING "charging_only"
#define MODE_CHARGING_FALLBACK "charging_only_fallback"
#define MODE_UNDEFINED "undefined"
#define MODE_ASK "ask"
#define MODE_DEVELOPER "developer_mode"
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-modesetting.c
Expand Up @@ -533,7 +533,7 @@ int usb_moded_mode_cleanup(const char *module)
{
/* no clean-up needs to be done when we come from charging mode. We need
to check since we use fake mass-storage for charging */
if(!strcmp(MODE_CHARGING, get_usb_mode()))
if(!strcmp(MODE_CHARGING, get_usb_mode()) || !strcmp(MODE_CHARGING_FALLBACK, get_usb_mode()))
return 0;
unset_mass_storage_mode(NULL);
}
Expand Down
74 changes: 38 additions & 36 deletions src/usb_moded.c
Expand Up @@ -69,7 +69,6 @@ extern int log_type;
gboolean rescue_mode = FALSE;
gboolean diag_mode = FALSE;
gboolean hw_fallback = FALSE;
gboolean charging_mode_set = FALSE;
gboolean android_broken_usb = FALSE;
#ifdef SYSTEMD
static gboolean systemd_notify = FALSE;
Expand Down Expand Up @@ -158,13 +157,13 @@ static gboolean set_disconnected(gpointer data)
/* signal usb disconnected */
usb_moded_send_signal(USB_DISCONNECTED);
/* unload modules and general cleanup if not charging */
if(strcmp(get_usb_mode(), MODE_CHARGING))
if(strcmp(get_usb_mode(), MODE_CHARGING) ||
strcmp(get_usb_mode(), MODE_CHARGING_FALLBACK))
usb_moded_mode_cleanup(get_usb_module());
/* Nothing else as we do not need to do anything for cleaning up charging mode */
usb_moded_module_cleanup(get_usb_module());
set_usb_mode(MODE_UNDEFINED);
#endif /* NOKIA */
charging_mode_set = FALSE;

}
return FALSE;
Expand All @@ -177,12 +176,12 @@ if(!get_usb_connection_state())
{
log_debug("Resetting connection data after HUP\n");
/* unload modules and general cleanup if not charging */
if(strcmp(get_usb_mode(), MODE_CHARGING))
if(strcmp(get_usb_mode(), MODE_CHARGING) ||
strcmp(get_usb_mode(), MODE_CHARGING_FALLBACK))
usb_moded_mode_cleanup(get_usb_module());
/* Nothing else as we do not need to do anything for cleaning up charging mode */
usb_moded_module_cleanup(get_usb_module());
set_usb_mode(MODE_UNDEFINED);
charging_mode_set = FALSE;
}
return FALSE;

Expand Down Expand Up @@ -262,10 +261,6 @@ void set_usb_connected_state(void)

if(!strcmp(MODE_ASK, mode_to_set))
{
/* if charging mode was set we do not do anything as we might get here
due to a devicelock state change */
if(charging_mode_set)
return;
/* send signal, mode will be set when the dialog service calls
the set_mode method call.
*/
Expand All @@ -285,7 +280,7 @@ void set_usb_connected_state(void)
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.
*/
set_usb_mode(MODE_CHARGING);
set_usb_mode(MODE_CHARGING_FALLBACK);
}
end:
free((void *)mode_to_set);
Expand All @@ -301,28 +296,14 @@ 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

/* check if we are allowed to export system contents 0 is unlocked */
/* In ACTDEAD export is always ok */
if(is_in_user_state())
{
export = usb_moded_get_export_permission();

if(export && strcmp(mode, MODE_CHARGING) && !rescue_mode)
{
log_debug("Secondary device lock check failed. Not setting mode!\n");
goto end;
}
}
#endif /* MEEGOLOCK */

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

if(!strcmp(mode, MODE_CHARGING))
/* CHARGING AND FALLBACK CHARGING are always ok to set, so this can be done
before the optional second device lock check */
if(!strcmp(mode, MODE_CHARGING) || !strcmp(mode, MODE_CHARGING_FALLBACK))
{
check_module_state(MODULE_MASS_STORAGE);
/* for charging we use a fake file_storage (blame USB certification for this insanity */
Expand All @@ -335,10 +316,29 @@ void set_usb_mode(const char *mode)
set_usb_module(MODULE_NONE);
ret = set_android_charging_mode();
}
charging_mode_set = TRUE;
goto end;
}
else if(!strcmp(mode, MODE_ASK) || !strcmp(mode, MODE_CHARGER))

#ifdef MEEGOLOCK
/* check if we are allowed to export system contents 0 is unlocked */
/* In ACTDEAD export is always ok */
if(is_in_user_state())
{
export = usb_moded_get_export_permission();

if(export && !rescue_mode)
{
log_debug("Secondary device lock check failed. Not setting mode!\n");
goto end;
}
}
#endif /* MEEGOLOCK */

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

/* nothing needs to be done for these modes, apart from the
signalling at the end */
if(!strcmp(mode, MODE_ASK) || !strcmp(mode, MODE_CHARGER))
{
ret = 0;
goto end;
Expand Down Expand Up @@ -382,7 +382,11 @@ void set_usb_mode(const char *mode)
log_debug("Network setting failed!\n");
free(current_mode.mode);
current_mode.mode = strdup(mode);
usb_moded_send_signal(get_usb_mode());
/* CHARGING_FALLBACK is an internal mode not to be broadcasted outside */
if(!strcmp(mode, MODE_CHARGING_FALLBACK))
usb_moded_send_signal(MODE_CHARGING);
else
usb_moded_send_signal(get_usb_mode());
}

/** check if a given usb_mode exists
Expand All @@ -394,7 +398,8 @@ void set_usb_mode(const char *mode)
int valid_mode(const char *mode)
{

/* MODE_ASK and MODE_CHARGER are not modes that are settable seen their special status */
/* MODE_ASK, MODE_CHARGER and MODE_CHARGING_FALLBACK are not modes that are settable seen their special 'internal' status
so we only check the modes that are announed outside. Only exception is the built in MODE_CHARGING */
if(!strcmp(MODE_CHARGING, mode))
return(0);
else
Expand Down Expand Up @@ -580,17 +585,14 @@ static gboolean charging_fallback(gpointer data)
if(strcmp(get_usb_mode(), MODE_ASK) != 0)
return FALSE;

set_usb_mode(MODE_CHARGING);
set_usb_mode(MODE_CHARGING_FALLBACK);
/* since this is the fallback, we keep an indication
for the UI, as we are not really in charging mode.
*/
free(current_mode.mode);
current_mode.mode = strdup(MODE_ASK);
current_mode.data = NULL;
charging_timeout = 0;
/* for extra safety we explicitly set charging_mode_set
to false as the mode was not chosen */
charging_mode_set = FALSE;
log_info("Falling back on charging mode.\n");

return(FALSE);
Expand Down

0 comments on commit 175c784

Please sign in to comment.