ModemConfig: Add a simple notification showing to-be-flashed firmware

In order to help our efforts finalizing the initial release, provide a
little bit of info to the user about the detected config and the
firmware path belonging to the installation.

TODO: This can be improved in various ways:
- Clear sony.modemswitcher.modem_name_*, and wait for it to change.
  This variable contains the path so that we do not need to read it from
  a file, including the default path (when the config is not found).
- Extend the notification (or start a Dialog/Activity onclick) to
  display more diagnostic info.

Signed-off-by: Marijn Suijten <marijns95@gmail.com>
This commit is contained in:
Marijn Suijten 2020-06-04 23:05:14 +02:00
commit 6ff9b1f132
7 changed files with 114 additions and 1 deletions

View file

@ -7,6 +7,7 @@
<application
android:directBootAware="true"
android:label="@string/app_name"
android:persistent="true">
<receiver
android:name=".BootReceiver"

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?><!--
~ Copyright (C) 2020 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#757575"
android:pathData="M19.99 4c0-1.1-.89-2-1.99-2h-8L4 8v12c0 1.1.9 2 2 2h12.01c1.1 0 1.99-.9 1.99-2l-.01-16zM9 19H7v-2h2v2zm8 0h-2v-2h2v2zm-8-4H7v-4h2v4zm4 4h-2v-4h2v4zm0-6h-2v-2h2v2zm4 2h-2v-4h2v4z" />
</vector>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="notification_channel_configuration_info">Konfigurationsinfo</string>
<string name="notification_title_modem_configuration">Modem-Konfiguration</string>
<string name="notification_text_modem_configuration_resolved_modem_config">Benutze Modem-Konfiguration: %1$s\nFirmware-Datei: %2$s</string>
<string name="notification_text_modem_configuration_no_match">Keine passende Modem-Konfiguration gefunden</string>
</resources>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="notification_channel_configuration_info">Informations de configuration</string>
<string name="notification_title_modem_configuration">Configuration du modem</string>
<string name="notification_text_modem_configuration_resolved_modem_config">Configuration du modem utilisée : %1$s\nFirmware utilisé: %2$s</string>
<string name="notification_text_modem_configuration_no_match">Aucune configuration de modem trouvée </string>
</resources>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="notification_channel_configuration_info">Informazioni configurazione</string>
<string name="notification_title_modem_configuration">Configurazione Modem</string>
<string name="notification_text_modem_configuration_resolved_modem_config">Uso configurazione modem %1$s\nFile firmware: %2%$s</string>
<string name="notification_text_modem_configuration_no_match">Nessuna configurazione modem trovata</string>
</resources>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">ModemConfig</string>
<string name="modem_config_path" translatable="false">/oem/modem-config</string>
<string name="modem_config_name" translatable="false">modem.conf</string>
<string name="notification_channel_configuration_info">Configuration info</string>
<string name="notification_title_modem_configuration">Modem configuration</string>
<string name="notification_text_modem_configuration_resolved_modem_config">Using modem configuration: %1$s\nFirmware file: %2$s</string>
<string name="notification_text_modem_configuration_no_match">Found no modem configuration</string>
</resources>

View file

@ -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<ProviderFilter>? = null
private val notificationManager: NotificationManager by lazy {
getSystemService(NotificationManager::class.java)
?: throw Exception("Expected NotificationManager, got null")
}
private fun getProviders(context: Context): List<ProviderFilter> {
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() {