Getting error "uid 1000 not allowed to su" on RunTime.exec(“su”)
<p>When I try to run a su command from my program, which has system rights, I got this error returned on stderr:</p>

<blockquote>
  <p>uid 1000 not allowed to su</p>
</blockquote>

<p>I'm setting shared uid to android.uid.system or android.uid.shell but it does not change a thing. The device is supposedely rooted. I really don't understand what happens.</p>

<p>Here is the code:</p>

<pre><code>private boolean runAsRoot(String cmd, File workdir) throws IOException {
    Log.i(LOG_TAG, "Execute command as root: " + cmd);
    Process p = Runtime.getRuntime().exec(new String[] {"su", "-c", cmd});
    if (p == null) {
        Log.e(LOG_TAG, "cannot create process for " + cmd);
        return false;
    }

    int exit = -1;
    try {
        exit = p.waitFor();

        InputStreamReader isr;
        if (exit == 0) {
            isr = new InputStreamReader(p.getInputStream());
        } else {
            isr = new InputStreamReader(p.getErrorStream());
        }

        BufferedReader br = new BufferedReader(isr);
        StringBuilder sb = new StringBuilder();

        String line;
        while ((line = br.readLine()) != null) {
            if (sb.length() &gt; 0) {
                sb.append('\n');
            }
            sb.append(line);
        }

        String string = sb.toString();

        Log.l(LOG_TAG, exit == 0 ? Level.INFO : Level.SEVERE, string);

    } catch (InterruptedException e) {
        Log.e(LOG_TAG, e);
    }

    return exit == 0;
}
</code></pre>
