diff --git a/ModemConfig/AndroidManifest.xml b/ModemConfig/AndroidManifest.xml index 45fc428..975d789 100644 --- a/ModemConfig/AndroidManifest.xml +++ b/ModemConfig/AndroidManifest.xml @@ -7,6 +7,7 @@ + + + diff --git a/ModemConfig/res/values-de/strings.xml b/ModemConfig/res/values-de/strings.xml new file mode 100644 index 0000000..7599bb9 --- /dev/null +++ b/ModemConfig/res/values-de/strings.xml @@ -0,0 +1,8 @@ + + + Konfigurationsinfo + + Modem-Konfiguration + Benutze 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 new file mode 100644 index 0000000..9659340 --- /dev/null +++ b/ModemConfig/res/values-fr/strings.xml @@ -0,0 +1,8 @@ + + + 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 diff --git a/ModemConfig/res/values-it/strings.xml b/ModemConfig/res/values-it/strings.xml new file mode 100644 index 0000000..3ee668c --- /dev/null +++ b/ModemConfig/res/values-it/strings.xml @@ -0,0 +1,8 @@ + + + Informazioni configurazione + + Configurazione Modem + Uso 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 new file mode 100644 index 0000000..b0b93bb --- /dev/null +++ b/ModemConfig/res/values/strings.xml @@ -0,0 +1,13 @@ + + + ModemConfig + + /oem/modem-config + modem.conf + + Configuration info + + Modem configuration + Using modem configuration: %1$s\nFirmware file: %2$s + Found no modem configuration + \ No newline at end of file diff --git a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt index c7379af..c1dbe54 100644 --- a/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt +++ b/ModemConfig/src/com/sony/opentelephony/modemconfig/ModemConfigService.kt @@ -16,6 +16,9 @@ package com.sony.opentelephony.modemconfig +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager import android.app.Service import android.content.Context import android.content.Intent @@ -27,9 +30,14 @@ import android.telephony.TelephonyManager import android.text.TextUtils import android.util.Log import org.xmlpull.v1.XmlPullParser +import java.nio.file.Files +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_ID = 1 + private val newlineMatch = Regex("[\n\r]") class ModemConfigService : Service() { @@ -49,6 +57,11 @@ class ModemConfigService : Service() { // TODO: Do a lateinit here? private /*lateinit*/ var providers: List? = null + private val notificationManager: NotificationManager by lazy { + getSystemService(NotificationManager::class.java) + ?: throw Exception("Expected NotificationManager, got null") + } + private fun getProviders(context: Context): List { if (providers != null) return providers!! @@ -155,6 +168,21 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { } } + private fun findFirmwarePath(configId: String): String { + val conf = Paths.get(resources.getString(R.string.modem_config_path), configId, + resources.getString(R.string.modem_config_name)) + return try { + if (Files.isRegularFile(conf)) { + Files.readAllLines(conf).first() + } else { + // TODO: Can/should we read default from modem-switcher prop? + "default" + } + } catch (e: Exception) { + "failed to derive" + } + } + private fun handleSubscription(sub: SubscriptionInfo) { if (VERBOSE) Log.v(TAG, "Checking sub $sub") @@ -162,11 +190,28 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { val tm = globalTm!!.createForSubscriptionId(sub.subscriptionId) val name = findConfigurationName(this, tm) - if (name != null) { + val notificationText = if (name != null) { val prop = "persist.vendor.somc.cust.modem${sub.simSlotIndex}" if (VERBOSE) Log.v(TAG, "Setting $prop to $name") SystemProperties.set(prop, name) + + resources.getString( + R.string.notification_text_modem_configuration_resolved_modem_config, + name, + findFirmwarePath(name)) + } else { + 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() + } + + notificationManager.notify(NOTIFICATION_ID, notification) } override fun onCreate() { @@ -174,6 +219,12 @@ context.resources.getXml(R.xml.service_provider_sim_configs).use { val sm = getSystemService(SubscriptionManager::class.java) ?: throw Exception("Expected SubscriptionManager, got null") + val channel = NotificationChannel( + NOTIFICATION_CHANNEL_ID, + resources.getString(R.string.notification_channel_configuration_info), + NotificationManager.IMPORTANCE_LOW) + notificationManager.createNotificationChannel(channel) + // Our callback is invoked once on .add too; no need to run the contents manually at startup sm.addOnSubscriptionsChangedListener( object : SubscriptionManager.OnSubscriptionsChangedListener() {