Skip to content

Commit f571b45

Browse files
author
nawaf
committed
fix: resolve multiple issues and crashes on recent Android versions
- Fix AbstractMethodError in IServiceConnection (JingMatrix#741) - Fix SystemUI crash on Android 15 via MediaRouter2Hooker (JingMatrix#755) - Fix Zygisk Next crash on Android 16 by forcing DB init (JingMatrix#731) - Bypass GrapheneOS DCL protection for manager and settings (JingMatrix#711) - Fix manager crash on EMUI/HarmonyOS due to pre-warmed shell process (JingMatrix#748) - Update PluginEntry.kt to fully support API 101 and 102
1 parent dc6675f commit f571b45

14 files changed

Lines changed: 180 additions & 22 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ val versionNameProvider by extra(providers.of(GitLatestTagValueSource::class.jav
6464
val injectedPackageName by extra("com.android.shell")
6565
val injectedPackageUid by extra(2000)
6666
val defaultManagerPackageName by extra("org.lsposed.manager")
67+
val grapheneSettingsPackageName by extra("com.android.settings")
6768

6869
val androidTargetSdkVersion by extra(36)
6970
val androidMinSdkVersion by extra(27)

daemon/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io.PrintStream
44
import java.util.UUID
55

66
val defaultManagerPackageName: String by rootProject.extra
7+
val grapheneSettingsPackageName: String by rootProject.extra
78
val injectedPackageName: String by rootProject.extra
89
val injectedPackageUid: Int by rootProject.extra
910
val versionCodeProvider: Provider<String> by rootProject.extra
@@ -22,6 +23,11 @@ android {
2223
"DEFAULT_MANAGER_PACKAGE_NAME",
2324
""""$defaultManagerPackageName"""",
2425
)
26+
buildConfigField(
27+
"String",
28+
"GRAPHENE_SETTINGS_PACKAGE_NAME",
29+
""""$grapheneSettingsPackageName"""",
30+
)
2531
buildConfigField("String", "FRAMEWORK_NAME", """"${rootProject.name}"""")
2632
buildConfigField("String", "MANAGER_INJECTED_PKG_NAME", """"$injectedPackageName"""")
2733
buildConfigField("int", "MANAGER_INJECTED_UID", """$injectedPackageUid""")

daemon/src/main/kotlin/org/matrix/vector/daemon/VectorDaemon.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ object VectorDaemon {
9797

9898
applyNotificationWorkaround()
9999

100+
// Force open the database as root (EUID 0) so the connection is cached
101+
// before dropping privileges. This prevents SQLiteCantOpenDatabaseException
102+
// when accessing the DB as system (EUID 1000) on restricted environments.
103+
runCatching { ConfigCache.dbHelper.writableDatabase }
104+
100105
// Setup IPC channel for applications by injecting DaemonService binder
101106
sendToBridge(VectorService.asBinder(), false, systemServerMaxRetry)
102107

daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object VectorService : IDaemonService.Stub() {
6767
if (ApplicationService.hasRegister(uid, pid)) return null
6868

6969
val scope = ProcessScope(processName, uid)
70-
if (!ManagerService.tryRegisterManagerProcess(pid, uid, processName) &&
70+
if (processName != BuildConfig.GRAPHENE_SETTINGS_PACKAGE_NAME && !ManagerService.tryRegisterManagerProcess(pid, uid, processName) &&
7171
ConfigCache.shouldSkipProcess(scope)) {
7272
Log.d(TAG, "Skipped $processName/$uid")
7373
return null

daemon/src/main/kotlin/org/matrix/vector/daemon/data/FileSystem.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ object FileSystem {
5858

5959
init {
6060
runCatching {
61-
Files.createDirectories(basePath)
62-
Os.chmod(basePath.toString(), "700".toInt(8))
63-
SELinux.setFileContext(basePath.toString(), "u:object_r:system_file:s0")
64-
Files.createDirectories(configDirPath)
65-
}
66-
.onFailure { Log.e(TAG, "Failed to initialize directories", it) }
61+
Files.createDirectories(basePath)
62+
Os.chmod(basePath.toString(), "700".toInt(8))
63+
}.onFailure { Log.e(TAG, "Failed to initialize basePath", it) }
64+
65+
runCatching {
66+
SELinux.setFileContext(basePath.toString(), "u:object_r:system_file:s0")
67+
}.onFailure { Log.e(TAG, "Failed to set SELinux context for basePath", it) }
68+
69+
runCatching {
70+
Files.createDirectories(configDirPath)
71+
}.onFailure { Log.e(TAG, "Failed to initialize configDirPath", it) }
6772
}
6873

6974
fun setupCli(): String {

daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ object ManagerService : ILSPManagerService.Stub() {
5555
private val connection =
5656
object : android.app.IServiceConnection.Stub() {
5757
override fun connected(name: ComponentName?, service: IBinder?, dead: Boolean) {}
58+
59+
override fun connected(
60+
name: ComponentName?,
61+
service: IBinder?,
62+
session: android.app.IBinderSession?,
63+
dead: Boolean
64+
) {}
5865
}
5966

6067
init {

daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/SystemServerService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ object SystemServerService : ILSPSystemServerService.Stub(), IBinder.DeathRecipi
4545
proxyServiceName = serviceName
4646
}
4747
.onFailure { Log.e(TAG, "Failed to register IServiceCallback", it) }
48+
} else {
49+
runCatching {
50+
ServiceManager.addService(serviceName, this)
51+
proxyServiceName = serviceName
52+
}.onFailure { Log.e(TAG, "Failed to register proxy service", it) }
4853
}
4954
}
5055

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package android.app;
2+
3+
import android.os.IInterface;
4+
5+
public interface IBinderSession extends IInterface {
6+
}

hiddenapi/stubs/src/main/java/android/app/IServiceConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
public interface IServiceConnection extends IInterface {
99
void connected(ComponentName name, IBinder service, boolean dead);
1010

11+
void connected(ComponentName name, IBinder service, IBinderSession session, boolean dead);
12+
1113
abstract class Stub extends Binder implements IServiceConnection {
1214

1315
public static IServiceConnection asInterface(IBinder obj) {

xposed/src/main/kotlin/org/matrix/vector/impl/core/VectorStartup.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ object VectorStartup {
5858
VectorHookBuilder(it).intercept(LoadedApkCtorHooker)
5959
}
6060

61+
// Workaround for Android 15 SystemUI MediaRouter2 crash (Issue #755)
62+
if (Build.VERSION.SDK_INT >= 35) {
63+
try {
64+
val mediaRouterClass = Class.forName("android.media.MediaRouter2")
65+
mediaRouterClass.declaredMethods
66+
.filter { it.name == "loadSystemRoutes" }
67+
.forEach { VectorHookBuilder(it).intercept(MediaRouter2Hooker) }
68+
} catch (ignored: Throwable) {}
69+
}
70+
6171
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
6272
loadedApkClass.declaredMethods
6373
.filter { it.name == "createAppFactory" }

0 commit comments

Comments
 (0)