From b570cb5b77e2693cbf2cc228514e687af5ccc50f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 18 Nov 2017 00:04:31 +0800 Subject: [PATCH] Extract external path --- .../java/com/topjohnwu/magisk/MagiskLogFragment.java | 9 ++++----- .../java/com/topjohnwu/magisk/asyncs/HideManager.java | 3 +-- .../java/com/topjohnwu/magisk/asyncs/InstallMagisk.java | 3 +-- .../java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java | 3 +-- .../com/topjohnwu/magisk/receivers/PackageReceiver.java | 1 - app/src/main/java/com/topjohnwu/magisk/utils/Const.java | 4 ++++ app/src/main/java/com/topjohnwu/magisk/utils/Utils.java | 3 +-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java index 8871352a3..e95318d9d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java @@ -3,7 +3,6 @@ package com.topjohnwu.magisk; import android.Manifest; import android.annotation.SuppressLint; import android.os.Bundle; -import android.os.Environment; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; import android.text.TextUtils; @@ -30,6 +29,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Calendar; +import java.util.Locale; import butterknife.BindView; import butterknife.ButterKnife; @@ -109,7 +109,6 @@ public class MagiskLogFragment extends Fragment { super(MagiskLogFragment.this.getActivity()); } - @SuppressLint("DefaultLocale") @Override protected Object doInBackground(Object... params) { mode = (int) params[0]; @@ -126,13 +125,13 @@ public class MagiskLogFragment extends Fragment { case 2: Calendar now = Calendar.getInstance(); - String filename = String.format( - "magisk_%s_%04d%02d%02d_%02d%02d%02d.log", "error", + String filename = String.format(Locale.US, + "magisk_log_%04d%02d%02d_%02d:%02d:%02d.log", now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1, now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND)); - targetFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename); + targetFile = new File(Const.EXTERNAL_PATH + "/logs", filename); if ((!targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs()) || (targetFile.exists() && !targetFile.delete())) { diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java index 19cccba68..800bb7901 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java @@ -1,6 +1,5 @@ package com.topjohnwu.magisk.asyncs; -import android.os.Environment; import android.widget.Toast; import com.topjohnwu.crypto.JarMap; @@ -97,7 +96,7 @@ public class HideManager extends ParallelTask { MagiskManager mm = MagiskManager.get(); // Generate a new unhide app with random package name - File repack = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", "repack.apk"); + File repack = new File(Const.EXTERNAL_PATH, "repack.apk"); repack.getParentFile().mkdirs(); String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length()); 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 8f0871b4f..2c83dd544 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -4,7 +4,6 @@ import android.app.Activity; import android.content.res.AssetManager; import android.net.Uri; import android.os.Build; -import android.os.Environment; import android.text.TextUtils; import com.topjohnwu.crypto.SignBoot; @@ -203,7 +202,7 @@ public class InstallMagisk extends ParallelTask { switch (mode) { case PATCH_MODE: - File dest = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/patched_boot" + mm.bootFormat); + File dest = new File(Const.EXTERNAL_PATH, patched_boot + mm.bootFormat); dest.getParentFile().mkdirs(); switch (mm.bootFormat) { case ".img": diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java index 80c95dd0b..72c48b40d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java @@ -5,7 +5,6 @@ import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.net.Uri; -import android.os.Environment; import android.os.Handler; import android.support.annotation.NonNull; import android.widget.Toast; @@ -45,7 +44,7 @@ public class ProcessRepoZip extends ParallelTask { public ProcessRepoZip(Activity context, String link, String filename, boolean install) { super(context); mLink = link; - mFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", filename); + mFile = new File(Const.EXTERNAL_PATH, filename); mInstall = install; mHandler = new Handler(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/PackageReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/PackageReceiver.java index f580454ac..40e6cb5d4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/PackageReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/PackageReceiver.java @@ -5,7 +5,6 @@ import android.content.Context; import android.content.Intent; import com.topjohnwu.magisk.MagiskManager; -import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Const.java b/app/src/main/java/com/topjohnwu/magisk/utils/Const.java index 5d8eb6151..670edf763 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Const.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Const.java @@ -1,5 +1,8 @@ package com.topjohnwu.magisk.utils; +import android.os.Environment; + +import java.io.File; import java.util.Arrays; import java.util.List; @@ -22,6 +25,7 @@ public class Const { public static final String TMP_FOLDER_PATH = "/dev/tmp"; public static final String MAGISK_LOG = "/cache/magisk.log"; public static final String BUSYBOXPATH = "/dev/magisk/bin"; + public static final File EXTERNAL_PATH = new File(Environment.getExternalStorageDirectory(), "MagiskManager"); public static String MAGISK_PATH() { if (Utils.itemExist("/dev/magisk/img")) { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 7ec13f4a0..19ec5afcc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -14,7 +14,6 @@ import android.database.Cursor; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; -import android.os.Environment; import android.provider.OpenableColumns; import android.support.annotation.StringRes; import android.support.design.widget.Snackbar; @@ -70,7 +69,7 @@ public class Utils { return; runWithPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> { - File file = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename); + File file = new File(Const.EXTERNAL_PATH, filename); if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs()) || (file.exists() && !file.delete())) {