Created
April 21, 2016 08:24
-
-
Save atastycookie/6052cdc9d12dde065979226d44123e45 to your computer and use it in GitHub Desktop.
This file contains 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
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