Skip to content

Commit 051ecec

Browse files
committed
feat: auto restart system bridge on debug builds
1 parent 82316a8 commit 051ecec

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

base/src/main/java/io/github/sds100/keymapper/base/promode/SystemBridgeAutoStarter.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ class SystemBridgeAutoStarter @Inject constructor(
154154

155155
if (isBoot) {
156156
handleAutoStartOnBoot()
157-
} else if (BuildConfig.DEBUG) {
158-
Timber.i("Auto starting system bridge because debug build")
159-
autoStartTypeFlow.first()?.let { autoStart(it) }
157+
} else if (BuildConfig.DEBUG && connectionManager.isConnected()) {
158+
// This is useful when developing and need to restart the system bridge
159+
// after making changes to it.
160+
Timber.w("Restarting system bridge on debug build.")
161+
162+
connectionManager.restartSystemBridge()
160163
} else {
161164
handleAutoStartFromPreVersion4()
162165
}

sysbridge/src/main/java/io/github/sds100/keymapper/sysbridge/manager/SystemBridgeConnectionManager.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ class SystemBridgeConnectionManagerImpl @Inject constructor(
136136
}
137137
}
138138

139+
override fun restartSystemBridge() {
140+
coroutineScope.launch {
141+
systemBridgeFlow.value?.let { restartSystemBridge(it) }
142+
}
143+
}
144+
139145
@SuppressLint("LogNotTimber")
140146
private suspend fun restartSystemBridge(systemBridge: ISystemBridge) {
141147
starter.startSystemBridge(executeCommand = { command ->
@@ -256,6 +262,7 @@ interface SystemBridgeConnectionManager {
256262

257263
fun <T> run(block: (ISystemBridge) -> T): KMResult<T>
258264
fun stopSystemBridge()
265+
fun restartSystemBridge()
259266

260267
fun startWithRoot()
261268
fun startWithShizuku()

sysbridge/src/main/java/io/github/sds100/keymapper/sysbridge/starter/SystemBridgeStarter.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ class SystemBridgeStarter @Inject constructor(
5353
) {
5454
private val userManager by lazy { ctx.getSystemService(UserManager::class.java)!! }
5555

56-
private val baseApkPath = ctx.applicationInfo.sourceDir
57-
private val splitApkPaths: Array<String> = ctx.applicationInfo.splitSourceDirs ?: emptyArray()
58-
private val libPath = ctx.applicationInfo.nativeLibraryDir
59-
private val packageName = ctx.applicationInfo.packageName
56+
// Important! Use getters because the values can change at runtime just after the app process
57+
// starts
58+
private val baseApkPath: String
59+
get() = ctx.applicationInfo.sourceDir
60+
private val splitApkPaths: Array<String>
61+
get() = ctx.applicationInfo.splitSourceDirs ?: emptyArray()
62+
private val libPath: String?
63+
get() = ctx.applicationInfo.nativeLibraryDir
64+
private val packageName: String
65+
get() = ctx.applicationInfo.packageName
66+
6067
private val startMutex: Mutex = Mutex()
6168

6269
private val shizukuStarterConnection: ServiceConnection = object : ServiceConnection {

0 commit comments

Comments
 (0)