mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Update zip and magisk installation
This commit is contained in:
parent
3fbbb0865a
commit
c562cbc2bb
@ -10,6 +10,8 @@ import com.topjohnwu.magisk.utils.AdaptiveList;
|
|||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.magisk.utils.ZipUtils;
|
import com.topjohnwu.magisk.utils.ZipUtils;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -21,27 +23,19 @@ import java.util.List;
|
|||||||
public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
||||||
|
|
||||||
private Uri mUri;
|
private Uri mUri;
|
||||||
private File mCachedFile, mScriptFile, mCheckFile;
|
private File mCachedFile;
|
||||||
|
|
||||||
private String mFilename;
|
|
||||||
private AdaptiveList<String> mList;
|
private AdaptiveList<String> mList;
|
||||||
|
|
||||||
public FlashZip(Activity context, Uri uri, AdaptiveList<String> list) {
|
public FlashZip(Activity context, Uri uri, AdaptiveList<String> list) {
|
||||||
super(context);
|
super(context);
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
mList = list;
|
mList = list;
|
||||||
|
|
||||||
mCachedFile = new File(context.getCacheDir(), "install.zip");
|
mCachedFile = new File(context.getCacheDir(), "install.zip");
|
||||||
mScriptFile = new File(context.getCacheDir(), "/META-INF/com/google/android/update-binary");
|
|
||||||
mCheckFile = new File(mScriptFile.getParent(), "updater-script");
|
|
||||||
|
|
||||||
// Try to get the filename ourselves
|
|
||||||
mFilename = Utils.getNameFromUri(context, mUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean unzipAndCheck() throws Exception {
|
private boolean unzipAndCheck() throws Exception {
|
||||||
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android", false);
|
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android", true);
|
||||||
List<String> ret = Utils.readFile(getShell(), mCheckFile.getPath());
|
List<String> ret = Utils.readFile(getShell(), new File(mCachedFile.getParentFile(), "updater-script").getPath());
|
||||||
return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK");
|
return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +60,13 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
|||||||
mCachedFile.delete();
|
mCachedFile.delete();
|
||||||
try (
|
try (
|
||||||
InputStream in = mm.getContentResolver().openInputStream(mUri);
|
InputStream in = mm.getContentResolver().openInputStream(mUri);
|
||||||
OutputStream out = new FileOutputStream(mCachedFile)
|
OutputStream out = new BufferedOutputStream(new FileOutputStream(mCachedFile))
|
||||||
) {
|
) {
|
||||||
if (in == null) throw new FileNotFoundException();
|
if (in == null) throw new FileNotFoundException();
|
||||||
byte buffer[] = new byte[1024];
|
InputStream buf= new BufferedInputStream(in);
|
||||||
|
byte buffer[] = new byte[4096];
|
||||||
int length;
|
int length;
|
||||||
while ((length = in.read(buffer)) > 0)
|
while ((length = buf.read(buffer)) > 0)
|
||||||
out.write(buffer, 0, length);
|
out.write(buffer, 0, length);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
mList.add("! Invalid Uri");
|
mList.add("! Invalid Uri");
|
||||||
@ -81,9 +76,10 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
if (!unzipAndCheck()) return 0;
|
if (!unzipAndCheck()) return 0;
|
||||||
mList.add("- Installing " + mFilename);
|
mList.add("- Installing " + Utils.getNameFromUri(mm, mUri));
|
||||||
getShell().su(mList,
|
getShell().su(mList,
|
||||||
"BOOTMODE=true sh " + mScriptFile + " dummy 1 " + mCachedFile +
|
"cd " + mCachedFile.getParent(),
|
||||||
|
"BOOTMODE=true sh update-binary dummy 1 " + mCachedFile +
|
||||||
" && echo 'Success!' || echo 'Failed!'"
|
" && echo 'Success!' || echo 'Failed!'"
|
||||||
);
|
);
|
||||||
if (TextUtils.equals(mList.get(mList.size() - 1), "Success!"))
|
if (TextUtils.equals(mList.get(mList.size() - 1), "Success!"))
|
||||||
|
@ -131,7 +131,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
source = tar;
|
source = tar;
|
||||||
} else {
|
} else {
|
||||||
// Direct copy raw image
|
// Direct copy raw image
|
||||||
source = in;
|
source = new BufferedInputStream(in);
|
||||||
}
|
}
|
||||||
byte buffer[] = new byte[1024];
|
byte buffer[] = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
@ -204,8 +204,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
break;
|
break;
|
||||||
case DIRECT_MODE:
|
case DIRECT_MODE:
|
||||||
// Direct flash boot image
|
// Direct flash boot image
|
||||||
getShell().su_raw("cat " + patched_boot + " /dev/zero | dd of=" + mBootLocation + " bs=4096");
|
getShell().su(mList, "flash_boot_image " + patched_boot + " " + mBootLocation);
|
||||||
mList.add("Flashing patched boot to " + mBootLocation);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -25,7 +25,7 @@ public class RestoreStockBoot extends ParallelTask<Void, Void, Boolean> {
|
|||||||
String stock_boot = "/data/stock_boot_" + ret.get(0).substring(ret.get(0).indexOf('=') + 1) + ".img.gz";
|
String stock_boot = "/data/stock_boot_" + ret.get(0).substring(ret.get(0).indexOf('=') + 1) + ".img.gz";
|
||||||
if (!Utils.itemExist(getShell(), stock_boot))
|
if (!Utils.itemExist(getShell(), stock_boot))
|
||||||
return false;
|
return false;
|
||||||
getShell().su_raw("gzip -d < " + stock_boot + " | cat - /dev/zero | dd of=" + mBoot + " bs=4096");
|
getShell().su_raw("flash_boot_image " + stock_boot + " " + mBoot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user