From 131e68dc246129d2c84d35c264de805797c522c4 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 5 Jun 2020 14:04:56 +0200 Subject: [PATCH 1/5] gitignore: Ignore gen and lib folder created by aidegen + Android Studio Signed-off-by: Marijn Suijten --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ccff052..48e08be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ **/.idea **/*.iml **/*.ipr +**/lib +**/gen From 5ed902095332c9f82cf93a8bc16bde9d01ceeb6a Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Sat, 6 Jun 2020 11:17:39 +0200 Subject: [PATCH 2/5] ModemConfig: Fix warning in translated string res/values-it/strings.xml:6: warn: multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?. --- ModemConfig/res/values-it/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModemConfig/res/values-it/strings.xml b/ModemConfig/res/values-it/strings.xml index 3ee668c..da58586 100644 --- a/ModemConfig/res/values-it/strings.xml +++ b/ModemConfig/res/values-it/strings.xml @@ -3,6 +3,6 @@ Informazioni configurazione Configurazione Modem - Uso configurazione modem %1$s\nFile firmware: %2%$s + Uso configurazione modem %1$s\nFile firmware: %2$s Nessuna configurazione modem trovata \ No newline at end of file From 0d8dc0c5421ec37b2180d3ba7451892a7e44cc8f Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 5 Jun 2020 22:44:45 +0200 Subject: [PATCH 3/5] ModemConfig: Deal with null|empty strings from TelephonyManager Some of these strings are (temporarily) empty, eg. while the SIM is locked. Make sure we do not crash in these instances, and rather wait for the time these become available. Signed-off-by: Marijn Suijten --- .../modemconfig/ModemConfigService.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt index c1dbe54..94860e3 100644 --- a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt +++ b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt @@ -109,7 +109,7 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { } else if (simConfigId != null) { // If not in a service_provider_sim_config element, and a valid simConfigId // /exists parse all members/subelements: - val text = cleanString(xml.nextText()) + val text = xml.nextText().cleanString() if (currentMap.containsKey(xml.name)) throw Exception("Already parsed ${xml.name}!") currentMap[xml.name] = text @@ -125,21 +125,27 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { return list } - private fun cleanString(str: String) = str.replace(newlineMatch, "").trim() + private fun String.cleanString() = replace(newlineMatch, "").trim() private fun findConfigurationName(context: Context, tm: TelephonyManager): String? { val operator = tm.simOperator - val mcc = operator.substring(0, 3) - val mnc = operator.substring(3) - - val sp = cleanString(tm.simOperatorName) + if (operator.isNullOrEmpty()) { + Log.d(TAG, "Operator is null or empty") + return null + } + val mcc = operator.take(3) + val mnc = operator.drop(3) + val sp = tm.simOperatorName?.cleanString() ?: "" + val gid1 = tm.groupIdLevel1 ?: "" val imsi = tm.subscriberId - val gid1 = tm.groupIdLevel1 - val iccid2 = tm.simSerialNumber + if (imsi.isNullOrEmpty()) { + Log.d(TAG, "Imsi is null or empty") + return null + } if (VERBOSE) Log.v(TAG, "Matching providers against: $sp $mcc/$mnc, imsi: $imsi" + - ", gid: $gid1, iccid2: $iccid2") + ", gid: $gid1") val result = getProviders(context).firstOrNull f@{ info -> if (info.mcc != null && info.mcc != mcc) From 16b7b8391edb9d14d1bef9b9b0f6b85f5b957d3c Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 5 Jun 2020 23:17:49 +0200 Subject: [PATCH 4/5] ModemConfig: Show a grouped notification per slot Otherwise the notifcation for slot 1 would hide the one for slot 0, if both are available. Signed-off-by: Marijn Suijten --- ModemConfig/AndroidManifest.xml | 1 + ModemConfig/res/values-de/strings.xml | 5 +- ModemConfig/res/values-fr/strings.xml | 7 +-- ModemConfig/res/values-it/strings.xml | 5 +- ModemConfig/res/values/strings.xml | 9 ++-- .../modemconfig/ModemConfigService.kt | 47 +++++++++++++++---- 6 files changed, 54 insertions(+), 20 deletions(-) diff --git a/ModemConfig/AndroidManifest.xml b/ModemConfig/AndroidManifest.xml index 975d789..9bd8a27 100644 --- a/ModemConfig/AndroidManifest.xml +++ b/ModemConfig/AndroidManifest.xml @@ -7,6 +7,7 @@ Konfigurationsinfo Modem-Konfiguration - Benutze Modem-Konfiguration: %1$s\nFirmware-Datei: %2$s + Steckplatz %1$s + Modem-Konfiguration: %1$s\nFirmware-Datei: %2$s Keine passende Modem-Konfiguration gefunden - \ No newline at end of file + diff --git a/ModemConfig/res/values-fr/strings.xml b/ModemConfig/res/values-fr/strings.xml index 9659340..e1eb6f9 100644 --- a/ModemConfig/res/values-fr/strings.xml +++ b/ModemConfig/res/values-fr/strings.xml @@ -3,6 +3,7 @@ Informations de configuration Configuration du modem - Configuration du modem utilisée : %1$s\nFirmware utilisé: %2$s - Aucune configuration de modem trouvée - \ No newline at end of file + Port SIM %1$s + Configuration du modem utilisée : %1$s\n Chemin d\'accès du firmware : %2$s + Aucune configuration modem Trouvée + diff --git a/ModemConfig/res/values-it/strings.xml b/ModemConfig/res/values-it/strings.xml index da58586..cf20daf 100644 --- a/ModemConfig/res/values-it/strings.xml +++ b/ModemConfig/res/values-it/strings.xml @@ -3,6 +3,7 @@ Informazioni configurazione Configurazione Modem - Uso configurazione modem %1$s\nFile firmware: %2$s + Slot %1$s + Configurazione modem: %1$s\nFile firmware: %2$s Nessuna configurazione modem trovata - \ No newline at end of file + diff --git a/ModemConfig/res/values/strings.xml b/ModemConfig/res/values/strings.xml index b0b93bb..fce9f74 100644 --- a/ModemConfig/res/values/strings.xml +++ b/ModemConfig/res/values/strings.xml @@ -1,6 +1,6 @@ - ModemConfig + Open Devices ModemConfig /oem/modem-config modem.conf @@ -8,6 +8,7 @@ Configuration info Modem configuration - Using modem configuration: %1$s\nFirmware file: %2$s - Found no modem configuration - \ No newline at end of file + Slot %1$s + Modem configuration: %1$s\nFirmware file: %2$s + No modem configuration found + diff --git a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt index 94860e3..e9bf5cd 100644 --- a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt +++ b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt @@ -36,7 +36,9 @@ import java.nio.file.Paths private const val TAG = "ModemConfigReceiver" private const val VERBOSE = false private const val NOTIFICATION_CHANNEL_ID = "Configuration" +private const val NOTIFICATION_GROUP_KEY_SLOTS = "com.sony.opentelephony.modemconfig.slot_result" private const val NOTIFICATION_ID = 1 +private const val NOTIFICATION_ID_SLOT_BASE = 1000 private val newlineMatch = Regex("[\n\r]") @@ -209,15 +211,22 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { resources.getString(R.string.notification_text_modem_configuration_no_match) } - val notification = Notification.Builder(this, NOTIFICATION_CHANNEL_ID).run { - setSmallIcon(R.drawable.ic_sim_card) - setContentTitle(resources.getString(R.string.notification_title_modem_configuration)) - setContentText(notificationText.substringBefore('\n')) - style = Notification.BigTextStyle().bigText(notificationText) - build() - } + val notification = Notification.Builder(this@ModemConfigService, + NOTIFICATION_CHANNEL_ID) + .run { + setSmallIcon(R.drawable.ic_sim_card) + setContentTitle(resources.getString( + R.string.notification_title_slot_index, + sub.simSlotIndex)) + setContentText(notificationText.substringBefore('\n')) + setGroup(NOTIFICATION_GROUP_KEY_SLOTS) + setSortKey(sub.simSlotIndex.toString()) + style = Notification.BigTextStyle() + .bigText(notificationText) + build() + } - notificationManager.notify(NOTIFICATION_ID, notification) + notificationManager.notify(NOTIFICATION_ID_SLOT_BASE + sub.simSlotIndex, notification) } override fun onCreate() { @@ -238,7 +247,27 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { // caching at all. The modem-switcher itself makes sure to not needlessly flash // firmware - let it handle the validation. override fun onSubscriptionsChanged() { - sm.activeSubscriptionInfoList?.forEach(::handleSubscription) + sm.activeSubscriptionInfoList?.run { + if (any()) { + val summaryNotification = Notification.Builder( + this@ModemConfigService, + NOTIFICATION_CHANNEL_ID) + .run { + setSmallIcon(R.drawable.ic_sim_card) + setContentTitle(resources.getString( + R.string.notification_title_modem_configuration + )) + setGroup(NOTIFICATION_GROUP_KEY_SLOTS) + setGroupSummary(true) + build() + } + + notificationManager.notify(NOTIFICATION_ID, summaryNotification) + } + + forEach(::handleSubscription) + } + } }) } From c7583ac3c8fec9e9a7e968eba0fbf515386540fc Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 7 Jun 2020 11:16:11 +0200 Subject: [PATCH 5/5] ModemConfig: Drop notification importance from LOW to MIN Hide the icon from the statusbar as well. It's not relevant to see here, just in the notification shade is enough. Signed-off-by: Marijn Suijten --- .../com/sony/opentelephony/modemconfig/ModemConfigService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt index e9bf5cd..d59305f 100644 --- a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt +++ b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt @@ -237,7 +237,7 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { val channel = NotificationChannel( NOTIFICATION_CHANNEL_ID, resources.getString(R.string.notification_channel_configuration_info), - NotificationManager.IMPORTANCE_LOW) + NotificationManager.IMPORTANCE_MIN) notificationManager.createNotificationChannel(channel) // Our callback is invoked once on .add too; no need to run the contents manually at startup