mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Add device-specific support configs.
This commit is contained in:
committed by
Greyson Parrelli
parent
c0da0bd272
commit
b806952430
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user