mirror of
https://github.com/SagerNet/sing-box-for-android.git
synced 2025-04-06 05:17:38 +03:00
Build memory limiter for android
This commit is contained in:
parent
e7b2c111a6
commit
f9fef233ca
6 changed files with 29 additions and 0 deletions
|
@ -122,6 +122,7 @@ class BoxService(
|
||||||
|
|
||||||
DefaultNetworkMonitor.start()
|
DefaultNetworkMonitor.start()
|
||||||
Libbox.registerLocalDNSTransport(LocalResolver)
|
Libbox.registerLocalDNSTransport(LocalResolver)
|
||||||
|
Libbox.setMemoryLimit(!Settings.disableMemoryLimit)
|
||||||
|
|
||||||
val newService = try {
|
val newService = try {
|
||||||
Libbox.newService(content, platformInterface)
|
Libbox.newService(content, platformInterface)
|
||||||
|
|
|
@ -6,6 +6,7 @@ object SettingsKey {
|
||||||
const val SERVICE_MODE = "service_mode"
|
const val SERVICE_MODE = "service_mode"
|
||||||
const val ANALYTICS_ALLOWED = "analytics_allowed"
|
const val ANALYTICS_ALLOWED = "analytics_allowed"
|
||||||
const val CHECK_UPDATE_ENABLED = "check_update_enabled"
|
const val CHECK_UPDATE_ENABLED = "check_update_enabled"
|
||||||
|
const val DISABLE_MEMORY_LIMIT = "disable_memory_limit"
|
||||||
|
|
||||||
// cache
|
// cache
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ object Settings {
|
||||||
|
|
||||||
var analyticsAllowed by dataStore.int(SettingsKey.ANALYTICS_ALLOWED) { ANALYSIS_UNKNOWN }
|
var analyticsAllowed by dataStore.int(SettingsKey.ANALYTICS_ALLOWED) { ANALYSIS_UNKNOWN }
|
||||||
var checkUpdateEnabled by dataStore.boolean(SettingsKey.CHECK_UPDATE_ENABLED) { true }
|
var checkUpdateEnabled by dataStore.boolean(SettingsKey.CHECK_UPDATE_ENABLED) { true }
|
||||||
|
var disableMemoryLimit by dataStore.boolean(SettingsKey.DISABLE_MEMORY_LIMIT)
|
||||||
|
|
||||||
fun serviceClass(): Class<*> {
|
fun serviceClass(): Class<*> {
|
||||||
return when (serviceMode) {
|
return when (serviceMode) {
|
||||||
|
|
|
@ -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 {
|
binding.communityButton.setOnClickListener {
|
||||||
it.context.launchCustomTab("https://community.sagernet.org/")
|
it.context.launchCustomTab("https://community.sagernet.org/")
|
||||||
}
|
}
|
||||||
|
@ -97,6 +103,8 @@ class SettingsFragment : Fragment() {
|
||||||
binding.checkUpdateEnabled.isEnabled = appCenterEnabled
|
binding.checkUpdateEnabled.isEnabled = appCenterEnabled
|
||||||
binding.checkUpdateEnabled.text = EnabledType.from(checkUpdateEnabled).name
|
binding.checkUpdateEnabled.text = EnabledType.from(checkUpdateEnabled).name
|
||||||
binding.checkUpdateEnabled.setSimpleItems(R.array.enabled)
|
binding.checkUpdateEnabled.setSimpleItems(R.array.enabled)
|
||||||
|
binding.disableMemoryLimit.text = EnabledType.from(!Settings.disableMemoryLimit).name
|
||||||
|
binding.disableMemoryLimit.setSimpleItems(R.array.enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,23 @@
|
||||||
|
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/disableMemoryLimit"
|
||||||
|
style="@style/Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:hint="@string/memory_limit">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"
|
||||||
|
android:text="@string/enabled"
|
||||||
|
app:simpleItems="@array/enabled" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -79,5 +79,6 @@
|
||||||
<string name="app_description">Android client for sing-box, the universal proxy platform.</string>
|
<string name="app_description">Android client for sing-box, the universal proxy platform.</string>
|
||||||
<string name="documentation_button">Documentation</string>
|
<string name="documentation_button">Documentation</string>
|
||||||
<string name="community_button">Community</string>
|
<string name="community_button">Community</string>
|
||||||
|
<string name="memory_limit">Memory Limit</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue