From 83098e3535747d72fff0b81838e6a9860dabeca0 Mon Sep 17 00:00:00 2001
From: Raman <81064836+cybr47@users.noreply.github.com>
Date: Sun, 29 Nov 2026 13:04:56 +0000
Subject: [PATCH] feat(statusbar): add Smart connectivity
Hide cellular signal slots in the regular status bar while Wi-Fi is connected. Keep the Quick Settings header on its own visibility rules and monitor Wi-Fi in SystemUI.
---
.../oneuix/ui/category/DetailPaneSystemUI.kt | 16 +++
app/src/main/res/values-zh/strings.xml | 2 +
app/src/main/res/values/strings.xml | 2 +
.../soclear/oneuix/common/Preference.kt | 1 +
.../io/github/soclear/oneuix/hook/Main.kt | 4 +
.../systemui/statusbar/SmartConnectivity.kt | 101 ++++++++++++++++++
6 files changed, 126 insertions(+)
create mode 100644 hook/src/main/java/io/github/soclear/oneuix/hook/systemui/statusbar/SmartConnectivity.kt
diff --git a/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt b/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt
index e952b75f..9cbe7bb2 100644
--- a/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt
+++ b/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt
@@ -294,6 +294,13 @@ fun DetailPaneSystemUI(
onEvent(SystemUIEvent.StatusBar.HideWifiGenerationDigit(it))
}
)
+ SwitchItem(
+ icon = ImageVector.vectorResource(id = R.drawable.wifi_link_speed),
+ title = stringResource(R.string.smartConnectivity_title),
+ summary = stringResource(R.string.smartConnectivity_summary),
+ checked = uiState.statusBar.smartConnectivity,
+ onCheckedChange = { onEvent(SystemUIEvent.StatusBar.SmartConnectivity(it)) }
+ )
}
Column {
var expanded by rememberSaveable { mutableStateOf(false) }
@@ -1161,6 +1168,9 @@ sealed interface SystemUIEvent {
@JvmInline
value class HideWifiGenerationDigit(val value: Boolean) : StatusBar
+ @JvmInline
+ value class SmartConnectivity(val value: Boolean) : StatusBar
+
@JvmInline
value class AddBatteryLevelText(val value: Boolean) : StatusBar
@@ -1525,6 +1535,12 @@ private fun SettingViewModel.onStatusBarEvent(event: SystemUIEvent.StatusBar) {
)
}
+ is SystemUIEvent.StatusBar.SmartConnectivity -> preference.copy(
+ systemUI = preference.systemUI.copy(
+ statusBar = preference.systemUI.statusBar.copy(smartConnectivity = event.value)
+ )
+ )
+
is SystemUIEvent.StatusBar.AddBatteryLevelText -> {
preference.copy(
systemUI = preference.systemUI.copy(
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 8f8d274c..041e4e52 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -18,6 +18,8 @@
隐藏电池图标,插入电源时显示充电图标。不影响电池百分比
隐藏 Wi-Fi 代数数字
隐藏 Wi-Fi 图标旁的数字(如 5、6、7),显示普通 Wi-Fi 图标。
+ 智能连接
+ 连接 Wi-Fi 时隐藏状态栏中的移动网络信号图标,在快捷设置中仍然显示。
显示电量文字
在电池图标旁显示电量文字,如 96%
隐藏百分号
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 945675b0..928ac298 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,6 +18,8 @@
Hides the battery icon while displaying the charging icon when plugged. Doesn\'t affect the battery percentage
Hide Wi-Fi generation number
Hides the digit next to the Wi-Fi icon (for example 5, 6 or 7) and shows the plain Wi-Fi icon.
+ Smart connectivity
+ Hide cellular signal bars while connected to Wi-Fi. Keep them visible in Quick Settings.
Show battery level text
Display battery level as text alongside the icon, e.g. 96%
Hide percentage sign
diff --git a/common/src/main/java/io/github/soclear/oneuix/common/Preference.kt b/common/src/main/java/io/github/soclear/oneuix/common/Preference.kt
index 6fc4de35..cf9a832f 100644
--- a/common/src/main/java/io/github/soclear/oneuix/common/Preference.kt
+++ b/common/src/main/java/io/github/soclear/oneuix/common/Preference.kt
@@ -54,6 +54,7 @@ data class Preference(
val hideBatteryLevelTextPercentageSign: Boolean = false,
val hideBatteryLevelTextChargingIcon: Boolean = false,
val hideWifiGenerationDigit: Boolean = false,
+ val smartConnectivity: Boolean = false,
val setStatusBarClockFormat: Boolean = false,
val statusBarClockFormat: String = "HH:mm",
val setStatusBarClockTextScale: Boolean = false,
diff --git a/hook/src/main/java/io/github/soclear/oneuix/hook/Main.kt b/hook/src/main/java/io/github/soclear/oneuix/hook/Main.kt
index 66f289c0..2c3a0979 100644
--- a/hook/src/main/java/io/github/soclear/oneuix/hook/Main.kt
+++ b/hook/src/main/java/io/github/soclear/oneuix/hook/Main.kt
@@ -15,6 +15,7 @@ import io.github.soclear.oneuix.hook.systemui.LockscreenShadeCloseFade
import io.github.soclear.oneuix.hook.systemui.WifiGeneration
import io.github.soclear.oneuix.hook.systemui.statusbar.ESIM
import io.github.soclear.oneuix.hook.systemui.statusbar.HideBatteryIcon
+import io.github.soclear.oneuix.hook.systemui.statusbar.SmartConnectivity
import io.github.soclear.oneuix.hook.systemui.Notification
import io.github.soclear.oneuix.hook.systemui.QS
import io.github.soclear.oneuix.hook.systemui.statusbar.StatusBar
@@ -350,6 +351,9 @@ class Main : XposedModule() {
if (preference.systemUI.statusBar.hideWifiGenerationDigit) {
WifiGeneration.hideDigit()
}
+ if (preference.systemUI.statusBar.smartConnectivity) {
+ SmartConnectivity.install()
+ }
}
} else {
if (preference.systemUI.statusBar.hideBatteryIcon) {
diff --git a/hook/src/main/java/io/github/soclear/oneuix/hook/systemui/statusbar/SmartConnectivity.kt b/hook/src/main/java/io/github/soclear/oneuix/hook/systemui/statusbar/SmartConnectivity.kt
new file mode 100644
index 00000000..d42d0b7d
--- /dev/null
+++ b/hook/src/main/java/io/github/soclear/oneuix/hook/systemui/statusbar/SmartConnectivity.kt
@@ -0,0 +1,101 @@
+package io.github.soclear.oneuix.hook.systemui.statusbar
+
+import android.net.ConnectivityManager
+import android.net.Network
+import android.net.NetworkCapabilities
+import android.net.NetworkRequest
+import android.os.Handler
+import android.os.Looper
+import android.view.ViewGroup
+import io.github.libxposed.api.XposedModule
+import io.github.soclear.oneuix.hook.util.afterAttachTry
+import io.github.soclear.oneuix.hook.util.xlog
+import java.util.WeakHashMap
+
+internal object SmartConnectivity {
+ private val cellularSlots = listOf("mobile", "mobile2", "stacked_mobile")
+
+ context(xposedModule: XposedModule)
+ fun install() = afterAttachTry {
+ val connectivity = getSystemService(ConnectivityManager::class.java) ?: return@afterAttachTry
+ val controllerClass = classLoader.loadClass(
+ "com.android.systemui.statusbar.phone.ui.StatusBarIconControllerImpl"
+ )
+ val managerClass = classLoader.loadClass("com.android.systemui.statusbar.phone.ui.IconManager")
+ val containerClass = classLoader.loadClass("com.android.systemui.statusbar.phone.StatusIconContainer")
+ val locationField = managerClass.getDeclaredField("mLocation").apply { isAccessible = true }
+ val groupField = managerClass.getDeclaredField("mGroup").apply { isAccessible = true }
+ val ignoredSlotsField = containerClass.getDeclaredField("mIgnoredSlots").apply { isAccessible = true }
+ val addIconGroup = controllerClass.getDeclaredMethod("addIconGroup", managerClass)
+ val removeIconGroup = controllerClass.getDeclaredMethod("removeIconGroup", managerClass)
+ val addIgnoredSlot = containerClass.getDeclaredMethod("addIgnoredSlot", String::class.java)
+ val removeIgnoredSlot = containerClass.getDeclaredMethod("removeIgnoredSlot", String::class.java)
+
+ val groups = WeakHashMap>()
+ val wifiNetworks = mutableSetOf()
+
+ fun statusBarGroup(manager: Any?): ViewGroup? {
+ val location = (locationField.get(manager) as? Enum<*>)?.name
+ // Samsung assigns the Quick Settings header its own QS icon group.
+ if (location != "HOME" && location != "KEYGUARD") return null
+ return (groupField.get(manager) as? ViewGroup)?.takeIf(containerClass::isInstance)
+ }
+
+ fun updateGroup(group: ViewGroup, addedSlots: MutableSet, hide: Boolean) {
+ runCatching {
+ if (hide) {
+ val ignoredSlots = ignoredSlotsField.get(group) as Set<*>
+ // Ignoring a slot removes its width from the bar. Keep track of our additions
+ // so a disconnect restores Samsung's visibility rules for the icon.
+ for (slot in cellularSlots) {
+ if (slot !in ignoredSlots) {
+ addIgnoredSlot.invoke(group, slot)
+ addedSlots.add(slot)
+ }
+ }
+ } else {
+ for (slot in addedSlots) removeIgnoredSlot.invoke(group, slot)
+ addedSlots.clear()
+ }
+ }.onFailure { xlog(it) }
+ }
+
+ xposedModule.hook(addIconGroup).intercept { chain ->
+ val result = chain.proceed()
+ runCatching {
+ val group = statusBarGroup(chain.args[0]) ?: return@runCatching
+ val addedSlots = groups.getOrPut(group) { mutableSetOf() }
+ if (wifiNetworks.isNotEmpty()) updateGroup(group, addedSlots, hide = true)
+ }.onFailure { xlog(it) }
+ result
+ }
+
+ xposedModule.hook(removeIconGroup).intercept { chain ->
+ val result = chain.proceed()
+ runCatching {
+ val group = statusBarGroup(chain.args[0]) ?: return@runCatching
+ groups.remove(group)?.let { updateGroup(group, it, hide = false) }
+ }.onFailure { xlog(it) }
+ result
+ }
+
+ val wifiRequest = NetworkRequest.Builder()
+ .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
+ .build()
+ // SystemUI owns this callback. The OneUIX configuration app can exit after saving the toggle.
+ connectivity.registerNetworkCallback(wifiRequest, object : ConnectivityManager.NetworkCallback() {
+ override fun onAvailable(network: Network) {
+ if (wifiNetworks.add(network) && wifiNetworks.size == 1) {
+ groups.forEach { (group, addedSlots) -> updateGroup(group, addedSlots, hide = true) }
+ }
+ }
+
+ override fun onLost(network: Network) {
+ if (wifiNetworks.remove(network) && wifiNetworks.isEmpty()) {
+ groups.forEach { (group, addedSlots) -> updateGroup(group, addedSlots, hide = false) }
+ }
+ }
+ }, Handler(Looper.getMainLooper()))
+ }
+}