Skip to content
Merged
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 @@ -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) }
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
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 @@ -18,6 +18,8 @@
<string name="hideBatteryIcon_summary">隐藏电池图标,插入电源时显示充电图标。不影响电池百分比</string>
<string name="hideWifiGenerationDigit_title">隐藏 Wi-Fi 代数数字</string>
<string name="hideWifiGenerationDigit_summary">隐藏 Wi-Fi 图标旁的数字(如 5、6、7),显示普通 Wi-Fi 图标。</string>
<string name="smartConnectivity_title">智能连接</string>
<string name="smartConnectivity_summary">连接 Wi-Fi 时隐藏状态栏中的移动网络信号图标,在快捷设置中仍然显示。</string>
<string name="addBatteryLevelText_title">显示电量文字</string>
<string name="addBatteryLevelText_summary">在电池图标旁显示电量文字,如 96%</string>
<string name="hideBatteryLevelTextPercentageSign_title">隐藏百分号</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 @@ -18,6 +18,8 @@
<string name="hideBatteryIcon_summary">Hides the battery icon while displaying the charging icon when plugged. Doesn\'t affect the battery percentage</string>
<string name="hideWifiGenerationDigit_title">Hide Wi-Fi generation number</string>
<string name="hideWifiGenerationDigit_summary">Hides the digit next to the Wi-Fi icon (for example 5, 6 or 7) and shows the plain Wi-Fi icon.</string>
<string name="smartConnectivity_title">Smart connectivity</string>
<string name="smartConnectivity_summary">Hide cellular signal bars while connected to Wi-Fi. Keep them visible in Quick Settings.</string>
<string name="addBatteryLevelText_title">Show battery level text</string>
<string name="addBatteryLevelText_summary">Display battery level as text alongside the icon, e.g. 96%</string>
<string name="hideBatteryLevelTextPercentageSign_title">Hide percentage sign</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions hook/src/main/java/io/github/soclear/oneuix/hook/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ViewGroup, MutableSet<String>>()
val wifiNetworks = mutableSetOf<Network>()

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<String>, 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()))
}
}
Loading