mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Update slow notification debugging info.
This commit is contained in:
committed by
Cody Henthorne
parent
afe3cd1098
commit
1c66da7873
@@ -79,9 +79,12 @@ object SlowNotificationHeuristics {
|
||||
if (Build.VERSION.SDK_INT < 23) {
|
||||
return false
|
||||
}
|
||||
if (!LocaleFeatureFlags.isBatterySaverPromptEnabled() || SignalStore.uiHints().hasDismissedBatterySaverPrompt()) {
|
||||
|
||||
val remoteEnabled = LocaleFeatureFlags.isBatterySaverPromptEnabled() || LocaleFeatureFlags.isDelayedNotificationPromptEnabled()
|
||||
if (!remoteEnabled || SignalStore.uiHints().hasDismissedBatterySaverPrompt()) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - SignalStore.uiHints().lastBatterySaverPrompt < TimeUnit.DAYS.toMillis(7)) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.notifications
|
||||
|
||||
import android.os.Build
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.ViewModel
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||
import org.thoughtcrime.securesms.notifications.SlowNotificationHeuristics.isHavingDelayedNotifications
|
||||
import org.thoughtcrime.securesms.notifications.SlowNotificationHeuristics.isPotentiallyCausedByBatteryOptimizations
|
||||
import org.thoughtcrime.securesms.notifications.SlowNotificationHeuristics.shouldPromptBatterySaver
|
||||
import org.thoughtcrime.securesms.notifications.SlowNotificationHeuristics.shouldPromptUserForLogs
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* View model for checking for slow notifications and if we should prompt the user with help or for information.
|
||||
*/
|
||||
class SlowNotificationsViewModel : ViewModel() {
|
||||
|
||||
private val checkSubject = BehaviorSubject.create<Unit>()
|
||||
|
||||
val slowNotificationState: Observable<State>
|
||||
|
||||
init {
|
||||
slowNotificationState = checkSubject
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.throttleFirst(1, TimeUnit.MINUTES)
|
||||
.switchMapSingle {
|
||||
checkHeuristics()
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun checkSlowNotificationHeuristics() {
|
||||
checkSubject.onNext(Unit)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun checkHeuristics(): Single<State> {
|
||||
return Single.fromCallable {
|
||||
var state = State.NONE
|
||||
if (isHavingDelayedNotifications()) {
|
||||
if (isPotentiallyCausedByBatteryOptimizations() && Build.VERSION.SDK_INT >= 23) {
|
||||
if (shouldPromptBatterySaver()) {
|
||||
state = State.PROMPT_BATTERY_SAVER_DIALOG
|
||||
}
|
||||
} else if (shouldPromptUserForLogs()) {
|
||||
state = State.PROMPT_DEBUGLOGS
|
||||
}
|
||||
}
|
||||
|
||||
return@fromCallable state
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
enum class State {
|
||||
NONE,
|
||||
PROMPT_BATTERY_SAVER_DIALOG,
|
||||
PROMPT_DEBUGLOGS
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.thoughtcrime.securesms.notifications
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Build
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
@@ -16,7 +15,6 @@ import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||
import org.thoughtcrime.securesms.crash.CrashConfig
|
||||
import org.thoughtcrime.securesms.database.LogDatabase
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.LocaleFeatureFlags
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.Duration.Companion.days
|
||||
|
||||
@@ -49,13 +47,8 @@ class VitalsViewModel(private val context: Application) : AndroidViewModel(conte
|
||||
return Single.fromCallable {
|
||||
var state = State.NONE
|
||||
if (SlowNotificationHeuristics.isHavingDelayedNotifications()) {
|
||||
if (LocaleFeatureFlags.isBatterySaverPromptEnabled() &&
|
||||
SlowNotificationHeuristics.isPotentiallyCausedByBatteryOptimizations() &&
|
||||
Build.VERSION.SDK_INT >= 23
|
||||
) {
|
||||
if (SlowNotificationHeuristics.shouldPromptBatterySaver()) {
|
||||
state = State.PROMPT_BATTERY_SAVER_DIALOG
|
||||
}
|
||||
if (SlowNotificationHeuristics.isPotentiallyCausedByBatteryOptimizations() && SlowNotificationHeuristics.shouldPromptBatterySaver()) {
|
||||
state = State.PROMPT_BATTERY_SAVER_DIALOG
|
||||
} else if (SlowNotificationHeuristics.shouldPromptUserForLogs()) {
|
||||
state = State.PROMPT_DEBUGLOGS_FOR_NOTIFICATIONS
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user