Skip to content

Commit

Permalink
Merge branch 'jb38422_serialno' into 'master'
Browse files Browse the repository at this point in the history
Set usb serial number and watch out for unexpected changes

See merge request !26
  • Loading branch information
spiiroin committed Apr 26, 2017
2 parents f1a17e3 + 0debddb commit 5e9e4e4
Show file tree
Hide file tree
Showing 7 changed files with 793 additions and 121 deletions.
4 changes: 3 additions & 1 deletion configure.ac
Expand Up @@ -75,7 +75,7 @@ AM_CONDITIONAL([CONNMAN], [test x$connman = xtrue])

AC_ARG_ENABLE([systemd], AS_HELP_STRING([--enable-systemd], [Enable systemd notify interface @<:@default=false@:>@]),
[case "${enableval}" in
yes) systemd=true ; CFLAGS="-DSYSTEMD -lsystemd-daemon $CFLAGS" ;;
yes) systemd=true ; CFLAGS="-DSYSTEMD $CFLAGS" ;;
no) systemd=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-systemd]) ;;
esac],[systemd=false])
Expand All @@ -98,6 +98,8 @@ PKG_CHECK_MODULES([USB_MODED], [
libudev
libkmod
ssu-sysinfo
libsystemd
dsme
])

AC_SUBST(USB_MODED_LIBS)
Expand Down
3 changes: 2 additions & 1 deletion rpm/usb-moded.spec
Expand Up @@ -14,8 +14,9 @@ BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(udev)
BuildRequires: pkgconfig(libkmod)
BuildRequires: doxygen
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: pkgconfig(libsystemd)
BuildRequires: pkgconfig(ssu-sysinfo)
BuildRequires: pkgconfig(dsme)

Requires: lsof
Requires: usb-moded-configs
Expand Down
56 changes: 55 additions & 1 deletion src/usb_moded-android.c
Expand Up @@ -43,11 +43,65 @@ int android_settings(void)
return ret;
}

/** Read android serial number from kernel command line
*/
static gchar *get_android_serial(void)
{
static const char path[] = "/proc/cmdline";
static const char find[] = "androidboot.serialno=";
static const char pbrk[] = " \t\r\n,";

char *res = 0;
FILE *file = 0;
size_t size = 0;
char *data = 0;

if( !(file = fopen(path, "r")) ) {
log_warning("%s: %s: %m", path, "can't open");
goto EXIT;
}

if( getline(&data, &size, file) < 0 ) {
log_warning("%s: %s: %m", path, "can't read");
goto EXIT;
}

char *beg = strstr(data, find);
if( !beg ) {
log_warning("%s: no serial found", path);
goto EXIT;
}

beg += sizeof find - 1;
size_t len = strcspn(beg, pbrk);
if( len < 1 ) {
log_warning("%s: empty serial found", path);
goto EXIT;
}

res = g_strndup(beg, len);

EXIT:

free(data);

if( file )
fclose(file);

return res;
}

/** initialize the basic android values
*/
void android_init_values(void)
{
char *text;
gchar *text;

if( (text = get_android_serial()) )
{
write_to_file("/sys/class/android_usb/android0/iSerial", text);
g_free(text);
}

text = get_android_manufacturer();
if(text)
Expand Down

0 comments on commit 5e9e4e4

Please sign in to comment.