Skip to content

Instantly share code, notes, and snippets.

@kairos34
Last active April 22, 2022 09:05
Show Gist options
  • Save kairos34/f95fdec422d544154cffb434d7ab3564 to your computer and use it in GitHub Desktop.
Save kairos34/f95fdec422d544154cffb434d7ab3564 to your computer and use it in GitHub Desktop.
Show/Hide System UI
val hardwareId
get() = "getprop ro.hardware".runAsCommand().trim()
fun setSystemUIVisibility(show: Boolean) {
GlobalScope.launch {
if (show) {
if(hardwareId.equals("qcom")) { // ZPAD Plus 4G (7.1.1)
"am broadcast -a com.android.zkteco.SHOW_NAVIGATION".runAsCommand()
"am broadcast -a com.android.zkteco.SHOW_STATUS".runAsCommand()
} else { // ZPAD Plus (6.0.1)
"am broadcast -a update.statusbar --ei status 1 -f 0x10000000".runAsCommand()
}
} else {
if(hardwareId.equals("qcom")) { // ZPAD Plus 4G (7.1.1)
"am broadcast -a com.android.zkteco.HIDE_NAVIGATION".runAsCommand()
"am broadcast -a com.android.zkteco.HIDE_STATUS".runAsCommand()
} else { // ZPAD Plus (6.0.1)
"am broadcast -a update.statusbar --ei status 0 -f 0x10000000".runAsCommand()
"am broadcast -a show.statusbar --ei status 0 -f 0x10000000".runAsCommand()
}
}
}
}
fun String.runAsCommand() = run {
ShellHelper.execCommandAndRetrieveStringResult(this).joinToString(separator = "\n")
}
@Throws(IOException::class)
fun execCommandAndRetrieveStringResult(command: String): List<String> {
val result = ArrayList<String>()
val runTime = Runtime.getRuntime()
val process = runTime.exec("su")
val outputStream = DataOutputStream(
process.outputStream
)
try {
outputStream.writeBytes(
"""
$command
""".trimIndent()
)
outputStream.flush()
process.outputStream
outputStream.writeBytes("exit\n")
outputStream.flush()
process.waitFor()
var line: String
// getInputStream gives an Input stream connected to
// the process standard output. Just use it to make
// a BufferedReader to readLine() what the program writes out.
val inputStream = BufferedReader(InputStreamReader(process.inputStream))
while (inputStream.readLine().also { line = it } != null && line.isNotEmpty()) {
result.add(line)
}
} catch (e: InterruptedException) {
Log.e("ExecCommand", "Error executing command", e)
} finally {
outputStream.close()
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment