Fix potential bug

This commit is contained in:
topjohnwu 2017-11-03 02:25:42 +08:00
parent 5f22d3e055
commit a34ed538b6

View File

@ -117,6 +117,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
File boot = new File(install, "boot.img"); File boot = new File(install, "boot.img");
switch (mode) { switch (mode) {
case PATCH_MODE: case PATCH_MODE:
mList.add("- Use boot image: " + boot);
// Copy boot image to local // Copy boot image to local
try ( try (
InputStream in = mm.getContentResolver().openInputStream(mBootImg); InputStream in = mm.getContentResolver().openInputStream(mBootImg);
@ -146,19 +147,15 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
mList.add("! Copy failed"); mList.add("! Copy failed");
throw e; throw e;
} }
mList.add("- Use boot image: " + boot);
break; break;
case DIRECT_MODE: case DIRECT_MODE:
try (OutputStream out = new FileOutputStream(boot)) {
Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "cat " + mBootLocation });
Utils.inToOut(process.getInputStream(), out);
process.waitFor();
process.destroy();
} catch (Exception e) {
mList.add("! Dump boot image failed");
throw e;
}
mList.add("- Use boot image: " + mBootLocation); mList.add("- Use boot image: " + mBootLocation);
if (boot.createNewFile()) {
Shell.su("cat " + mBootLocation + " > " + boot);
} else {
mList.add("! Dump boot image failed");
return false;
}
break; break;
default: default:
return false; return false;