Skip to content

Instantly share code, notes, and snippets.

@atastycookie
Created April 21, 2016 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atastycookie/6052cdc9d12dde065979226d44123e45 to your computer and use it in GitHub Desktop.
Save atastycookie/6052cdc9d12dde065979226d44123e45 to your computer and use it in GitHub Desktop.
static public boolean runCommandWait(String cmd, boolean needsu) {
try {
String su = "sh";
if (needsu) { su = "su"; }
Process process = Runtime.getRuntime().exec(new String[]{su, "-c", cmd});
int result = process.waitFor();
return (result == 0);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
static public void makeAppSystem(String appName) {
String systemPrivAppDir = "/system/priv-app/";
String systemAppDir = "/system/app/";
String appPath = "/data/app/" + appName;
if (!runCommandWait("mount -o remount,rw /system", true)) {
Log.e(TAG, "makeAppSystem: Can't mount /system");
return;
}
int api = Build.VERSION.SDK_INT;
String appDir = systemPrivAppDir;
if (api >= 21) {
runCommandWait("cp -R " + appPath + "* " + appDir, true);
runCommandWait("chown -R 0:0 " + appDir + appName + "*", true);
runCommandWait("rm -Rf " + appPath + "*", true);
} else {
if (api < 20) { appDir = systemAppDir; }
runCommandWait("cp " + appPath + "* " + appDir, true);
runCommandWait("chown 0:0 " + appDir + appName + "*", true);
runCommandWait("rm -f " + appPath + "*", true);
}
Shell.runCommand("am restart", true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment