From 2c78c415e9193efa5dc05931075f0e55c9c52ab2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 11 Mar 2018 05:28:47 +0800 Subject: [PATCH] Android P cannot install from sdcardfs, use TMPDIR --- .../com/topjohnwu/magisk/SettingsActivity.java | 16 +--------------- .../topjohnwu/magisk/asyncs/HideManager.java | 8 ++++---- .../com/topjohnwu/magisk/utils/ZipUtils.java | 17 +++-------------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 45ed7fd51..affcd0313 100644 --- a/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -159,9 +159,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { if (mm.magiskVersionCode >= 1440) { if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { hideManager.setOnPreferenceClickListener((pref) -> { - Utils.runWithPermission(getActivity(), - Manifest.permission.WRITE_EXTERNAL_STORAGE, - () -> new HideManager(getActivity()).exec()); + new HideManager(getActivity()).exec(); return true; }); generalCatagory.removePreference(restoreManager); @@ -188,18 +186,6 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { generalCatagory.removePreference(hideManager); } - if (mm.getPackageName().equals(Const.ORIG_PKG_NAME) && mm.magiskVersionCode >= 1440) { - hideManager.setOnPreferenceClickListener((pref) -> { - Utils.runWithPermission(getActivity(), - Manifest.permission.WRITE_EXTERNAL_STORAGE, - () -> new HideManager(getActivity()).exec()); - return true; - }); - generalCatagory.removePreference(restoreManager); - } else { - generalCatagory.removePreference(hideManager); - } - if (!Shell.rootAccess() || (Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { prefScreen.removePreference(suCategory); diff --git a/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java b/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java index 3de3b5999..b4603aed0 100644 --- a/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java +++ b/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java @@ -11,9 +11,10 @@ import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.ZipUtils; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; +import com.topjohnwu.superuser.io.SuFile; +import com.topjohnwu.superuser.io.SuFileOutputStream; import com.topjohnwu.utils.JarMap; -import java.io.File; import java.io.FileInputStream; import java.security.SecureRandom; import java.util.jar.JarEntry; @@ -104,8 +105,7 @@ public class HideManager extends ParallelTask { MagiskManager mm = MagiskManager.get(); // Generate a new unhide app with random package name - File repack = new File(Const.EXTERNAL_PATH, "repack.apk"); - repack.getParentFile().mkdirs(); + SuFile repack = new SuFile("/data/local/tmp/repack.apk", true); String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length()); try { @@ -123,7 +123,7 @@ public class HideManager extends ParallelTask { apk.getOutputStream(je).write(xml); // Sign the APK - ZipUtils.signZip(apk, repack); + ZipUtils.signZip(apk, new SuFileOutputStream(repack)); } catch (Exception e) { e.printStackTrace(); return false; diff --git a/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java b/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java index 628646e0a..3baf94363 100644 --- a/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java +++ b/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java @@ -49,21 +49,10 @@ public class ZipUtils { } } - public static void signZip(InputStream is, File output) throws Exception { - try (JarMap map = new JarMap(is, false)) { - signZip(map, output); - } - } - public static void signZip(File input, File output) throws Exception { - try (JarMap map = new JarMap(input, false)) { - signZip(map, output); - } - } - - public static void signZip(JarMap input, File output) throws Exception { - try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(output))) { - signZip(input, out); + try (JarMap map = new JarMap(input, false); + BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(output))) { + signZip(map, out); } }