Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor devicelock related boot state query, and move it all
to its own dedicated file.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 21, 2013
1 parent 0f19dce commit 94f76bd
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 45 deletions.
4 changes: 3 additions & 1 deletion src/Makefile.am
Expand Up @@ -51,7 +51,9 @@ endif
if MEEGOLOCK
usb_moded_SOURCES += \
usb_moded-devicelock.h \
usb_moded-devicelock.c
usb_moded-devicelock.c \
usb_moded-dsme.h \
usb_moded-dsme.c
endif

if APP_SYNC
Expand Down
65 changes: 65 additions & 0 deletions src/usb_moded-dsme.c
@@ -0,0 +1,65 @@
/**
@file usb_moded-dsme.c
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
@author: Jonni Rainisto <jonni.rainisto@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>

#include "usb_moded-dsme.h"
#include "usb_moded-log.h"

/** Checks if the device is is USER-state.
*
* @return 1 if it is in USER-state, 0 for not
*
*/
int is_in_user_state(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 systembus (is_in_user_state)\n");
}

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("user state = %s\n", buffer);
if (strcmp(buffer, "USER")==0) ret = 1;
return(ret);
}

23 changes: 23 additions & 0 deletions src/usb_moded-dsme.h
@@ -0,0 +1,23 @@
/**
@file usb_moded-dsme.h
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

int is_in_user_state(void);
50 changes: 6 additions & 44 deletions src/usb_moded.c
Expand Up @@ -31,10 +31,6 @@
#ifdef NOKIA
#include <string.h>
#endif
#ifdef MEEGOLOCK
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#endif

#include <libkmod.h>

Expand All @@ -56,6 +52,9 @@
#include "usb_moded-network.h"
#include "usb_moded-mac.h"
#include "usb_moded-android.h"
#ifdef MEEGOLOCK
#include "usb_moded-dsme.h"
#endif

/* global definitions */

Expand All @@ -81,44 +80,6 @@ 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
*
* @param connected The connection status, true for connected
Expand Down Expand Up @@ -228,8 +189,9 @@ void set_usb_connected_state(void)
return;
}
#ifdef MEEGOLOCK
int user = isUserState(); // don't proceed on act_dead mode
if(mode_to_set && !export && user)
/* 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(mode_to_set && !export && is_in_user_state())
#else
if(mode_to_set)
#endif /* MEEGOLOCK */
Expand Down

0 comments on commit 94f76bd

Please sign in to comment.