From ce4b742b25d737420d0492eeca42f8bd8b4012c4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 4 Sep 2017 01:57:45 +0800 Subject: [PATCH] Support .img.tar as input --- app/build.gradle | 10 ++++---- .../com/topjohnwu/magisk/MainActivity.java | 2 +- .../magisk/asyncs/InstallMagisk.java | 23 ++++++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4afd2fd90..a3e3e22b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { applicationId "com.topjohnwu.magisk" minSdkVersion 21 targetSdkVersion 26 - versionCode 52 + versionCode 53 versionName "5.2.0" ndk { moduleName 'zipadjust' @@ -54,10 +54,10 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation project(':resource') - implementation 'com.android.support:recyclerview-v7:26.0.1' - implementation 'com.android.support:cardview-v7:26.0.1' - implementation 'com.android.support:design:26.0.1' - implementation 'com.android.support:support-v4:26.0.1' + implementation 'com.android.support:recyclerview-v7:26.0.2' + implementation 'com.android.support:cardview-v7:26.0.2' + implementation 'com.android.support:design:26.0.2' + implementation 'com.android.support:support-v4:26.0.2' implementation 'com.jakewharton:butterknife:8.8.1' implementation 'com.atlassian.commonmark:commonmark:0.9.0' implementation 'org.bouncycastle:bcprov-jdk15on:1.57' diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index c55f47900..5b0fe444b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -51,7 +51,7 @@ public class MainActivity extends Activity setSupportActionBar(toolbar); - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.magisk, R.string.magisk) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index fa8aea0f3..433297cf7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -10,8 +10,10 @@ import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.utils.AdaptiveList; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.TarEntry; +import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.ZipUtils; +import org.kamranzafar.jtar.TarInputStream; import org.kamranzafar.jtar.TarOutputStream; import java.io.BufferedInputStream; @@ -113,12 +115,27 @@ public class InstallMagisk extends ParallelTask { // Copy boot image to local try ( InputStream in = mm.getContentResolver().openInputStream(mBootImg); - OutputStream out = new FileOutputStream(boot); + OutputStream out = new FileOutputStream(boot) ) { + InputStream source; if (in == null) throw new FileNotFoundException(); + + if (Utils.getNameFromUri(mm, mBootImg).endsWith(".tar")) { + // Extract boot.img from tar + TarInputStream tar = new TarInputStream(new BufferedInputStream(in)); + org.kamranzafar.jtar.TarEntry entry; + while ((entry = tar.getNextEntry()) != null) { + if (entry.getName().equals("boot.img")) + break; + } + source = tar; + } else { + // Direct copy raw image + source = in; + } byte buffer[] = new byte[1024]; int length; - while ((length = in.read(buffer)) > 0) + while ((length = source.read(buffer)) > 0) out.write(buffer, 0, length); } catch (FileNotFoundException e) { mList.add("! Invalid Uri"); @@ -141,7 +158,7 @@ public class InstallMagisk extends ParallelTask { getShell().sh(mList, "cd " + install, "KEEPFORCEENCRYPT=" + mKeepEnc + " KEEPVERITY=" + mKeepVerity + " sh " + - "update-binary indep boot_patch.sh " + boot + + "update-binary indep boot_patch.sh " + boot + " 2>&1" + " && echo 'Success!' || echo 'Failed!'" );