Skip to content

Commit ca68a68

Browse files
committed
fix: refresh the system bridge starter script when the app launches in case the paths changed
1 parent 4e63c1c commit ca68a68

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SystemBridgeConnectionManagerImpl @Inject constructor(
6767
time = SystemClock.elapsedRealtime(),
6868
// Get whether the user previously stopped the system bridge.
6969
isStoppedByUser =
70-
preferences.get(Keys.isSystemBridgeStoppedByUser).firstBlocking() ?: false,
70+
preferences.get(Keys.isSystemBridgeStoppedByUser).firstBlocking() ?: false,
7171
),
7272
)
7373
private var isExpectedDeath: Boolean = false
@@ -93,6 +93,18 @@ class SystemBridgeConnectionManagerImpl @Inject constructor(
9393
}
9494
}
9595

96+
init {
97+
// Refresh the starter script because the paths to the apk and libs may
98+
// have changed.
99+
coroutineScope.launch {
100+
try {
101+
starter.refreshStarterScript()
102+
} catch (e: Exception) {
103+
Timber.e("Failed to refresh system bridge starter script", e)
104+
}
105+
}
106+
}
107+
96108
fun pingBinder(): Boolean {
97109
synchronized(systemBridgeLock) {
98110
return systemBridgeFlow.value?.asBinder()?.pingBinder() == true

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,19 @@ class SystemBridgeStarter @Inject constructor(
170170
}
171171
}
172172

173+
suspend fun refreshStarterScript() {
174+
writeStarterScript()
175+
}
176+
173177
/**
174178
* Get the shell command that can be used to start the system bridge manually.
175179
* This command should be executed with 'adb shell'.
176180
*/
177181
suspend fun getStartCommand(): KMResult<String> {
182+
return writeStarterScript().then { starterPath -> Success("sh $starterPath") }
183+
}
184+
185+
private suspend fun writeStarterScript(): KMResult<String> {
178186
val directory = if (buildConfigProvider.sdkInt > Build.VERSION_CODES.R) {
179187
try {
180188
ctx.getExternalFilesDir(null)?.parentFile
@@ -196,7 +204,7 @@ class SystemBridgeStarter @Inject constructor(
196204
protectedStorageDir
197205
}
198206

199-
return copyStarterFiles(directory!!).then { starterPath -> Success("sh $starterPath") }
207+
return copyStarterFiles(directory!!)
200208
}
201209

202210
/**

0 commit comments

Comments
 (0)