Created
January 16, 2016 15:02
-
-
Save arihantagarwal/d3f8724a815be0524f92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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