Skip to content

Commit

Permalink
Merge branch 'mozilla_main' into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijitvalluri committed Sep 29, 2020
2 parents eb7d5f7 + 2fda22e commit e04fbe2
Show file tree
Hide file tree
Showing 78 changed files with 1,232 additions and 502 deletions.
6 changes: 3 additions & 3 deletions .cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
treeherder-symbol: Nd
target-tasks-method: nightly
when:
- {hour: 18, minute: 0}
- {hour: 5, minute: 0}
# This is a temporary hook in order to not overload Google Play.
# See bug 1628413 for more context.
- name: nightly-on-google-play
Expand All @@ -19,7 +19,7 @@ jobs:
treeherder-symbol: Nd-gp
target-tasks-method: nightly-on-google-play
when:
- {hour: 6, minute: 0}
- {hour: 17, minute: 0}
- name: fennec-production
job:
type: decision-task
Expand All @@ -31,7 +31,7 @@ jobs:
type: decision-task
treeherder-symbol: bump-ac
target-tasks-method: bump_android_components
when: [{hour: 14, minute: 0}]
when: [{hour: 15, minute: 30}]
- name: screenshots
job:
type: decision-task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ class TabbedBrowsingTest {
}.openTabTray {
verifyNoTabsOpened()
verifyNewTabButton()
verifyTabTrayOverflowMenu(false)
verifyTabTrayOverflowMenu(true)
}.toggleToPrivateTabs {
verifyNoTabsOpened()
verifyNewTabButton()
verifyTabTrayOverflowMenu(false)
verifyTabTrayOverflowMenu(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import androidx.preference.PreferenceManager
import leakcanary.AppWatcher
import leakcanary.LeakCanary
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.resetPoliciesAfter

class DebugFenixApplication : FenixApplication() {

override fun setupLeakCanary() {
val isEnabled = StrictMode.allowThreadDiskReads().resetPoliciesAfter {
val isEnabled = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getPreferenceKey(R.string.pref_key_leakcanary), true)
}
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ import mozilla.components.support.rusthttp.RustHttpConfig
import mozilla.components.support.rustlog.RustLog
import mozilla.components.support.utils.logElapsedTime
import mozilla.components.support.webextensions.WebExtensionSupport
import org.mozilla.fenix.StrictModeManager.enableStrictMode
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.components.metrics.MetricServiceType
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.StorageStatsMetrics
import org.mozilla.fenix.perf.StartupTimeline
Expand Down Expand Up @@ -126,11 +124,11 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
val megazordSetup = setupMegazord()

setDayNightTheme()
enableStrictMode(true)
components.strictMode.enableStrictMode(true)
warmBrowsersCache()

// Make sure the engine is initialized and ready to use.
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
components.core.engine.warmUp()
}
initializeWebExtensionSupport()
Expand Down Expand Up @@ -451,7 +449,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
applicationContext.resources.configuration.uiMode = config.uiMode

// random StrictMode onDiskRead violation even when Fenix is not running in the background.
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
super.onConfigurationChanged(config)
}
}
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import org.mozilla.fenix.ext.breadcrumb
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
Expand Down Expand Up @@ -150,9 +149,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
private lateinit var navigationToolbar: Toolbar

final override fun onCreate(savedInstanceState: Bundle?) {
StrictModeManager.changeStrictModePolicies(supportFragmentManager)
components.strictMode.attachListenerToDisablePenaltyDeath(supportFragmentManager)
// There is disk read violations on some devices such as samsung and pixel for android 9/10
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
super.onCreate(savedInstanceState)
}

Expand Down Expand Up @@ -757,7 +756,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}

override fun attachBaseContext(base: Context) {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
base.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
super.attachBaseContext(base)
}
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.mozilla.fenix.components.IntentProcessorType
import org.mozilla.fenix.components.getType
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.StartupTimeline
import org.mozilla.fenix.shortcut.NewTabShortcutIntentProcessor
Expand All @@ -28,7 +27,7 @@ class IntentReceiverActivity : Activity() {
@VisibleForTesting
override fun onCreate(savedInstanceState: Bundle?) {
// StrictMode violation on certain devices such as Samsung
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
super.onCreate(savedInstanceState)
}

Expand Down Expand Up @@ -68,7 +67,7 @@ class IntentReceiverActivity : Activity() {
)
}
// StrictMode violation on certain devices such as Samsung
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
startActivity(intent)
}
finish() // must finish() after starting the other activity
Expand Down
56 changes: 35 additions & 21 deletions app/src/main/java/org/mozilla/fenix/StrictModeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ import android.os.Build
import android.os.StrictMode
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import mozilla.components.support.ktx.android.os.resetAfter

private const val MANUFACTURE_HUAWEI: String = "HUAWEI"
private const val MANUFACTURE_ONE_PLUS: String = "OnePlus"

/**
* Manages strict mode settings for the application.
*/
object StrictModeManager {
class StrictModeManager(config: Config) {

// This is public so it can be used by inline functions.
val isEnabledByBuildConfig = config.channel.isDebug

/***
* Enables strict mode for debug purposes. meant to be run only in the main process.
* @param setPenaltyDeath boolean value to decide setting the penaltyDeath as a penalty.
* @param setPenaltyDialog boolean value to decide setting the dialog box as a penalty.
* Note: dialog penalty cannot be set with penaltyDeath
*/
fun enableStrictMode(setPenaltyDeath: Boolean, setPenaltyDialog: Boolean = false) {
if (Config.channel.isDebug) {
fun enableStrictMode(setPenaltyDeath: Boolean) {
if (isEnabledByBuildConfig) {
val threadPolicy = StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
if (setPenaltyDeath && Build.MANUFACTURER !in strictModeExceptionList) {
threadPolicy.penaltyDeath()
}

// dialog penalty cannot be set with penaltyDeath
if (!setPenaltyDeath && setPenaltyDialog) {
threadPolicy.penaltyDialog()
}

StrictMode.setThreadPolicy(threadPolicy.build())

val builder = StrictMode.VmPolicy.Builder()
Expand All @@ -47,33 +46,48 @@ object StrictModeManager {
builder.detectContentUriWithoutPermission()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (setPenaltyDeath || setPenaltyDialog) {
builder.permitNonSdkApiUsage()
} else {
builder.detectNonSdkApiUsage()
}
builder.detectNonSdkApiUsage()
}
StrictMode.setVmPolicy(builder.build())
}
}

/**
* Revert strict mode to disable penalty. Tied to fragment lifecycle since strict mode
* Revert strict mode to disable penalty based on fragment lifecycle since strict mode
* needs to switch to penalty logs. Using the fragment life cycle allows decoupling from any
* specific fragment.
*/
fun changeStrictModePolicies(fragmentManager: FragmentManager) {
fun attachListenerToDisablePenaltyDeath(fragmentManager: FragmentManager) {
fragmentManager.registerFragmentLifecycleCallbacks(object :
FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
enableStrictMode(setPenaltyDeath = false, setPenaltyDialog = false)
enableStrictMode(setPenaltyDeath = false)
fm.unregisterFragmentLifecycleCallbacks(this)
}
}, false)
}

private const val MANUFACTURE_HUAWEI: String = "HUAWEI"
private const val MANUFACTURE_ONE_PLUS: String = "OnePlus"
/**
* Runs the given [functionBlock] and sets the given [StrictMode.ThreadPolicy] after its
* completion when in a build configuration that has StrictMode enabled. If StrictMode is
* not enabled, simply runs the [functionBlock].
*
* This function is written in the style of [AutoCloseable.use].
*
* This is significantly less convenient to run than when it was written as an extension function
* on [StrictMode.ThreadPolicy] but I think this is okay: it shouldn't be easy to ignore StrictMode.
*
* @return the value returned by [functionBlock].
*/
inline fun <R> resetAfter(policy: StrictMode.ThreadPolicy, functionBlock: () -> R): R {
// Calling resetAfter takes 1-2ms (unknown device) so we only execute it if StrictMode can
// actually be enabled. https://github.com/mozilla-mobile/fenix/issues/11617
return if (isEnabledByBuildConfig) {
policy.resetAfter(functionBlock)
} else {
functionBlock()
}
}

/**
* There are certain manufacturers that have custom font classes for the OS systems.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
)
},
onCloseTab = { closedSession ->
val tab = store.state.findTab(closedSession.id)
?: return@DefaultBrowserToolbarController
val isSelected = tab.id == context.components.core.store.state.selectedTabId
val tab = store.state.findTab(closedSession.id) ?: return@DefaultBrowserToolbarController

val snackbarMessage = if (tab.content.private) {
requireContext().getString(R.string.snackbar_private_tab_closed)
Expand All @@ -276,12 +274,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
snackbarMessage,
requireContext().getString(R.string.snackbar_deleted_undo),
{
sessionManager.add(
closedSession,
isSelected,
engineSessionState = tab.engineState.engineSessionState
)
requireComponents.useCases.tabsUseCases.undo.invoke()
},
paddedForBottomToolbar = true,
operation = { }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.shortcut.PwaOnboardingObserver
import org.mozilla.fenix.trackingprotection.TrackingProtectionOverlay
Expand Down Expand Up @@ -110,7 +109,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
)

readerViewFeature.set(
feature = StrictMode.allowThreadDiskReads().resetPoliciesAfter {
feature = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
ReaderViewFeature(
context,
components.core.engine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ class ToolbarGestureHandler(
when (getDestination()) {
is Destination.Tab -> {
// Restrict the range of motion for the views so you can't start a swipe in one direction
// then move your finger far enough in the other direction and make the content visually
// start sliding off screen the other way.
// then move your finger far enough or in the other direction and make the content visually
// start sliding off screen.
tabPreview.translationX = when (gestureDirection) {
GestureDirection.RIGHT_TO_LEFT -> min(
windowWidth.toFloat() + previewOffset,
tabPreview.translationX - distanceX
)
).coerceAtLeast(0f)
GestureDirection.LEFT_TO_RIGHT -> max(
-windowWidth.toFloat() - previewOffset,
tabPreview.translationX - distanceX
)
).coerceAtMost(0f)
}
contentLayout.translationX = when (gestureDirection) {
GestureDirection.RIGHT_TO_LEFT -> min(
0f,
contentLayout.translationX - distanceX
)
).coerceAtLeast(-windowWidth.toFloat() - previewOffset)
GestureDirection.LEFT_TO_RIGHT -> max(
0f,
contentLayout.translationX - distanceX
)
).coerceAtMost(windowWidth.toFloat() + previewOffset)
}
}
is Destination.None -> {
Expand Down

0 comments on commit e04fbe2

Please sign in to comment.