From 76cab3b9a0acbf839dce873ba717b43340be7397 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 19 Jan 2022 12:33:00 +0100 Subject: [PATCH] add PeriodicWorkRequest to register local token every 24h Signed-off-by: Marcel Hibbe --- .../talk/utils/ClosedInterfaceImpl.kt | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt index b183eb087..7ab19d8bb 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -35,23 +35,6 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi override fun onProviderInstallFailed(p0: Int, p1: Intent?) { } - override fun setUpPushTokenRegistration() { - val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() - WorkManager.getInstance().enqueue(pushRegistrationWork) - - val periodicPushRegistration = PeriodicWorkRequest.Builder( - GetFirebasePushTokenWorker::class.java, 15, // TODO: discuss intervall. joas 24h, google 1 month - TimeUnit.MINUTES - ) - .build() - - WorkManager.getInstance() - .enqueueUniquePeriodicWork( - "periodicPushRegistration", ExistingPeriodicWorkPolicy.REPLACE, - periodicPushRegistration - ) - } - private fun isGPlayServicesAvailable() : Boolean { val api = GoogleApiAvailability.getInstance() val code = @@ -62,4 +45,43 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi } return code == ConnectionResult.SUCCESS } + + override fun setUpPushTokenRegistration() { + registerLocalToken() + setUpPeriodicLocalTokenRegistration() + setUpPeriodicTokenRefreshFromFCM() + } + + private fun registerLocalToken(){ + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + WorkManager.getInstance().enqueue(pushRegistrationWork) + } + + private fun setUpPeriodicLocalTokenRegistration () { + val periodicTokenRegistration = PeriodicWorkRequest.Builder( + PushRegistrationWorker::class.java, 1, + TimeUnit.DAYS + ) + .build() + + WorkManager.getInstance() + .enqueueUniquePeriodicWork( + "periodicTokenRegistration", ExistingPeriodicWorkPolicy.REPLACE, + periodicTokenRegistration + ) + } + + private fun setUpPeriodicTokenRefreshFromFCM () { + val periodicTokenRefreshFromFCM = PeriodicWorkRequest.Builder( + GetFirebasePushTokenWorker::class.java, 30, + TimeUnit.DAYS + ) + .build() + + WorkManager.getInstance() + .enqueueUniquePeriodicWork( + "periodicTokenRefreshFromFCM", ExistingPeriodicWorkPolicy.REPLACE, + periodicTokenRefreshFromFCM + ) + } } \ No newline at end of file