Skip to content

Commit

Permalink
log the result of some important shell commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian04 committed Jun 30, 2024
1 parent af174a6 commit b7d3c5f
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CharacterDeviceManager private constructor(private val application: Applic

withContext(dispatcher) {
val commandResult = Shell.cmd(appResources.openRawResource(R.raw.create_char_devices)).exec()
Timber.d("create device script: \nstdout=%s\nstderr=%s", commandResult.out, commandResult.err)
logShellCommandResult("create devices script", commandResult)

fixSelinuxPermissions()

Expand Down Expand Up @@ -96,7 +96,8 @@ class CharacterDeviceManager private constructor(private val application: Applic
fun deleteCharacterDevices() {
val appResources: Resources = application.resources

Shell.cmd(appResources.openRawResource(R.raw.delete_char_devices)).exec()
val commandResult = Shell.cmd(appResources.openRawResource(R.raw.delete_char_devices)).exec()
logShellCommandResult("delete gadget script", commandResult)

return
}
Expand Down Expand Up @@ -147,6 +148,12 @@ class CharacterDeviceManager private constructor(private val application: Applic
}
}

private fun logShellCommandResult(label: String, commandResult: Shell.Result) {
with(commandResult) {
Timber.i("${label}: \nexit code=%d\nstdout=%s\nstderr=%s", code, out, err)
}
}

// This annotation is to help me ensure that I don't accidentally bypass my ViewModel wrappers when calling certain
// methods from inside ViewModel. For example, by calling CharacterDeviceManager.anyCharacterDeviceMissing directly without
// updating the state at the call site.
Expand Down

0 comments on commit b7d3c5f

Please sign in to comment.