Skip to content

Commit

Permalink
Merge branch 'ecclist' into 'master'
Browse files Browse the repository at this point in the history
Add support for MediaTek specific ril.ecclist syntax

See merge request mer-core/ofono!244
  • Loading branch information
monich committed Nov 25, 2019
2 parents 8ba2d96 + 4d513b6 commit 04b2a9b
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 15 deletions.
1 change: 1 addition & 0 deletions ofono/.gitignore
Expand Up @@ -48,6 +48,7 @@ unit/test-dbus-access
unit/test-dbus-queue
unit/test-gprs-filter
unit/test-ril_config
unit/test-ril_ecclist
unit/test-ril_util
unit/test-ril_vendor
unit/test-ril-transport
Expand Down
7 changes: 7 additions & 0 deletions ofono/Makefile.am
Expand Up @@ -1062,6 +1062,13 @@ unit_test_ril_config_LDADD = @GLIB_LIBS@ -ldl
unit_objects += $(unit_test_ril_config_OBJECTS)
unit_tests += unit/test-ril_config

unit_test_ril_ecclist_SOURCES = unit/test-ril_ecclist.c \
drivers/ril/ril_ecclist.c src/log.c
unit_test_ril_ecclist_CFLAGS = $(COVERAGE_OPT) $(AM_CFLAGS)
unit_test_ril_ecclist_LDADD = @GLIB_LIBS@ -ldl
unit_objects += $(unit_test_ril_ecclist_OBJECTS)
unit_tests += unit/test-ril_ecclist

unit_test_ril_util_SOURCES = unit/test-ril_util.c drivers/ril/ril_util.c \
src/log.c
unit_test_ril_util_CFLAGS = $(COVERAGE_OPT) $(AM_CFLAGS)
Expand Down
71 changes: 56 additions & 15 deletions ofono/drivers/ril/ril_ecclist.c
@@ -1,7 +1,8 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2016 Jolla Ltd.
* Copyright (C) 2016-2019 Jolla Ltd.
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -47,6 +48,53 @@ G_DEFINE_TYPE(RilEccList, ril_ecclist, G_TYPE_OBJECT)
#define RIL_ECCLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
RIL_ECCLIST_TYPE, RilEccList))

static char **ril_ecclist_parse(const char *content)
{
char **ptr;
char **list = NULL;
guint i;

/*
* Some MediaTek devices use ECC,CAT;ECC,CAT kind of syntax
*/
if (strchr(content, ';')) {
list = g_strsplit(content, ";", 0);
for (ptr = list; *ptr; ptr++) {
char* comma;

*ptr = g_strstrip(*ptr);

/* Strip service category */
comma = strchr(*ptr, ',');
if (comma) {
*comma = 0;
}
}
} else {
/* The right ECC,ECC syntax is handled here */
list = g_strsplit(content, ",", 0);
for (ptr = list; *ptr; ptr++) {
*ptr = g_strstrip(*ptr);
}
}

/* Sort the list */
gutil_strv_sort(list, TRUE);

/* Remove empty strings (those are at the beginning after sorting) */
while (list[0] && !list[0][0]) {
list = gutil_strv_remove_at(list, 0, TRUE);
}

/* Remove duplicates */
for (i = 0; list[i] && list[i+1]; i++) {
while (list[i+1] && !strcmp(list[i], list[i+1])) {
list = gutil_strv_remove_at(list, i+1, TRUE);
}
}
return list;
}

static char **ril_ecclist_read(struct ril_ecclist *self)
{
struct ril_ecclist_priv *priv = self->priv;
Expand All @@ -58,16 +106,9 @@ static char **ril_ecclist_read(struct ril_ecclist *self)
GError *error = NULL;

if (g_file_get_contents(priv->path, &content, &len, &error)) {
char **ptr;

DBG("%s = %s", priv->name, content);
list = g_strsplit(content, ",", 0);
for (ptr = list; *ptr; ptr++) {
*ptr = g_strstrip(*ptr);
}

gutil_strv_sort(list, TRUE);
} else if (error) {
list = ril_ecclist_parse(content);
} else {
DBG("%s: %s", priv->path, GERRMSG(error));
g_error_free(error);
}
Expand All @@ -89,7 +130,8 @@ static void ril_ecclist_update(struct ril_ecclist *self)
DBG("%s changed", priv->name);
g_strfreev(self->list);
self->list = list;
g_signal_emit(self, ril_ecclist_signals[SIGNAL_LIST_CHANGED], 0);
g_signal_emit(self, ril_ecclist_signals
[SIGNAL_LIST_CHANGED], 0);
} else {
g_strfreev(list);
}
Expand Down Expand Up @@ -121,10 +163,9 @@ static void ril_ecclist_dir_changed(GUtilInotifyWatch *watch, guint mask,
priv->file_watch = gutil_inotify_watch_callback_new(priv->path,
IN_MODIFY | IN_CLOSE_WRITE,
ril_ecclist_changed, self);
if (priv->file_watch) {
DBG("watching %s", priv->path);
ril_ecclist_update(self);
}
DBG("%swatching %s", priv->file_watch ? "" : "not ",
priv->path);
ril_ecclist_update(self);
}

if (mask & IN_IGNORED) {
Expand Down
1 change: 1 addition & 0 deletions ofono/unit/coverage
Expand Up @@ -23,6 +23,7 @@ TESTS="\
test-watch \
test-ril_util \
test-ril_config \
test-ril_ecclist \
test-ril-transport \
test-ril_vendor \
test-sms-filter \
Expand Down

0 comments on commit 04b2a9b

Please sign in to comment.