Skip to content

Commit

Permalink
Fix devicelock to work with lipstick
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonni Rainisto committed Aug 21, 2013
1 parent 027c0a6 commit ed47da3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rpm/usb-moded.spec
Expand Up @@ -210,7 +210,7 @@ modes with the android gadget driver)

%build
%autogen
%configure --enable-app-sync --enable-udev --enable-n900
%configure --enable-app-sync --enable-udev --enable-n900 --enable-meegodevlock
make all doc %{?_smp_mflags}

%install
Expand Down
18 changes: 10 additions & 8 deletions src/usb_moded-devicelock.c
Expand Up @@ -61,13 +61,12 @@ int usb_moded_get_export_permission(void)

if ((msg = dbus_message_new_method_call(DEVICELOCK_SERVICE, DEVICELOCK_REQUEST_PATH, DEVICELOCK_REQUEST_IF, DEVICELOCK_STATE_REQ)) != NULL)
{
dbus_message_append_args (msg, DBUS_TYPE_INT32, &arg, DBUS_TYPE_INVALID);
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn_devicelock, msg, -1, NULL)) != NULL)
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn_devicelock, msg, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(msg);
dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(msg);
}
dbus_connection_unref(dbus_conn_devicelock);

Expand Down Expand Up @@ -124,11 +123,14 @@ static DBusHandlerResult devicelock_unlocked_cb(DBusConnection *conn, DBusMessag
else if( !strcmp(member, "stateChanged") )
{
dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
log_debug("Devicelock state changed. New state = %d\n", ret);
log_debug("Devicelock state changed. New state = %d\n", ret);
if(ret == 0 && get_usb_connection_state() == 1 )
{
if(!strcmp(get_usb_mode(), MODE_UNDEFINED) || !strcmp(get_usb_mode(), MODE_CHARGING))
log_debug("usb_mode %d\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();
}
}
}
result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
Expand Down
47 changes: 43 additions & 4 deletions src/usb_moded.c
Expand Up @@ -31,6 +31,10 @@
#ifdef NOKIA
#include <string.h>
#endif
#ifdef MEEGOLOCK
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#endif

#include <libkmod.h>

Expand Down Expand Up @@ -77,6 +81,43 @@ static void usage(void);


/* ============= Implementation starts here =========================================== */
#ifdef MEEGOLOCK
/** Checks if the device is is USER-state.
*
* @return 1 if it is in USER-state, 0 for not
*
*/
int isUserState(void)
{
DBusConnection *dbus_conn = NULL;
DBusMessage *msg = NULL, *reply = NULL;
DBusError error;
int ret = 0;
char* buffer = NULL;

dbus_error_init(&error);

if( (dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == 0 )
{
log_err("Could not connect to dbus for isUserState()");
}

if ((msg = dbus_message_new_method_call("com.nokia.dsme", "/request", "com.nokia.dsme.request", "get_state")) != NULL)
{
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn, msg, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, &error, DBUS_TYPE_STRING, &buffer, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(msg);
}
dbus_connection_unref(dbus_conn);

log_debug("is user state = %s\n", buffer);
if (strcmp(buffer, "USER")==0) ret = 1;
return(ret);
}
#endif

/** set the usb connection status
*
Expand Down Expand Up @@ -187,10 +228,8 @@ void set_usb_connected_state(void)
return;
}
#ifdef MEEGOLOCK
int act_dead = 0;
/* check if we are in acting dead or not, /tmp/USER will not exist in acting dead */
act_dead = access("/tmp/USER", R_OK);
if(mode_to_set && !export && !act_dead)
int user = isUserState(); // don't proceed on act_dead mode
if(mode_to_set && !export && user)
#else
if(mode_to_set)
#endif /* MEEGOLOCK */
Expand Down

0 comments on commit ed47da3

Please sign in to comment.