Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[usb-moded] Support broken android kernels
Some android kernels don't have working cable detection and charging, unless
a gadget is active. This broken by design behaviouris usually easy to fix
(and recommended due to possible charging issues and extra power drain).
But to make initial porting easier we keep the gadget in charging mode,
even when disconnected.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Jun 2, 2014
1 parent 3bacf82 commit af48bfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/usb_moded.c
Expand Up @@ -70,6 +70,7 @@ gboolean rescue_mode = FALSE;
gboolean diag_mode = FALSE;
gboolean hw_fallback = FALSE;
gboolean charging_mode_set = FALSE;
gboolean android_broken_usb = FALSE;
#ifdef SYSTEMD
static gboolean systemd_notify = FALSE;
#endif
Expand Down Expand Up @@ -132,6 +133,12 @@ void set_usb_connected(gboolean connected)
return;
current_mode.connected = FALSE;
set_disconnected(NULL);
/* Some android kernels check for an active gadget to enable charging and
* cable detection, meaning USB is completely dead unless we keep the gadget
* active
*/
if(current_mode.android_usb_broken)
set_android_charging_mode();
}

}
Expand Down Expand Up @@ -535,6 +542,9 @@ static void usb_moded_init(void)
current_mode.mode = strdup(MODE_UNDEFINED);
current_mode.module = strdup(MODULE_NONE);

if(android_broken_usb)
current_mode.android_usb_broken = TRUE;

/* check config, merge or create if outdated */
if(conf_file_merge() != 0)
{
Expand Down Expand Up @@ -845,6 +855,7 @@ int main(int argc, char* argv[])
int opt = 0, opt_idx = 0;

struct option const options[] = {
{ "android_usb_broken", no_argument, 0, 'a' },
{ "fallback", no_argument, 0, 'd' },
{ "force-syslog", no_argument, 0, 's' },
{ "force-stderr", no_argument, 0, 'T' },
Expand All @@ -860,10 +871,13 @@ int main(int argc, char* argv[])
log_name = basename(*argv);

/* Parse the command-line options */
while ((opt = getopt_long(argc, argv, "fsTDdhrnv", options, &opt_idx)) != -1)
while ((opt = getopt_long(argc, argv, "afsTDdhrnv", options, &opt_idx)) != -1)
{
switch (opt)
{
case 'a':
android_broken_usb = TRUE;
break;
case 'f':
hw_fallback = TRUE;
break;
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded.h
Expand Up @@ -48,6 +48,7 @@ typedef struct usb_mode
/*@{*/
gboolean connected; /* connection status, 1 for connected */
gboolean mounted; /* mount status, 1 for mounted -UNUSED atm- */
gboolean android_usb_broken; /* Used to keep an active gadget for broken Android kernels */
char *mode; /* the mode name */
char *module; /* the module name for the specific mode */
struct mode_list_elem *data; /* contains the mode data */
Expand Down

0 comments on commit af48bfd

Please sign in to comment.