Root.kt raw

   1  @file:Suppress("HardCodedStringLiteral")
   2  
   3  package io.github.domi04151309.alwayson.helpers
   4  
   5  import android.util.Log
   6  import java.io.DataOutputStream
   7  import java.io.IOException
   8  
   9  internal object Root {
  10      fun request(): Boolean {
  11          val process: Process
  12          return try {
  13              process = Runtime.getRuntime().exec("su")
  14              val output = DataOutputStream(process.outputStream)
  15              output.writeBytes("echo access granted\n")
  16              output.writeBytes("exit\n")
  17              output.flush()
  18              true
  19          } catch (exception: IOException) {
  20              Log.w(Global.LOG_TAG, exception.toString())
  21              false
  22          }
  23      }
  24  
  25      fun shell(command: String) {
  26          try {
  27              val process = Runtime.getRuntime().exec(arrayOf("su", "-c", command))
  28              process.waitFor()
  29          } catch (exception: IOException) {
  30              Log.w("Superuser", exception.toString())
  31          }
  32      }
  33  }
  34