Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data class Preference(
val hideBatteryLevelTextChargingIcon: Boolean = false,
val supportRealTimeNetworkSpeed: Boolean = true,
val showSeparateUpDownNetworkSpeeds: Boolean = false,
val networkSpeedThresholdKb: Int = 0,
val setStatusBarClockFormat: Boolean = false,
val statusBarClockFormat: String = "HH:mm",
val setStatusBarClockTextScale: Boolean = false,
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/io/github/soclear/oneuix/hook/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ class Main : IXposedHookLoadPackage, IXposedHookInitPackageResources, IXposedHoo
}

if (preference.systemUI.statusBar.showSeparateUpDownNetworkSpeeds) {
Network.showSeparateUpDownNetworkSpeeds(lpparam)
Network.showSeparateUpDownNetworkSpeeds(
lpparam,
thresholdKb = preference.systemUI.statusBar.networkSpeedThresholdKb
)
}

if (preference.systemUI.statusBar.setStatusBarClockFormat) {
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/io/github/soclear/oneuix/hook/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ object Network {

fun showSeparateUpDownNetworkSpeeds(
loadPackageParam: LoadPackageParam,
intervalMillisecond: Long = 3000L
intervalMillisecond: Long = 3000L,
thresholdKb: Int = 0
) {
if (loadPackageParam.packageName != Package.SYSTEMUI || intervalMillisecond <= 0L) {
return
Expand Down Expand Up @@ -115,6 +116,9 @@ object Network {
): String {
val txBytesPerSecond = (current.totalTx - previous.totalTx) / actualIntervalSeconds
val rxBytesPerSecond = (current.totalRx - previous.totalRx) / actualIntervalSeconds
if (!shouldDisplayNetworkSpeed(txBytesPerSecond, rxBytesPerSecond, thresholdKb)) {
return ""
}
return "${formatSpeed(txBytesPerSecond)}\n${formatSpeed(rxBytesPerSecond)}"
}

Expand Down Expand Up @@ -303,3 +307,14 @@ object Network {
}
}
}

internal fun shouldDisplayNetworkSpeed(
txBytesPerSecond: Float,
rxBytesPerSecond: Float,
thresholdKb: Int,
): Boolean {
if (thresholdKb <= 0) return true
val thresholdBytesPerSecond = thresholdKb * 1024f
return txBytesPerSecond > thresholdBytesPerSecond ||
rxBytesPerSecond > thresholdBytesPerSecond
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,47 @@ fun DetailPaneSystemUI(
onEvent(SystemUIEvent.StatusBar.ShowSeparateUpDownNetworkSpeeds(it))
}
)
Column {
var expanded by rememberSaveable { mutableStateOf(false) }
var threshold by remember {
mutableIntStateOf(uiState.statusBar.networkSpeedThresholdKb)
}
SwitchItem(
icon = ImageVector.vectorResource(id = R.drawable.net_speed),
title = stringResource(id = R.string.networkSpeedThreshold_title),
summary = if (uiState.statusBar.networkSpeedThresholdKb > 0) {
"${uiState.statusBar.networkSpeedThresholdKb} KB/s"
} else null,
modifier = Modifier.animateContentSize(),
clickable = true,
onClick = { expanded = !expanded },
checked = uiState.statusBar.networkSpeedThresholdKb > 0,
onCheckedChange = {
if (it && threshold == 0) threshold = 1
if (!it) threshold = 0
onEvent(SystemUIEvent.StatusBar.NetworkSpeedThreshold(threshold))
}
)
AnimatedVisibility(expanded && uiState.statusBar.networkSpeedThresholdKb > 0) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(horizontal = 16.dp),
) {
OutlinedTextField(
value = threshold.toString(),
onValueChange = { threshold = it.toIntOrNull()?.coerceAtLeast(1) ?: 1 },
modifier = Modifier.weight(1f),
label = { Text(stringResource(id = R.string.networkSpeedThreshold_label)) }
)
Spacer(modifier = Modifier.width(8.dp))
Button(onClick = {
onEvent(SystemUIEvent.StatusBar.NetworkSpeedThreshold(threshold))
}) {
Text(text = stringResource(id = R.string.confirm))
}
}
}
}
Column {
var expanded by rememberSaveable { mutableStateOf(false) }

Expand Down Expand Up @@ -992,6 +1033,9 @@ sealed interface SystemUIEvent {
@JvmInline
value class ShowSeparateUpDownNetworkSpeeds(val value: Boolean) : StatusBar

@JvmInline
value class NetworkSpeedThreshold(val value: Int) : StatusBar

@JvmInline
value class SetStatusBarClockFormat(val value: Boolean) : StatusBar

Expand Down Expand Up @@ -1293,6 +1337,16 @@ private fun SettingViewModel.onStatusBarEvent(event: SystemUIEvent.StatusBar) {
)
}

is SystemUIEvent.StatusBar.NetworkSpeedThreshold -> {
preference.copy(
systemUI = preference.systemUI.copy(
statusBar = preference.systemUI.statusBar.copy(
networkSpeedThresholdKb = event.value
)
)
)
}

is SystemUIEvent.StatusBar.SetStatusBarClockFormat -> {
preference.copy(
systemUI = preference.systemUI.copy(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string name="supportRealTimeNetworkSpeed_summary">设置->通知->高级设置->显示实时网速</string>
<string name="showSeparateUpDownNetworkSpeeds_title">状态栏显示上传下载网速</string>
<string name="showSeparateUpDownNetworkSpeeds_summary">上行为上传速度,下行为下载速度</string>
<string name="networkSpeedThreshold_title">网速显示阈值</string>
<string name="networkSpeedThreshold_label">阈值(KB/s)</string>
<string name="turnOn5gQsTile_title">开启快捷设置 5G 磁贴</string>
<string name="turnOn5gQsTile_summary">需要勾选系统 UI 和通话设置</string>
<string name="root5gQsTile_summary">请授予本应用 root 权限后手动添加 5G 磁贴</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string name="supportRealTimeNetworkSpeed_summary">Settings -> Notifications -> Advanced settings -> Show real-time network speed</string>
<string name="showSeparateUpDownNetworkSpeeds_title">Show separate upload/download speeds in status bar</string>
<string name="showSeparateUpDownNetworkSpeeds_summary">Top is upload speed, bottom is download speed</string>
<string name="networkSpeedThreshold_title">Network speed display threshold</string>
<string name="networkSpeedThreshold_label">Threshold (KB/s)</string>
<string name="turnOn5gQsTile_title">Enable 5G Quick Settings tile</string>
<string name="turnOn5gQsTile_summary">Requires checking System UI and Call Settings</string>
<string name="root5gQsTile_summary">Please grant root access to this app, then manually add the 5G tile</string>
Expand Down
14 changes: 14 additions & 0 deletions app/src/test/java/io/github/soclear/oneuix/hook/NetworkTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.soclear.oneuix.hook

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class NetworkTest {
@Test
fun displaysWhenEitherDirectionExceedsThreshold() {
assertTrue(shouldDisplayNetworkSpeed(1025f, 0f, 1))
assertTrue(shouldDisplayNetworkSpeed(0f, 1025f, 1))
assertFalse(shouldDisplayNetworkSpeed(1024f, 1024f, 1))
}
}