Unverified Commit 36b1c710 authored by Sachin's avatar Sachin Committed by GitHub
Browse files

for #11617 added a resetPoliciesAfter ext function for StrictMode, and...

for #11617 added a resetPoliciesAfter ext function for StrictMode, and replaced all existing calls to "resetAfter" with "resetPoliciesAfter" (#11619)
parent 4e590bf7
......@@ -8,13 +8,13 @@ import android.os.StrictMode
import androidx.preference.PreferenceManager
import leakcanary.AppWatcher
import leakcanary.LeakCanary
import mozilla.components.support.ktx.android.os.resetAfter
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.resetPoliciesAfter
class DebugFenixApplication : FenixApplication() {
override fun setupLeakCanary() {
val isEnabled = StrictMode.allowThreadDiskReads().resetAfter {
val isEnabled = StrictMode.allowThreadDiskReads().resetPoliciesAfter {
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getPreferenceKey(R.string.pref_key_leakcanary), true)
}
......
......@@ -49,8 +49,8 @@ import org.mozilla.fenix.session.PerformanceActivityLifecycleCallbacks
import org.mozilla.fenix.session.VisibilityLifecycleCallback
import org.mozilla.fenix.utils.BrowsersCache
import org.mozilla.fenix.utils.Settings
import mozilla.components.support.ktx.android.os.resetAfter
import org.mozilla.fenix.StrictModeManager.enableStrictMode
import org.mozilla.fenix.ext.resetPoliciesAfter
/**
*The main application class for Fenix. Records data to measure initialization performance.
......@@ -130,7 +130,7 @@ open class FenixApplication : LocaleAwareApplication() {
warmBrowsersCache()
// Make sure the engine is initialized and ready to use.
StrictMode.allowThreadDiskReads().resetAfter {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.core.engine.warmUp()
}
initializeWebExtensionSupport()
......
......@@ -44,7 +44,6 @@ import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
import mozilla.components.support.ktx.android.content.share
import mozilla.components.support.ktx.android.os.resetAfter
import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
import mozilla.components.support.locale.LocaleAwareAppCompatActivity
......@@ -63,6 +62,7 @@ import org.mozilla.fenix.ext.checkAndUpdateScreenshotPermission
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
import org.mozilla.fenix.home.intent.DeepLinkIntentProcessor
......@@ -130,7 +130,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
final override fun onCreate(savedInstanceState: Bundle?) {
StrictModeManager.changeStrictModePolicies(supportFragmentManager)
// There is disk read violations on some devices such as samsung and pixel for android 9/10
StrictMode.allowThreadDiskReads().resetAfter {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
super.onCreate(savedInstanceState)
}
......@@ -435,7 +435,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
}
override fun attachBaseContext(base: Context) {
StrictMode.allowThreadDiskReads().resetAfter {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
super.attachBaseContext(base)
}
}
......
......@@ -18,7 +18,7 @@ import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.ktx.android.os.resetAfter
import org.mozilla.fenix.ext.resetPoliciesAfter
import kotlin.coroutines.CoroutineContext
/**
......@@ -77,7 +77,7 @@ class AccountAbnormalities(
private val logger = Logger("AccountAbnormalities")
private val prefs = StrictMode.allowThreadDiskReads().resetAfter {
private val prefs = StrictMode.allowThreadDiskReads().resetPoliciesAfter {
context.getSharedPreferences(PREF_FXA_ABNORMALITIES, Context.MODE_PRIVATE)
}
......
......@@ -16,8 +16,8 @@ import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.tab.collections.TabCollectionStorage
import mozilla.components.support.base.observer.Observable
import mozilla.components.support.base.observer.ObserverRegistry
import mozilla.components.support.ktx.android.os.resetAfter
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.toShortUrl
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
import org.mozilla.fenix.utils.Mockable
......@@ -52,7 +52,7 @@ class TabCollectionStorage(
var cachedTabCollections = listOf<TabCollection>()
private val collectionStorage by lazy {
StrictMode.allowThreadDiskReads().resetAfter {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
TabCollectionStorage(context, sessionManager)
}
}
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import android.os.StrictMode
import org.mozilla.fenix.Config
/**
* Runs the given [functionBlock] and sets the ThreadPolicy after its completion in Debug mode.
* Otherwise simply runs the [functionBlock]
* This function is written in the style of [AutoCloseable.use].
* @return the value returned by [functionBlock].
*/
inline fun <R> StrictMode.ThreadPolicy.resetPoliciesAfter(functionBlock: () -> R): R {
return if (Config.channel.isDebug) {
try {
functionBlock()
} finally {
StrictMode.setThreadPolicy(this)
}
} else {
functionBlock()
}
}
......@@ -65,7 +65,6 @@ import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.ktx.android.os.resetAfter
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
......@@ -88,6 +87,7 @@ import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.toTab
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
import org.mozilla.fenix.home.sessioncontrol.SessionControlInteractor
import org.mozilla.fenix.home.sessioncontrol.SessionControlView
......@@ -184,7 +184,7 @@ class HomeFragment : Fragment() {
collections = requireComponents.core.tabCollectionStorage.cachedTabCollections,
expandedCollections = emptySet(),
mode = currentMode.getCurrentMode(),
topSites = StrictMode.allowThreadDiskReads().resetAfter {
topSites = StrictMode.allowThreadDiskReads().resetPoliciesAfter {
requireComponents.core.topSiteStorage.cachedTopSites
},
tip = FenixTipManager(listOf(MigrationTipProvider(requireContext()))).getTip()
......
......@@ -6,7 +6,7 @@ package org.mozilla.fenix.whatsnew
import android.content.Context
import android.os.StrictMode
import mozilla.components.support.ktx.android.os.resetAfter
import org.mozilla.fenix.ext.resetPoliciesAfter
// This file is a modified port from Focus Android
......@@ -70,7 +70,7 @@ class WhatsNew private constructor(private val storage: WhatsNewStorage) {
fun shouldHighlightWhatsNew(context: Context): Boolean {
return shouldHighlightWhatsNew(
ContextWhatsNewVersion(context),
StrictMode.allowThreadDiskReads().resetAfter {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
SharedPreferenceWhatsNewStorage(context)
}
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment