Add a setting to hide memory pressure from a-c

This adds a setting in "Customize" to fix
https://github.com/fork-maintainers/iceraven-browser/issues/115
pull/157/head
Adam Novak 4 years ago
parent f801c65d7b
commit 15202cc076

@ -326,7 +326,22 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
runOnlyInMainProcess {
components.core.icons.onTrimMemory(level)
components.core.store.dispatch(SystemAction.LowMemoryAction(level))
// We want to be judicious in passing low mamory messages to
// android-components, because it is (at time of writing) hardcoded
// to drop tab states (and any user data in them) as soon as we
// reach "moderate" memory pressure on the system, even if the
// browser is in no danger of being killed. See
// https://github.com/mozilla-mobile/android-components/blob/38186676d46c555b5a24268e5fa361e45e57102c/components/browser/session/src/main/java/mozilla/components/browser/session/engine/middleware/TrimMemoryMiddleware.kt#L53-L64
// for the relvant android-components code and
// https://stuff.mit.edu/afs/sipb/project/android/docs/reference/android/content/ComponentCallbacks2.html
// for the list of memory pressure levels.
val settings = this.settings()
if (settings.shouldRelinquishMemoryUnderPressure) {
// We will give up our RAM when asked nicely
components.core.store.dispatch(SystemAction.LowMemoryAction(level))
}
// Otherwise we will die for our RAM, if pressed.
}
}

@ -64,6 +64,7 @@ class CustomizationFragment : PreferenceFragmentCompat() {
setupHomeCategory()
setupGesturesCategory()
setupAddonsCustomizationCategory()
setupSystemBehaviorCategory()
}
private fun setupRadioGroups() {
@ -256,4 +257,11 @@ class CustomizationFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}
private fun setupSystemBehaviorCategory() {
requirePreference<SwitchPreference>(R.string.pref_key_relinquish_memory_under_pressure).apply {
isChecked = context.settings().shouldRelinquishMemoryUnderPressure
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}
}

@ -550,6 +550,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
appContext.getPreferenceKey(R.string.pref_key_strip_url),
default = true
)
var shouldRelinquishMemoryUnderPressure by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_relinquish_memory_under_pressure),
default = true
)
/**
* Check each active accessibility service to see if it can perform gestures, if any can,

@ -133,7 +133,7 @@
<string name="pref_key_dynamic_toolbar" translatable="false">pref_key_dynamic_toolbar</string>
<string name="pref_key_swipe_toolbar_switch_tabs" translatable="false">pref_key_swipe_toolbar_switch_tabs</string>
<string name="pref_key_swipe_toolbar_show_tabs" translatable="false">pref_key_swipe_toolbar_show_tabs</string>
<!-- Tabs Tray Customization Settings -->
<string name="pref_tabs_tray_settings_category" translatable="false">pref_tabs_tray_settings_category</string>
<string name="pref_key_tabs_tray_compact_tab" translatable="false">pref_key_tabs_tray_compact_tab</string>
@ -151,6 +151,10 @@
<string name="pref_addons_settings_category" translatable="false">pref_addons_settings_category</string>
<string name="pref_key_addons_custom_account" translatable="false">pref_key_addons_custom_account</string>
<string name="pref_key_addons_custom_collection" translatable="false">pref_key_addons_custom_collection</string>
<!-- System Customization Settings -->
<string name="pref_system_behavior_settings_category" translatable="false">pref_system_behavior_settings_category</string>
<string name="pref_key_relinquish_memory_under_pressure" translatable="false">pref_key_relinquish_memory_under_pressure</string>
<!-- Tracking Protection Settings -->
<string name="pref_key_etp_learn_more" translatable="false">pref_key_etp_learn_more</string>

@ -1585,6 +1585,13 @@
<string name="addons_custom_source_account">Set custom add-ons account</string>
<!-- Label for add-ons custom source collection preference -->
<string name="addons_custom_source_collection">Set custom add-ons collection</string>
<!-- Preference category for system behavior customization -->
<string name="preferences_system_behavior">Configure system behavior</string>
<!-- Title for relinquish memory preference in customization settings -->
<string name="preferences_relinquish_memory_title">Suspend tabs to avoid being killed for memory</string>
<!-- Description for relinquish memory preference in customization settings -->
<string name="preferences_relinquish_memory_description">If enabled, tabs will be suspended and page state lost when the system is low on memory</string>
<!-- Label for enable compact tabs in tabs tray preference -->
<string name="enable_compact_tabs">Enable compact tabs</string>

@ -138,4 +138,17 @@
android:title="@string/addons_custom_source_collection" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_system_behavior_settings_category"
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_system_behavior"
app:allowDividerAbove="true"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_relinquish_memory_under_pressure"
android:summary="@string/preferences_relinquish_memory_description"
android:title="@string/preferences_relinquish_memory_title" />
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>

Loading…
Cancel
Save