Skip to content

Commit

Permalink
[android] Normalize numerical id-values to lower case hex. JB#41748
Browse files Browse the repository at this point in the history
Configfs wants to have numbers in '0xbeef' form while android usb wants to
have 'beef'. Normalizing the output to expected format allows either form
to be used in usb-moded configuration files.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Aug 24, 2018
1 parent 4f9ffa6 commit 18efbfc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/usb_moded-android.c
Expand Up @@ -267,7 +267,15 @@ bool
android_set_productid(const char *id)
{
bool ack = false;

if( id && android_in_use() ) {
char str[16];
char *end = 0;
unsigned num = strtol(id, &end, 16);
if( end > id && *end == 0 ) {
snprintf(str, sizeof str, "%04x", num);
id = str;
}
ack = write_to_file(ANDROID0_ID_PRODUCT, id) != -1;
}
log_debug("ANDROID %s(%s) -> %d", __func__, id, ack);
Expand All @@ -283,6 +291,13 @@ android_set_vendorid(const char *id)
{
bool ack = false;
if( id && android_in_use() ) {
char str[16];
char *end = 0;
unsigned num = strtol(id, &end, 16);
if( end > id && *end == 0 ) {
snprintf(str, sizeof str, "%04x", num);
id = str;
}
ack = write_to_file(ANDROID0_ID_VENDOR, id) != -1;
}
log_debug("ANDROID %s(%s) -> %d", __func__, id, ack);
Expand Down

0 comments on commit 18efbfc

Please sign in to comment.