diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java index 64a471a5f..e5f2b5578 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java @@ -105,36 +105,38 @@ public class ReposAdapter extends RecyclerView.Adapter new DownloadReceiver() { @Override public void task(Uri uri) { - // Process and sign the zip - try { - ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); - ByteArrayInputStream inBuffer; - - // First remove top folder (the folder with the repo name) in Github source zip - ZipUtils.removeTopFolder(mContext.getContentResolver().openInputStream(uri), outBuffer); - inBuffer = new ByteArrayInputStream(outBuffer.toByteArray()); - outBuffer.reset(); - - // Then sign the zip for the first time - ZipUtils.signZip(mContext, inBuffer, outBuffer, false); - - // Call zipadjust through JNI - inBuffer = new ByteArrayInputStream(ZipUtils.zipAdjust(outBuffer.toByteArray(), outBuffer.size())); - outBuffer.reset(); - - // Finally, sign the whole zip file again - ZipUtils.signZip(mContext, inBuffer, outBuffer, true); - - // Write it back to the downloaded zip - OutputStream out = mContext.getContentResolver().openOutputStream(uri); - outBuffer.writeTo(out); - out.close(); - } catch (IOException e) { - return; - } - // Flash the zip - new Async.FlashZIP(mContext, uri, mFilename).exec(); + new Async.FlashZIP(mContext, uri, mFilename){ + @Override + protected void preProcessing() throws Throwable { + // Process and sign the zip + publishProgress(mContext.getString(R.string.zip_install_process_zip_msg)); + try { + ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); + ByteArrayInputStream inBuffer; + + // First remove top folder (the folder with the repo name) in Github source zip + ZipUtils.removeTopFolder(mContext.getContentResolver().openInputStream(mUri), outBuffer); + inBuffer = new ByteArrayInputStream(outBuffer.toByteArray()); + outBuffer.reset(); + + // Then sign the zip for the first time + ZipUtils.signZip(mContext, inBuffer, outBuffer, false); + + // Call zipadjust through JNI + inBuffer = new ByteArrayInputStream(ZipUtils.zipAdjust(outBuffer.toByteArray(), outBuffer.size())); + outBuffer.reset(); + + // Finally, sign the whole zip file again + ZipUtils.signZip(mContext, inBuffer, outBuffer, true); + + // Write it back to the downloaded zip + OutputStream out = mContext.getContentResolver().openOutputStream(mUri); + outBuffer.writeTo(out); + out.close(); + } catch (IOException ignored) {} + } + }.exec(); } }, repo.getZipUrl(), diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index e6777c47f..a7c4a7215 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -167,25 +167,25 @@ public class Async { } } - public static class FlashZIP extends RootTask { + public static class FlashZIP extends RootTask { protected Uri mUri; - protected File mCachedFile, sdFile; + protected File mCachedFile; private String mFilename; - private ProgressDialog progress; + protected ProgressDialog progress; private Context mContext; - private boolean copyToSD; public FlashZIP(Context context, Uri uri, String filename) { mContext = context; mUri = uri; mFilename = filename; - copyToSD = true; + progress = new ProgressDialog(mContext); } public FlashZIP(Context context, Uri uri) { mContext = context; mUri = uri; + progress = new ProgressDialog(mContext); Cursor c = mContext.getContentResolver().query(uri, null, null, null, null); if (c != null) { int nameIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME); @@ -199,7 +199,6 @@ public class Async { int idx = uri.getPath().lastIndexOf('/'); mFilename = uri.getPath().substring(idx + 1); } - copyToSD = false; } private void createFileFromInputStream(InputStream inputStream, File file) throws IOException { @@ -240,7 +239,13 @@ public class Async { @Override protected void onPreExecute() { - progress = ProgressDialog.show(mContext, mContext.getString(R.string.zip_install_progress_title), mContext.getString(R.string.zip_install_progress_msg, mFilename)); + progress.setTitle(R.string.zip_install_progress_title); + progress.show(); + } + + @Override + protected void onProgressUpdate(String... values) { + progress.setMessage(values[0]); } @Override @@ -251,11 +256,10 @@ public class Async { preProcessing(); copyToCache(); } catch (Throwable e) { - this.cancel(true); - progress.cancel(); e.printStackTrace(); return -1; } + publishProgress(mContext.getString(R.string.zip_install_progress_msg, mFilename)); if (Shell.rootAccess()) { ret = Shell.su( "unzip -o " + mCachedFile.getPath() + " META-INF/com/google/android/* -d " + mCachedFile.getParent(), @@ -274,28 +278,6 @@ public class Async { Logger.dev(line); } } - // Copy the file to sdcard - if (copyToSD && mCachedFile != null) { - String filename = Utils.getLegalFilename(mFilename.contains(".zip") ? mFilename : mFilename + ".zip"); - sdFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename); - Logger.dev("FlashZip: Copy zip back to " + sdFile.getPath()); - if ((!sdFile.getParentFile().exists() && !sdFile.getParentFile().mkdirs()) || (sdFile.exists() && !sdFile.delete())) { - sdFile = null; - } else { - try { - FileInputStream in = new FileInputStream(mCachedFile); - createFileFromInputStream(in, sdFile); - in.close(); - } catch (IOException e) { - // Use the badass way :) - e.printStackTrace(); - Shell.su("cp -af " + mCachedFile.getPath() + " " + sdFile.getPath()); - if (!sdFile.exists()) { - sdFile = null; - } - } - } - } if (mCachedFile != null && mCachedFile.exists() && !mCachedFile.delete()) { Utils.removeItem(mCachedFile.getPath()); } @@ -312,11 +294,7 @@ public class Async { progress.dismiss(); switch (result) { case -1: - if (sdFile == null) { - Toast.makeText(mContext, mContext.getString(R.string.install_error), Toast.LENGTH_LONG).show(); - } else { - Toast.makeText(mContext, mContext.getString(R.string.manual_install, sdFile.getAbsolutePath()), Toast.LENGTH_LONG).show(); - } + Toast.makeText(mContext, mContext.getString(R.string.manual_install, mUri.getPath()), Toast.LENGTH_LONG).show(); break; case 0: Toast.makeText(mContext, mContext.getString(R.string.invalid_zip), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f11b9f2ba..adde5ff7f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -78,6 +78,7 @@ Do you want to reboot now? Reboot Installing + Processing zip file ... "Installing %1$s …" No Magisk Installed! Do you want to download and install Magisk?