diff --git a/.gitignore b/.gitignore index ccff052..48e08be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ **/.idea **/*.iml **/*.ipr +**/lib +**/gen 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 3ee668c..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 c1dbe54..d59305f 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]") @@ -109,7 +111,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 +127,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) @@ -203,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() { @@ -222,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 @@ -232,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) + } + } }) }