Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'hide-mode' into 'master'
[modes] Add possibility to hide modes from the UI



See merge request !2
  • Loading branch information
philippedeswert committed Mar 22, 2016
2 parents df78d2f + 9c3e0f2 commit 1bcc68e
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 94 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,4 +1,4 @@
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])
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
@@ -1,3 +1,9 @@
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
Expand Down
24 changes: 21 additions & 3 deletions docs/usb_moded-doc.txt
Expand Up @@ -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
-------------------
Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions src/usb_moded-config-private.h
Expand Up @@ -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);
80 changes: 79 additions & 1 deletion src/usb_moded-config.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -617,6 +687,9 @@ int conf_file_merge(void)
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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/usb_moded-config.h
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 1bcc68e

Please sign in to comment.