Build memory limiter for android

This commit is contained in:
世界
2023-07-16 12:58:17 +08:00
parent e7b2c111a6
commit f9fef233ca
6 changed files with 29 additions and 0 deletions

View File

@@ -122,6 +122,7 @@ class BoxService(
DefaultNetworkMonitor.start()
Libbox.registerLocalDNSTransport(LocalResolver)
Libbox.setMemoryLimit(!Settings.disableMemoryLimit)
val newService = try {
Libbox.newService(content, platformInterface)

View File

@@ -6,6 +6,7 @@ object SettingsKey {
const val SERVICE_MODE = "service_mode"
const val ANALYTICS_ALLOWED = "analytics_allowed"
const val CHECK_UPDATE_ENABLED = "check_update_enabled"
const val DISABLE_MEMORY_LIMIT = "disable_memory_limit"
// cache

View File

@@ -42,6 +42,7 @@ object Settings {
var analyticsAllowed by dataStore.int(SettingsKey.ANALYTICS_ALLOWED) { ANALYSIS_UNKNOWN }
var checkUpdateEnabled by dataStore.boolean(SettingsKey.CHECK_UPDATE_ENABLED) { true }
var disableMemoryLimit by dataStore.boolean(SettingsKey.DISABLE_MEMORY_LIMIT)
fun serviceClass(): Class<*> {
return when (serviceMode) {

View File

@@ -74,6 +74,12 @@ class SettingsFragment : Fragment() {
}
}
}
binding.disableMemoryLimit.addTextChangedListener {
lifecycleScope.launch(Dispatchers.IO) {
val newValue = EnabledType.valueOf(it).boolValue
Settings.disableMemoryLimit = !newValue
}
}
binding.communityButton.setOnClickListener {
it.context.launchCustomTab("https://community.sagernet.org/")
}
@@ -97,6 +103,8 @@ class SettingsFragment : Fragment() {
binding.checkUpdateEnabled.isEnabled = appCenterEnabled
binding.checkUpdateEnabled.text = EnabledType.from(checkUpdateEnabled).name
binding.checkUpdateEnabled.setSimpleItems(R.array.enabled)
binding.disableMemoryLimit.text = EnabledType.from(!Settings.disableMemoryLimit).name
binding.disableMemoryLimit.setSimpleItems(R.array.enabled)
}
}