Commit 22a0f778 authored by martinjones's avatar martinjones

[hidden modes] Add interface to get list of hidden modes. Contributes to MER#1540

parent 1bcc68ee
......@@ -415,4 +415,4 @@ For example
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)
See usb_moded_util (-v, -i and -u)
......@@ -30,6 +30,17 @@
<method name="get_modes">
<arg name="modes" type="s" direction="out"/>
</method>
<method name="hide_mode">
<arg name="mode" type="s" direction="in"/>
<arg name="mode" type="s" direction="out"/>
</method>
<method name="unhide_mode">
<arg name="mode" type="s" direction="in"/>
<arg name="mode" type="s" direction="out"/>
</method>
<method name="get_hidden">
<arg name="modes" type="s" direction="out"/>
</method>
<method name="rescue_off"/>
<signal name="sig_usb_state_ind">
<arg name="mode" type="s"/>
......@@ -45,5 +56,8 @@
<arg name="key" type="s"/>
<arg name="value" type="s"/>
</signal>
<signal name="sig_usb_hidden_modes_ind">
<arg name="modes" type="s"/>
</signal>
</interface>
</node>
......@@ -28,4 +28,5 @@ 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);
char * get_hidden_modes(void);
set_config_result_t set_network_setting(const char *config, const char *setting);
......@@ -434,6 +434,8 @@ static const char * make_hidden_modes_string(const char *hidden, int hide)
for(i = 0; hidden_mode_split[i] != NULL; i++)
{
if(strlen(hidden_mode_split[i]) == 0)
continue;
if(!strcmp(hidden_mode_split[i], hidden))
{
/* if hiding a mode that is already hidden do nothing */
......@@ -442,12 +444,13 @@ static const char * make_hidden_modes_string(const char *hidden, int hide)
if(!hide)
continue;
}
modelist_str = g_string_append(modelist_str, hidden_mode_split[i]);
if(hidden_mode_split[i+1] != NULL)
if(strlen(modelist_str->str) != 0)
modelist_str = g_string_append(modelist_str, ",");
modelist_str = g_string_append(modelist_str, hidden_mode_split[i]);
}
if(hide)
{
if(strlen(modelist_str->str) != 0)
modelist_str = g_string_append(modelist_str, ",");
modelist_str = g_string_append(modelist_str, hidden);
}
......@@ -461,8 +464,10 @@ 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)
if(ret == SET_CONFIG_UPDATED) {
send_hidden_modes_signal();
send_supported_modes_signal();
}
return(ret);
}
......@@ -471,8 +476,10 @@ 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)
if(ret == SET_CONFIG_UPDATED) {
send_hidden_modes_signal();
send_supported_modes_signal();
}
return(ret);
}
......
......@@ -32,3 +32,6 @@ int usb_moded_send_error_signal(const char *error);
/* send supported modes signal system bus */
int usb_moded_send_supported_modes_signal(const char *supported_modes);
/* send hidden modes signal system bus */
int usb_moded_send_hidden_modes_signal(const char *hidden_modes);
......@@ -244,6 +244,15 @@ error_reply:
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_HIDDEN_GET))
{
char *config = get_hidden_modes();
if(!config)
config = strdup("");
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
free(config);
}
else if(!strcmp(member, USB_MODE_NETWORK_SET))
{
char *config = 0, *setting = 0;
......@@ -499,3 +508,15 @@ int usb_moded_send_supported_modes_signal(const char *supported_modes)
{
return(usb_moded_dbus_signal(USB_MODE_SUPPORTED_MODES_SIGNAL_NAME, supported_modes));
}
/**
* Send regular usb_moded hidden mode list signal
*
* @return 0 on success, 1 on failure
* @param hidden_modes list of supported modes
*
*/
int usb_moded_send_hidden_modes_signal(const char *hidden_modes)
{
return(usb_moded_dbus_signal(USB_MODE_HIDDEN_MODES_SIGNAL_NAME, hidden_modes));
}
......@@ -37,6 +37,7 @@
#define USB_MODE_CONFIG_SIGNAL_NAME "sig_usb_config_ind"
#define USB_MODE_ERROR_SIGNAL_NAME "sig_usb_state_error_ind"
#define USB_MODE_SUPPORTED_MODES_SIGNAL_NAME "sig_usb_supported_modes_ind"
#define USB_MODE_HIDDEN_MODES_SIGNAL_NAME "sig_usb_hidden_modes_ind"
/* supported methods */
#define USB_MODE_STATE_REQUEST "mode_request" /* returns the current mode */
......@@ -45,6 +46,7 @@
#define USB_MODE_LIST "get_modes" /* returns a comma-separated list of supported modes for ui's */
#define USB_MODE_HIDE "hide_mode" /* hide a mode */
#define USB_MODE_UNHIDE "unhide_mode" /* unhide a mode */
#define USB_MODE_HIDDEN_GET "get_hidden" /* return the hidden modes */
#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 */
......
......@@ -46,3 +46,4 @@
#define MODE_CHARGER "dedicated_charger"
void send_supported_modes_signal(void);
void send_hidden_modes_signal(void);
......@@ -240,6 +240,31 @@ static int set_unhide_mode_config (char *mode)
return 1;
}
static int get_hiddenlist (void)
{
DBusMessage *req = NULL, *reply = NULL;
char *ret = 0;
if ((req = dbus_message_new_method_call(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_HIDDEN_GET)) != NULL)
{
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("hidden modes are = %s\n", ret);
return 0;
}
/* not everything went as planned, return error */
return 1;
}
static int handle_network(char *network)
{
char *operation = 0, *setting = 0, *value = 0;
......@@ -314,7 +339,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, hide = 0, unhide = 0;
int modelist = 0, mode_configured = 0, hide = 0, unhide = 0, hiddenlist = 0;
int res = 1, opt, rescue = 0;
char *option = 0;
......@@ -324,7 +349,7 @@ int main (int argc, char *argv[])
exit(1);
}
while ((opt = getopt(argc, argv, "c:dhi:mn:qrs:u:")) != -1)
while ((opt = getopt(argc, argv, "c:dhi:mn:qrs:u:v")) != -1)
{
switch (opt) {
case 'c':
......@@ -359,6 +384,9 @@ int main (int argc, char *argv[])
unhide = 1;
option = optarg;
break;
case 'v':
hiddenlist = 1;
break;
case 'h':
default:
fprintf(stderr, "\nUsage: %s -<option> <args>\n\n \
......@@ -371,8 +399,9 @@ int main (int argc, char *argv[])
\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-u unhide a mode\n",
\t-s to set/activate a mode,\n \
\t-u unhide a mode,\n \
\t-v to get the list of hidden modes\n",
argv[0]);
exit(1);
}
......@@ -407,6 +436,8 @@ int main (int argc, char *argv[])
res = set_hide_mode_config(option);
else if (unhide)
res = set_unhide_mode_config(option);
else if (hiddenlist)
res = get_hiddenlist();
/* subfunctions will return 1 if an error occured, print message */
if(res)
......
......@@ -714,6 +714,16 @@ void send_supported_modes_signal(void)
g_free(mode_list);
}
void send_hidden_modes_signal(void)
{
/* Send hidden modes signal */
gchar *mode_list = get_hidden_modes();
if(mode_list) {
usb_moded_send_hidden_modes_signal(mode_list);
g_free(mode_list);
}
}
/** Pipe fd for transferring signals to mainloop context */
static int sigpipe_fd = -1;
......@@ -997,6 +1007,7 @@ int main(int argc, char* argv[])
#endif /* SYSTEMD */
send_supported_modes_signal();
send_hidden_modes_signal();
if(hw_fallback)
{
......
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