From fda0f1de97f3e2017811a6ea93aaf24615922e14 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Tue, 28 May 2019 15:26:36 -0700 Subject: [PATCH] No issue: sync and refresh device state on foreground --- .../main/java/org/mozilla/fenix/HomeActivity.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 19ef52eeb..6ba4e3fc5 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -14,6 +14,9 @@ import androidx.appcompat.widget.Toolbar import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.NavigationUI +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager @@ -102,6 +105,19 @@ open class HomeActivity : AppCompatActivity() { handleOpenedFromExternalSourceIfNecessary(intent) } + override fun onResume() { + super.onResume() + CoroutineScope(Dispatchers.Main).launch { + // Make sure accountManager is initialized. + components.backgroundServices.accountManager.initAsync().await() + // If we're authenticated, kick-off a sync and a device state refresh. + components.backgroundServices.accountManager.authenticatedAccount()?.let { + components.backgroundServices.syncManager.syncNow(startup = true) + it.deviceConstellation().refreshDeviceStateAsync().await() + } + } + } + override fun onCreateView( parent: View?, name: String,