diff --git a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java index dbce2c5d2..5cbd8b96a 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java @@ -35,7 +35,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.zip.InflaterInputStream; +import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; @@ -183,19 +185,17 @@ public class DownloadActivity extends Activity { Os.close(fd); } } else { - File dir = new File(getCodeCacheDir(), "res"); - dir.mkdirs(); - - // addAssetPath requires a directory containing AndroidManifest.xml on Android 6.0 - try (var stubApk = new ZipFile(getPackageCodePath()); - var manifest = new FileOutputStream(new File(dir, "AndroidManifest.xml"))) { - var stubManifest = stubApk.getInputStream( - stubApk.getEntry("AndroidManifest.xml")); - APKInstall.transfer(stubManifest, manifest); + File res = new File(getCodeCacheDir(), "res.apk"); + try (var out = new ZipOutputStream(new FileOutputStream(res))) { + // AndroidManifest.xml is reuqired on Android 6-, and directory support is broken on Android 9-10 + out.putNextEntry(new ZipEntry("AndroidManifest.xml")); + try (var stubApk = new ZipFile(getPackageCodePath())) { + APKInstall.transfer(stubApk.getInputStream(stubApk.getEntry("AndroidManifest.xml")), out); + } + out.putNextEntry(new ZipEntry("resources.arsc")); + decryptResources(out); } - - decryptResources(new FileOutputStream(new File(dir, "resources.arsc"))); - StubApk.addAssetPath(getResources(), dir.getPath()); + StubApk.addAssetPath(getResources(), res.getPath()); } } }