Commit 1bcc68ee authored by phdeswer's avatar phdeswer

Merge branch 'hide-mode' into 'master'

[modes] Add possibility to hide modes from the UI



See merge request !2
parents df78d2fb 9c3e0f2c
AC_INIT([usb_moded], [0.85.2])
AC_INIT([usb_moded], [0.85.3])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_CONFIG_HEADER([config.h])
......
usb-moded (0.85.2) unstable; urgency=low
* [hidden modes] Add support for hidden modes. Fixes: MER#1540
-- Philippe De Swert <philippedeswert@gmail.com> Tue 22 Mar 23:24:01 EET 2016
usb-moded (0.85.2) unstable; urgency=low
* [devel] Fix DIAG_MODE definition. Fixes: JB#32805
......
......@@ -14,9 +14,11 @@ Thus if you need this functionality, usb_moded needs to be started
with the session.
(functionality not verified yet on multi-user setups. See TODO)
Usb cable detection is supported by several different methods.
Old deprecated hal, through Nokia's own battery monitoring bme,
or the preferred udev option. (This has to be chosen at compile time)
Usb cable detection is handled with udev, it even tries to guess
which is the correct power_supply entry to use.
A Qt lib to interact with usb-moded is available here:
https://git.merproject.org/mer-core/libusb-moded-qt
Starting usb_moded
-------------------
......@@ -398,3 +400,19 @@ For this are the
Network options. nat_interface documents which interfaces the internet facing modem. noroaming when set to 1
will prohibit enabling the modem interface in case you are roaming (this requires ofono).
hidden modes
------------
Sometimes it is useful to hide modes from the ui (the mode can be queried through dbus).
To hide modes this can be done by adding a hide= key to the
[usbmode] section. If you want to hide more modes this needs
to be a comma separated list.
For example
[usbmode]
hide=developer_mode,bastard_mode
Modes can also be set and removed through dbus (one mode at a time)
See usb_moded_util (-i and -u)
......@@ -26,4 +26,6 @@
char * get_mode_setting(void);
set_config_result_t set_mode_setting(const char *mode);
set_config_result_t set_hide_mode_setting(const char *mode);
set_config_result_t set_unhide_mode_setting(const char *mode);
set_config_result_t set_network_setting(const char *config, const char *setting);
......@@ -409,6 +409,73 @@ set_config_result_t set_mode_setting(const char *mode)
return (set_config_setting(MODE_SETTING_ENTRY, MODE_SETTING_KEY, mode));
}
/* Builds the string used for hidden modes, when hide set to one builds the
new string of hidden modes when adding one, otherwise it will remove one */
static const char * make_hidden_modes_string(const char *hidden, int hide)
{
GString *modelist_str;
char *hidden_modes_list;
gchar **hidden_mode_split;
int i;
hidden_modes_list = get_hidden_modes();
if(hidden_modes_list)
{
hidden_mode_split = g_strsplit(hidden_modes_list, ",", 0);
}
else
{
/* no hidden modes yet. So just return the original string */
return hidden;
}
modelist_str = g_string_new(NULL);
for(i = 0; hidden_mode_split[i] != NULL; i++)
{
if(!strcmp(hidden_mode_split[i], hidden))
{
/* if hiding a mode that is already hidden do nothing */
if(hide)
return(NULL);
if(!hide)
continue;
}
modelist_str = g_string_append(modelist_str, hidden_mode_split[i]);
if(hidden_mode_split[i+1] != NULL)
modelist_str = g_string_append(modelist_str, ",");
}
if(hide)
{
modelist_str = g_string_append(modelist_str, ",");
modelist_str = g_string_append(modelist_str, hidden);
}
g_strfreev(hidden_mode_split);
return(g_string_free(modelist_str, FALSE));
}
set_config_result_t set_hide_mode_setting(const char *mode)
{
set_config_result_t ret;
ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 1));
if(ret == SET_CONFIG_UPDATED)
send_supported_modes_signal();
return(ret);
}
set_config_result_t set_unhide_mode_setting(const char *mode)
{
set_config_result_t ret;
ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 0));
if(ret == SET_CONFIG_UPDATED)
send_supported_modes_signal();
return(ret);
}
/*
* @param config : the key to be set
* @param setting : The value to be set
......@@ -515,7 +582,7 @@ int conf_file_merge(void)
{
GDir *confdir;
struct stat fileinfo, dir;
char *mode = 0, *ip = 0, *gateway = 0, *udev = 0;
char *mode = 0, *ip = 0, *gateway = 0, *udev = 0, *hide = 0;
gchar *filename_full;
const gchar *filename;
GString *keyfile_string = NULL;
......@@ -575,8 +642,11 @@ int conf_file_merge(void)
mode = get_mode_setting();
/* store udev path (especially important for the upgrade path */
udev = find_udev_path();
/* store network info */
ip = get_conf_string(NETWORK_ENTRY, NETWORK_IP_KEY);
gateway = get_conf_string(NETWORK_ENTRY, NETWORK_GATEWAY_KEY);
/* store hidden modes */
hide = get_hidden_modes();
continue;
}
/* load contents of file, if it fails skip to next one */
......@@ -617,6 +687,9 @@ next:
set_network_setting(NETWORK_IP_KEY, ip);
if(gateway)
set_network_setting(NETWORK_GATEWAY_KEY, gateway);
/* re-add hidden modes info */
if(hide)
set_hide_mode_setting(hide);
}
else
ret = 1;
......@@ -655,6 +728,11 @@ char * get_android_product_id(void)
return(get_conf_string(ANDROID_ENTRY, ANDROID_PRODUCT_ID_KEY));
}
char * get_hidden_modes(void)
{
return(get_conf_string(MODE_SETTING_ENTRY, MODE_HIDE_KEY));
}
int check_android_section(void)
{
GKeyFile *settingsfile;
......
......@@ -57,6 +57,7 @@
#define ANDROID_VENDOR_ID_KEY "idVendor"
#define ANDROID_PRODUCT_KEY "iProduct"
#define ANDROID_PRODUCT_ID_KEY "idProduct"
#define MODE_HIDE_KEY "hide"
const char * find_mounts(void);
int find_sync(void);
......@@ -78,6 +79,8 @@ char * get_android_vendor_id(void);
char * get_android_product(void);
char * get_android_product_id(void);
char * get_hidden_modes(void);
int check_android_section(void);
int is_roaming_not_allowed(void);
......
This diff is collapsed.
......@@ -43,10 +43,8 @@
#define USB_MODE_RESCUE_OFF "rescue_off" /* turns rescue mode off so normal mode selection is restored */
#define USB_MODE_CONFIG_GET "get_config" /* returns the mode set in the config */
#define USB_MODE_LIST "get_modes" /* returns a comma-separated list of supported modes for ui's */
/**
* @credential usb-moded::USBControl Credential needed to be able to call the set_mode or set_config methods
**/
#define USB_MODE_HIDE "hide_mode" /* hide a mode */
#define USB_MODE_UNHIDE "unhide_mode" /* unhide a mode */
#define USB_MODE_STATE_SET "set_mode" /* set a mode (only works when connected) */
#define USB_MODE_CONFIG_SET "set_config" /* set the mode that needs to be activated in the config file */
#define USB_MODE_NETWORK_SET "net_config" /* set the network config in the config file */
......
......@@ -44,3 +44,5 @@
**/
#define MODE_CHARGING_FALLBACK "charging_only_fallback"
#define MODE_CHARGER "dedicated_charger"
void send_supported_modes_signal(void);
......@@ -615,8 +615,10 @@ static int connman_fill_connection_data(DBusMessage *reply, struct ipforward_dat
/* if cellular not online, connect it */
if(strcmp(string, "online"))
{
log_debug("Not online. Turning on cellular data connection.\n");
return(1);
/* if in ready state connection might be up anyway */
if(strcmp(string, "ready"))
log_debug("Not online. Turning on cellular data connection.\n");
return(1);
}
}
......
......@@ -181,7 +181,61 @@ static int set_mode_config (char *mode)
printf("mode set in the configuration file = %s\n", ret);
return 0;
}
/* not everything went as planned, return error */
return 1;
}
static int set_hide_mode_config (char *mode)
{
DBusMessage *req = NULL, *reply = NULL;
char *ret = 0;
printf("Trying to hide the following mode %s in the config file\n", mode);
if ((req = dbus_message_new_method_call(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_HIDE)) != NULL)
{
dbus_message_append_args (req, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
if ((reply = dbus_connection_send_with_reply_and_block(conn, req, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(req);
}
if(ret)
{
printf("mode hidden = %s\n", ret);
return 0;
}
/* not everything went as planned, return error */
return 1;
}
static int set_unhide_mode_config (char *mode)
{
DBusMessage *req = NULL, *reply = NULL;
char *ret = 0;
printf("Trying to unhide the following mode %s in the config file\n", mode);
if ((req = dbus_message_new_method_call(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_UNHIDE)) != NULL)
{
dbus_message_append_args (req, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
if ((reply = dbus_connection_send_with_reply_and_block(conn, req, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(req);
}
if(ret)
{
printf("mode unhidden = %s\n", ret);
return 0;
}
/* not everything went as planned, return error */
return 1;
}
......@@ -260,7 +314,7 @@ static int handle_network(char *network)
int main (int argc, char *argv[])
{
int query = 0, network = 0, setmode = 0, config = 0;
int modelist = 0, mode_configured = 0;
int modelist = 0, mode_configured = 0, hide = 0, unhide = 0;
int res = 1, opt, rescue = 0;
char *option = 0;
......@@ -270,7 +324,7 @@ int main (int argc, char *argv[])
exit(1);
}
while ((opt = getopt(argc, argv, "c:dhmn:qrs:")) != -1)
while ((opt = getopt(argc, argv, "c:dhi:mn:qrs:u:")) != -1)
{
switch (opt) {
case 'c':
......@@ -280,6 +334,10 @@ int main (int argc, char *argv[])
case 'd':
mode_configured = 1;
break;
case 'i':
hide = 1;
option = optarg;
break;
case 'm':
modelist = 1;
break;
......@@ -297,6 +355,10 @@ int main (int argc, char *argv[])
setmode = 1;
option = optarg;
break;
case 'u':
unhide = 1;
option = optarg;
break;
case 'h':
default:
fprintf(stderr, "\nUsage: %s -<option> <args>\n\n \
......@@ -304,11 +366,13 @@ int main (int argc, char *argv[])
\t-c to set a mode in the config file,\n \
\t-d to get the default mode set in the configuration, \n \
\t-h to get this help, \n \
\t-i hide a mode,\n \
\t-n to get/set network configuration. Use get:${config}/set:${config},${value}\n \
\t-m to get the list of supported modes, \n \
\t-q to query the current mode,\n \
\t-r turn rescue mode off,\n \
\t-s to set/activate a mode\n",
\t-s to set/activate a mode\n \
\t-u unhide a mode\n",
argv[0]);
exit(1);
}
......@@ -339,6 +403,10 @@ int main (int argc, char *argv[])
res = handle_network(option);
else if (rescue)
res = unset_rescue();
else if (hide)
res = set_hide_mode_config(option);
else if (unhide)
res = set_unhide_mode_config(option);
/* subfunctions will return 1 if an error occured, print message */
if(res)
......
......@@ -83,8 +83,6 @@ static gboolean set_disconnected_silent(gpointer data);
static void usb_moded_init(void);
static gboolean charging_fallback(gpointer data);
static void usage(void);
static void send_supported_modes_signal(void);
/* ============= Implementation starts here =========================================== */
/** set the usb connection status
......@@ -434,6 +432,16 @@ gchar *get_mode_list(void)
{
GString *modelist_str;
char *hidden_modes_list;
gchar **hidden_mode_split = NULL;
int hiddenmode = 0, i;
hidden_modes_list = get_hidden_modes();
if(hidden_modes_list)
{
hidden_mode_split = g_strsplit(hidden_modes_list, ",", 0);
}
modelist_str = g_string_new(NULL);
......@@ -447,11 +455,26 @@ gchar *get_mode_list(void)
for( iter = modelist; iter; iter = g_list_next(iter) )
{
struct mode_list_elem *data = iter->data;
if(hidden_modes_list && hidden_mode_split)
for(i = 0; hidden_mode_split[i] != NULL; i++)
{
if(!strcmp(hidden_mode_split[i], data->mode_name))
hiddenmode = 1;
}
if(hiddenmode)
{
hiddenmode = 0;
continue;
}
modelist_str = g_string_append(modelist_str, data->mode_name);
modelist_str = g_string_append(modelist_str, ", ");
}
}
if(hidden_mode_split)
g_strfreev(hidden_mode_split);
/* end with charging mode */
g_string_append(modelist_str, MODE_CHARGING);
return(g_string_free(modelist_str, FALSE));
......@@ -683,7 +706,7 @@ static void usage(void)
"\n");
}
static void send_supported_modes_signal(void)
void send_supported_modes_signal(void)
{
/* Send supported modes signal */
gchar *mode_list = get_mode_list();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment