Skip to content

Instantly share code, notes, and snippets.

@arihantagarwal
Created January 16, 2016 15:02
Show Gist options
  • Save arihantagarwal/d3f8724a815be0524f92 to your computer and use it in GitHub Desktop.
Save arihantagarwal/d3f8724a815be0524f92 to your computer and use it in GitHub Desktop.
String pname = getPackageName();
String[] CMDLINE_GRANTPERMS = { "su", "-c", null };
if (getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, pname) != 0) {
if (android.os.Build.VERSION.SDK_INT >= 16) {
try {
CMDLINE_GRANTPERMS[2] = String.format("pm grant %s android.permission.READ_LOGS", pname);
java.lang.Process p = Runtime.getRuntime().exec(CMDLINE_GRANTPERMS);
int res = p.waitFor();
Log.d(TAG, res);
if (res != 0)
throw new Exception("root didn't work");
} catch (Exception e) {
Log.d(TAG, "exception from exec:" e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment