【发布时间】:2014-08-30 09:36:02
【问题描述】:
我制作了一个应用程序来使用 roottools 备份和恢复应用程序和数据。
我将文件夹 data/data/com.example.anotherapp 备份到 sdcard。现在,我卸载/重新安装并将文件夹 com.example.anotherapp 复制到 data/data/ 但应用程序无法运行。
如何 chmod 文件夹 com.example.anotherapp?
public static boolean restoreDatabase(Context context, AppManagerItem item) {
String from = "/data/data/";
File fileOut = new File(Environment.getExternalStorageDirectory(),
context.getString(R.string.app_name));
String to = fileOut.getAbsolutePath() + File.separator
+ item.getPackageName();
to = normalizeParameter(to);
boolean isSuccess = false;
String comando = "cp -r " + to + " " + from;
Process suProcess;
try {
suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
suProcess.getOutputStream());
os.writeBytes(comando + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
try {
int suProcessRetval = suProcess.waitFor();
if (255 != suProcessRetval) {
// Acceso Root concedido
isSuccess = true;
} else {
// Acceso Root denegado
isSuccess = false;
}
} catch (Exception ex) {
Log.w("Error ejecutando el comando Root", ex);
}
String chmod = "chmod -R 757 " + from + item.getPackageName();
Runtime.getRuntime().exec(chmod);
} catch (IOException e) {
e.printStackTrace();
}
return isSuccess;
}
谢谢。
【问题讨论】:
标签: android backup directory restore chmod