title: Is it possible to disable Doze mode via adb command executed from Android app?
body: <p>I have a requirement to disable the doze mode completely on my phone from my android app.
  I was able to find that the following command can disable Doze mode in Andriod.</p>
  <p><code>adb -d shell dumpsys deviceidle disable</code></p>
  <p>I made a small sample to run the above command from my Android application. I am getting an exception - permission denied.</p>
  <pre><code>package com.example.myapplication
  
  import android.os.Bundle
  import android.util.Log
  import androidx.appcompat.app.AppCompatActivity
  import kotlinx.android.synthetic.main.activity_main.*
  import java.io.BufferedReader
  import java.io.InputStreamReader
  
  class MainActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          btn_test_shell.setOnClickListener()
          {
              val adbShellCommand =   &quot;dumpsys deviceidle disable&quot; //&quot;pwd&quot; //
  
              val pb = ProcessBuilder(adbShellCommand)
              val p: Process
  
              try {
                  p = pb.start()
                  val reader = BufferedReader(InputStreamReader(p.inputStream))
                  //Set the output to a TextView
                  txt_shell_output.text = reader.read().toString()
  
                  p.waitFor()
                  p.destroy()
              } catch (e: Exception) {
                  e.printStackTrace()
                  Log.e(&quot;Execute Shell&quot;,  e.printStackTrace().toString())
              }
          }
      }
  
  }
  </code></pre>
  <p>When I run the same code using Runtime.getRuntime().exec(adbShellCommand), I get an output of 80 in the TextView, not sure what it means. In this case, there is no exception though.</p>
  <p>Few questions:</p>
  <ol>
  <li><p>Are we allowed to run the above command, from within an Android app?</p>
  </li>
  <li><p>Does whitelisting your app via the following command, result in the same effect as setting the 'Ignore Battery Optimizations' in Android?
  <code>adb -d shell dumpsys deviceidle whitelist + &lt;pkg-name&gt;</code></p>
  </li>
  </ol>