diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..fe3d695 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,53 @@ +{ + "permissions": { + "allow": [ + "Bash(cat)", + "Read(//tmp/**)", + "Bash(./gradlew assembleDebug)", + "Bash(apt-get update *)", + "Bash(apt-get install *)", + "Bash(./gradlew clean *)", + "Bash(export ANDROID_SDK_ROOT=/opt/android-sdk)", + "Bash(yes)", + "Bash(/opt/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=/opt/android-sdk --licenses)", + "Bash(mkdir *)", + "Bash(rm *)", + "Bash(export ANDROID_SDK_ROOT=/opt/android-sdk-linux)", + "Bash(rm -rf android-35)", + "Bash(mv android-35-2 *)", + "Bash(./gradlew --offline assembleDebug)", + "Bash(rm -rf android-34-* android-35-*)", + "Read(//home/shihaam/git/sargit/**)", + "Bash(git rm *)", + "Bash(git add *)", + "Bash(git config *)", + "Bash(gradle build *)", + "Bash(gradle compileDebugKotlin)", + "Bash(gradle dependencies *)", + "WebFetch(domain:github.com)", + "Bash(gradle assemble *)", + "Bash(gradle tasks *)", + "Bash(gradle -p app tasks)", + "Bash(gradle :app:build --stacktrace)", + "Bash(gradle projects *)", + "Bash(gradle settings *)", + "Bash(gradle --debug projects)", + "Bash(gradle -S projects)", + "Bash(kotlinc *)", + "Bash(gradle *)", + "Bash(chmod +x ./gradlew)", + "Bash(./gradlew --version)", + "Bash(./gradlew build *)", + "Bash(export ANDROID_HOME=/opt/android-sdk)", + "Bash(export ANDROID_HOME=/opt/android-sdk-linux)", + "Bash(mkdir -p /opt/android-sdk-linux/licenses)", + "Bash(xargs cat)", + "Bash(git commit *)", + "Bash(git restore *)", + "Bash(python3 *)", + "Bash(aapt2 dump *)", + "Bash(aapt dump *)", + "Bash(./gradlew assembleDebug --info)" + ] + } +} diff --git a/.gitignore b/.gitignore index d4c3a57..029f1c9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ .cxx local.properties /.idea/ +/ref/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..f74378d --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Unstack + +libxposed (API 102) module that disables the stacked dual-SIM status bar icon introduced in Android 16 QPR1, bringing back separate per-SIM signal icons. + +| | Status bar | +|---|---| +| **Stock** | ![Stock stacked icon](screenshots/stock.jpg) | +| **Unstack, data on SIM 1** | ![Data on SIM 1](screenshots/sim1_data.jpg) | +| **Unstack, data on SIM 2** | ![Data on SIM 2](screenshots/sim2_data.jpg) | + +The stock stacked icon squeezes both SIMs into one glyph with a single `5G` label next to it, so the status bar no longer tells you which SIM is carrying mobile data. With Unstack, each SIM gets its own signal icon again and the network type label sits next to the SIM that's using data. + +## What it changes + +Since Android 16 QPR1, when two SIMs are active SystemUI merges their signal bars into one stacked icon. Whether that happens is decided by a `Flow` named `isStackable` on the mobile icons interactor. Reconstructed from the decompiled `SystemUI.apk` (crDroid, Android 17), it looks roughly like this: + +```kotlin +// MobileIconsInteractorImpl +val isStackable: Flow = + icons.flatMapLatest { icons -> + if (icons.isEmpty()) flowOf(false) + else combine(icons.map { it.signalLevelIcon }) { levels -> + /* true when both SIMs' cellular icons can be merged */ + } + } + +// MobileIconsViewModel +val isStackable: StateFlow = + combine(iconsAreAllVisible, interactor.isStackable) { visible, stackable -> + visible && stackable + }.stateIn(scope, SharingStarted.WhileSubscribed(), false) +``` + +The view model only shows the stacked icon when the interactor says the icons are stackable. Unstack hooks the interactor's `isStackable()` getter and makes it always return a flow of `false`: + +```kotlin +val falseFlow = MutableStateFlow(false) // created via SystemUI's own classloader + +module.hook(MobileIconsInteractorImpl::isStackable).intercept { falseFlow } +module.hook(MobileIconsInteractorKairosAdapter::isStackable).intercept { falseFlow } +``` + +So `visible && stackable` is always `false`, and SystemUI falls back to drawing one signal icon per SIM. + +### Why this hook point + +- **The getter, not the field.** The backing field is `final` and is built once in the constructor. The view model reads it through the `MobileIconsInteractor.isStackable()` interface method, so hooking the getter catches every consumer, with no need to touch the constructor or rewrite final fields. +- **The flow is created in SystemUI's classloader.** The `Flow` type has to be SystemUI's own `kotlinx.coroutines` class. A flow built from the module's classes would be a different type and would fail when SystemUI collects it. +- **Two implementations are hooked.** SystemUI has a second, Kairos-based mobile icons pipeline behind a flag. Its `Flow`-facing entry point is `MobileIconsInteractorKairosAdapter.isStackable()`. Hooking both covers whichever pipeline is active. A class that doesn't exist on a given build is logged and skipped. + +## Build + +Requires `io.github.libxposed:api:102.0.0` in `mavenLocal()` (run `./gradlew publishToMavenLocal` in the [libxposed/api](https://github.com/libxposed/api) repo). + +```bash +./gradlew assembleDebug +adb install -r app/build/outputs/apk/debug/app-debug.apk +``` + +Vector discovers the module through `app/src/main/resources/META-INF/xposed/` (`java_init.list`, `module.prop`, `scope.list`). + +## Usage + +1. Enable **Unstack** in Vector. The scope is preset to System UI. +2. Restart SystemUI: `adb shell su -c 'pkill -f com.android.systemui'` +3. Check that the hooks attached: `adb logcat -s Unstack` diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d504b28..5972bbb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -4,20 +4,14 @@ plugins { android { namespace = "sh.sar.unstacksim" - compileSdk { - version = release(36) { - minorApiLevel = 1 - } - } + compileSdk = 34 defaultConfig { applicationId = "sh.sar.unstacksim" - minSdk = 36 - targetSdk = 36 + minSdk = 26 + targetSdk = 34 versionCode = 1 versionName = "1.0" - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -29,17 +23,19 @@ android { ) } } + compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } + + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } } dependencies { - implementation(libs.androidx.appcompat) - implementation(libs.androidx.core.ktx) - implementation(libs.material) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.espresso.core) - androidTestImplementation(libs.androidx.junit) + compileOnly(libs.libxposed.api) } \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..eb6d52b 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,21 +1,15 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html +# Keep all Xposed module classes and entry points +-keep class sh.sar.unstacksim.** { *; } -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} +# Keep reflection targets +-keepclasseswithmembernames class * { + native ; +} -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +# Keep hook callbacks +-keep interface io.github.libxposed.api.XposedModuleInterface$* { *; } -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +# Kotlin metadata +-keepattributes *Annotation* +-keepattributes SourceFile,LineNumberTable +-keepattributes InnerClasses diff --git a/app/src/androidTest/java/sh/sar/unstacksim/ExampleInstrumentedTest.kt b/app/src/androidTest/java/sh/sar/unstacksim/ExampleInstrumentedTest.kt deleted file mode 100644 index 4f1ea33..0000000 --- a/app/src/androidTest/java/sh/sar/unstacksim/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package sh.sar.unstacksim - -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("sh.sar.unstacksim", appContext.packageName) - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 332a3e3..dd1cf1b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,15 +1,11 @@ - + + android:supportsRtl="true" /> - \ No newline at end of file + diff --git a/app/src/main/kotlin/sh/sar/unstacksim/EntryPoint.kt b/app/src/main/kotlin/sh/sar/unstacksim/EntryPoint.kt new file mode 100644 index 0000000..05a4967 --- /dev/null +++ b/app/src/main/kotlin/sh/sar/unstacksim/EntryPoint.kt @@ -0,0 +1,19 @@ +package sh.sar.unstacksim + +import io.github.libxposed.api.XposedModule +import io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam +import android.util.Log + +class EntryPoint : XposedModule() { + companion object { + private const val TAG = "Unstack" + private const val SYSTEM_UI_PACKAGE = "com.android.systemui" + } + + override fun onPackageLoaded(param: PackageLoadedParam) { + if (param.packageName == SYSTEM_UI_PACKAGE) { + Log.d(TAG, "SystemUI package loaded, installing hooks") + HookManager.init(this, param.defaultClassLoader) + } + } +} diff --git a/app/src/main/kotlin/sh/sar/unstacksim/HookManager.kt b/app/src/main/kotlin/sh/sar/unstacksim/HookManager.kt new file mode 100644 index 0000000..791fdf2 --- /dev/null +++ b/app/src/main/kotlin/sh/sar/unstacksim/HookManager.kt @@ -0,0 +1,29 @@ +package sh.sar.unstacksim + +import android.util.Log +import io.github.libxposed.api.XposedModule + +object HookManager { + private const val TAG = "Unstack" + private const val PKG = "com.android.systemui.statusbar.pipeline.mobile.domain.interactor" + private val TARGETS = listOf( + "$PKG.MobileIconsInteractorImpl", + "$PKG.MobileIconsInteractorKairosAdapter", + ) + + fun init(module: XposedModule, classLoader: ClassLoader) { + val falseFlow = classLoader.loadClass("kotlinx.coroutines.flow.StateFlowKt") + .getDeclaredMethod("MutableStateFlow", Any::class.java) + .invoke(null, false)!! + + for (name in TARGETS) { + try { + val method = classLoader.loadClass(name).getDeclaredMethod("isStackable") + module.hook(method).intercept { falseFlow } + Log.i(TAG, "Hooked $name.isStackable") + } catch (e: ReflectiveOperationException) { + Log.w(TAG, "Skipping $name: $e") + } + } + } +} diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index f57e8c4..c8bb31f 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,16 +1,10 @@ - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 51dc4b7..0efb9d3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ + - unstacksim - \ No newline at end of file + Unstack + Disables stacked dual-SIM status bar icons + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index b9424f6..76de063 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,16 +1,10 @@ - - \ No newline at end of file diff --git a/app/src/main/resources/META-INF/xposed/java_init.list b/app/src/main/resources/META-INF/xposed/java_init.list new file mode 100644 index 0000000..dc423c7 --- /dev/null +++ b/app/src/main/resources/META-INF/xposed/java_init.list @@ -0,0 +1 @@ +sh.sar.unstacksim.EntryPoint diff --git a/app/src/main/resources/META-INF/xposed/module.prop b/app/src/main/resources/META-INF/xposed/module.prop new file mode 100644 index 0000000..3bccada --- /dev/null +++ b/app/src/main/resources/META-INF/xposed/module.prop @@ -0,0 +1,3 @@ +minApiVersion=102 +targetApiVersion=102 +staticScope=true diff --git a/app/src/main/resources/META-INF/xposed/scope.list b/app/src/main/resources/META-INF/xposed/scope.list new file mode 100644 index 0000000..fb7c8c8 --- /dev/null +++ b/app/src/main/resources/META-INF/xposed/scope.list @@ -0,0 +1 @@ +com.android.systemui diff --git a/app/src/test/java/sh/sar/unstacksim/ExampleUnitTest.kt b/app/src/test/java/sh/sar/unstacksim/ExampleUnitTest.kt deleted file mode 100644 index 1326889..0000000 --- a/app/src/test/java/sh/sar/unstacksim/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package sh.sar.unstacksim - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6a25d17..7e3f08c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,9 @@ [versions] agp = "9.2.1" -coreKtx = "1.19.1" -junit = "4.13.2" -junitVersion = "1.3.0" -espressoCore = "3.7.0" -appcompat = "1.6.1" -material = "1.10.0" +libxposed = "102.0.0" [libraries] -androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } -junit = { group = "junit", name = "junit", version.ref = "junit" } -androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } -androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } -androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } -material = { group = "com.google.android.material", name = "material", version.ref = "material" } +libxposed-api = { group = "io.github.libxposed", name = "api", version.ref = "libxposed" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/screenshots/sim1_data.jpg b/screenshots/sim1_data.jpg new file mode 100644 index 0000000..c3597ae Binary files /dev/null and b/screenshots/sim1_data.jpg differ diff --git a/screenshots/sim2_data.jpg b/screenshots/sim2_data.jpg new file mode 100644 index 0000000..db91164 Binary files /dev/null and b/screenshots/sim2_data.jpg differ diff --git a/screenshots/stock.jpg b/screenshots/stock.jpg new file mode 100644 index 0000000..ec3e581 Binary files /dev/null and b/screenshots/stock.jpg differ diff --git a/settings.gradle.kts b/settings.gradle.kts index 66b20b6..29c6c9b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,11 +14,13 @@ pluginManagement { plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" } + dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() + mavenLocal() } }