Skip to content

Commit

Permalink
have background polling interval set to 1 day to effectively pause it
Browse files Browse the repository at this point in the history
Use a waiter instead of waiterWithValue
  • Loading branch information
emawby committed Jun 13, 2024
1 parent 3822030 commit 54bb02d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ class ConfigModel : Model() {

/**
* The number of milliseconds between fetching the current notification permission value when the app is out of focus
* We want this value to be very large to effectively stop polling in the background
*/
var backgroundFetchNotificationPermissionInterval: Long
get() = getLongProperty(::backgroundFetchNotificationPermissionInterval.name) { 1_800_000 }
get() = getLongProperty(::backgroundFetchNotificationPermissionInterval.name) { 86_400_000 }
set(value) {
setLongProperty(::backgroundFetchNotificationPermissionInterval.name, value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import com.onesignal.common.AndroidUtils
import com.onesignal.common.events.EventProducer
import com.onesignal.common.threading.Waiter
import com.onesignal.common.threading.WaiterWithValue
import com.onesignal.core.internal.application.ApplicationLifecycleHandlerBase
import com.onesignal.core.internal.application.IApplicationService
Expand Down Expand Up @@ -59,7 +60,7 @@ internal class NotificationPermissionController(
) : IRequestPermissionService.PermissionCallback,
INotificationPermissionController {
private val waiter = WaiterWithValue<Boolean>()
private val pollingWaiter = WaiterWithValue<Boolean>()
private val pollingWaiter = Waiter()
private var pollingWaitInterval: Long
private val events = EventProducer<INotificationPermissionChangedHandler>()
private var enabled: Boolean
Expand Down Expand Up @@ -89,11 +90,12 @@ internal class NotificationPermissionController(
override fun onFocus() {
super.onFocus()
pollingWaitInterval = _configModelStore.model.foregroundFetchNotificationPermissionInterval
pollingWaiter.wake(true)
pollingWaiter.wake()
}

override fun onUnfocused() {
super.onUnfocused()
// Changing the polling interval to 1 day to effectively pause polling
pollingWaitInterval = _configModelStore.model.backgroundFetchNotificationPermissionInterval
}
},
Expand Down

0 comments on commit 54bb02d

Please sign in to comment.