public static String getSecondSdcardPath(boolean hasSplit) { CommandResult ret = RootUtils.runCommand("mount", false, null); String[] lines = ret.result.split("\n"); String systemSdcard = Environment.getExternalStorageDirectory().getAbsolutePath(); String extSdcard = ""; for (String s : lines) { if (s.contains("secure") || s.contains("asec")) { continue; } if (s.contains("fat") || s.contains("fuse")) { String columns[] = s.split(" "); if (columns != null && columns.length > 3) { if (columns[3].contains("rw,")) { extSdcard += columns[1] + "\n"; } } } } extSdcard = extSdcard.replace(systemSdcard, "").trim(); if (!extSdcard.endsWith("/") && hasSplit) { extSdcard += "/"; } return extSdcard; }
public static boolean installSystemApp(String path, boolean isPrivate) { String fn = path.substring(0, path.length() - 3) + "*"; String onlyApkName = path.substring(path.lastIndexOf("/") + 1); CommandResult result = RootUtils.runCommand( String.format("busybox cp -r %s /system/%s/", fn, isPrivate ? "priv-app" : "app"), true, null); if (result.error.equals("")) { result = RootUtils.runCommand( String.format("chmod 644 /system/%s/%s", isPrivate ? "priv-app" : "app", onlyApkName), true, null); } return result.error.equals(""); }
public static String forceInstallAppWithResult(String filePath) { // change to package name ApplicationInfo appInfo = getAppInfoFromPackage(filePath); String fileName = appInfo.packageName + "-1.apk"; // force install CommandResult result = RootUtils.runCommand(String.format("busybox cp %s /data/app/%s", filePath, fileName), true); if (result.error.equals("")) { result = RootUtils.runCommand(String.format("chmod 644 /data/app/%s", fileName), true); } if (result.error.equals("")) { result = RootUtils.runCommand(String.format("chown system:system /data/app/%s", fileName), true); } return result.error; }
public static boolean uninstallApk(String packageName) { try { CommandResult cmdRet = RootUtils.runCommand(String.format("pm uninstall %s", packageName), true, null); return cmdRet.error.equals(""); } catch (Exception e) { return false; } }
public static boolean saveHosts(List<HostRecordInfo> list) { // save hosts String hosts = ""; addLocalHostToPos0(list); for (HostRecordInfo info : list) { hosts += String.format("%s\t%s\n", info.ip, info.domain); } try { String fn = DirHelper.HOSTS_DIR + "hosts"; FileUtils.rewriteFile(fn, hosts); String cmd = String.format("busybox cp %s /system/etc/", fn); CommandResult result = RootUtils.runCommand(cmd, true); if (result.error.equals("")) { result = RootUtils.runCommand("chmod 644 /system/etc/hosts", true); } return result.error.equals(""); } catch (Exception e) { return false; } }
public static String getDataSize(String path) { String ret = ""; CommandResult result = RootUtils.runCommand("busybox du -s " + path, true, null); if (result.error.equals("")) { ret = result.result; try { ret = ret.substring(0, ret.indexOf('\t')); } catch (Exception e) { ret = "unknown"; } } return ret; }
public static void setInstallLocation(int location) { RootUtils.runCommand("pm set-install-location " + String.valueOf(location), true, null); }
public static String installAppWithResult(String filePath) { CommandResult result = RootUtils.runCommand("pm install -r " + filePath, true); return result.error; }
public static boolean installApp(String filePath) { CommandResult result = RootUtils.runCommand("pm install -r " + filePath, true); return result.result.toLowerCase().contains("success"); }
public static boolean deleteSystemAppData(String ns) { CommandResult result = RootUtils.runCommand("rm -r " + ns, true, null); return result.error.equals(""); }
public static boolean deleteSystemApp(String path) { String fn = path.substring(0, path.length() - 3) + "*"; CommandResult result = RootUtils.runCommand("rm " + fn, true, null); return result.error.equals(""); }
public static boolean backupSystemApp(String path) { String fn = path.substring(0, path.length() - 3) + "*"; CommandResult result = RootUtils.runCommand("busybox cp " + fn + " " + DirHelper.SYSAPP_DIR, true, null); return result.error.equals(""); }