Add device-specific support configs.

This commit is contained in:
Michelle Tang
2024-06-21 10:45:22 -07:00
committed by Greyson Parrelli
parent c0da0bd272
commit b806952430
10 changed files with 203 additions and 15 deletions

View File

@@ -0,0 +1,62 @@
package org.thoughtcrime.securesms.notifications
import android.os.Build
import androidx.annotation.VisibleForTesting
import com.fasterxml.jackson.annotation.JsonProperty
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.util.JsonUtils
import org.thoughtcrime.securesms.util.RemoteConfig
import java.io.IOException
/**
* Remote configs for a device to show a support screen in an effort to prevent delayed notifications
*/
object DelayedNotificationConfig {
private val TAG = Log.tag(DelayedNotificationConfig::class.java)
private const val GENERAL_SUPPORT_URL = "https://support.signal.org/hc/articles/360007318711#android_notifications_troubleshooting"
val currentConfig: Config by lazy { computeConfig() }
/**
* Maps a device model to specific modifications set in order to support better notification
* @param model either exact device model name or model name that ends with a wildcard
* @param showPreemptively shows support sheet immediately if true or after a vitals failure if not, still dependent on localePercent
* @param link represents the Signal support url that corresponds to this device model
* @param localePercent represents the percent of people who will get this change per country
*/
data class Config(
@JsonProperty val model: String = "",
@JsonProperty val showPreemptively: Boolean = false,
@JsonProperty val link: String = GENERAL_SUPPORT_URL,
@JsonProperty val localePercent: String = RemoteConfig.promptBatterySaver
)
@VisibleForTesting
fun computeConfig(): Config {
val default = Config()
val serialized = RemoteConfig.promptDelayedNotificationConfig
if (serialized.isNullOrBlank()) {
return default
}
val list: List<Config> = try {
JsonUtils.fromJsonArray(serialized, Config::class.java)
} catch (e: IOException) {
Log.w(TAG, "Failed to parse json!", e)
emptyList()
}
val config: Config? = list
.filter { it.model.isNotEmpty() }
.find {
if (it.model.last() == '*') {
Build.MODEL.startsWith(it.model.substring(0, it.model.length - 1))
} else {
it.model.contains(Build.MODEL)
}
}
return config ?: default
}
}

View File

@@ -143,6 +143,10 @@ object SlowNotificationHeuristics {
return true
}
fun showPreemptively(): Boolean {
return DelayedNotificationConfig.currentConfig.showPreemptively
}
private fun hasRepeatedFailedServiceStarts(metrics: List<LocalMetricsDatabase.EventMetrics>, minimumEventAgeMs: Long, minimumEventCount: Int, failurePercentage: Float): Boolean {
if (!haveEnoughData(SignalLocalMetrics.FcmServiceStartSuccess.NAME, minimumEventAgeMs) && !haveEnoughData(SignalLocalMetrics.FcmServiceStartFailure.NAME, minimumEventAgeMs)) {
Log.d(TAG, "insufficient data for service starts")

View File

@@ -46,7 +46,7 @@ class VitalsViewModel(private val context: Application) : AndroidViewModel(conte
private fun checkHeuristics(): Single<State> {
return Single.fromCallable {
var state = State.NONE
if (SlowNotificationHeuristics.isHavingDelayedNotifications()) {
if (SlowNotificationHeuristics.showPreemptively() || SlowNotificationHeuristics.isHavingDelayedNotifications()) {
if (SlowNotificationHeuristics.isPotentiallyCausedByBatteryOptimizations() && SlowNotificationHeuristics.shouldPromptBatterySaver()) {
state = State.PROMPT_BATTERY_SAVER_DIALOG
} else if (SlowNotificationHeuristics.shouldPromptUserForLogs()) {