diff --git a/app/src/full/java/com/topjohnwu/magisk/Const.java b/app/src/full/java/com/topjohnwu/magisk/Const.java index 5bde3ac61..f770cbe3a 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Const.java +++ b/app/src/full/java/com/topjohnwu/magisk/Const.java @@ -1,5 +1,6 @@ package com.topjohnwu.magisk; +import android.os.Environment; import android.os.Process; import java.io.File; @@ -9,7 +10,6 @@ import java.util.List; public class Const { public static final String DEBUG_TAG = "MagiskManager"; - public static final String ORIG_PKG_NAME = BuildConfig.APPLICATION_ID; public static final String MAGISKHIDE_PROP = "persist.magisk.hide"; // APK content @@ -19,11 +19,13 @@ public class Const { // Paths public static final String MAGISK_PATH = "/sbin/.magisk/img"; + public static final File EXTERNAL_PATH; public static File MAGISK_DISABLE_FILE; static { - /* Prevent crashing on unrooted devices */ MAGISK_DISABLE_FILE = new File("xxx"); + EXTERNAL_PATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + EXTERNAL_PATH.mkdirs(); } public static final String BUSYBOX_PATH = "/sbin/.magisk/busybox"; diff --git a/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java b/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java index 514ae8e92..e3fd4fbea 100644 --- a/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java @@ -15,7 +15,6 @@ import android.widget.Toast; import com.topjohnwu.magisk.asyncs.FlashZip; import com.topjohnwu.magisk.asyncs.InstallMagisk; import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.CallbackList; @@ -59,7 +58,7 @@ public class FlashActivity extends BaseActivity { now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND)); - File logFile = new File(Download.EXTERNAL_PATH, filename); + File logFile = new File(Const.EXTERNAL_PATH, filename); try (FileWriter writer = new FileWriter(logFile)) { for (String s : logs) { writer.write(s); diff --git a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java index cfe55748f..f551521bf 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java @@ -23,15 +23,15 @@ public class SplashActivity extends BaseActivity { super.onCreate(savedInstanceState); String pkg = mm.mDB.getStrings(Const.Key.SU_MANAGER, null); - if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) { + if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) { mm.mDB.setStrings(Const.Key.SU_MANAGER, null); Shell.su("pm uninstall " + pkg).exec(); } if (TextUtils.equals(pkg, getPackageName())) { try { // We are the manager, remove com.topjohnwu.magisk as it could be malware - getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0); - RootUtils.uninstallPkg(Const.ORIG_PKG_NAME); + getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0); + RootUtils.uninstallPkg(BuildConfig.APPLICATION_ID); } catch (PackageManager.NameNotFoundException ignored) {} } diff --git a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java index e9352601f..9db9ad34d 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java @@ -135,7 +135,7 @@ public class SuRequestActivity extends BaseActivity { } // Never allow com.topjohnwu.magisk (could be malware) - if (TextUtils.equals(policy.packageName, Const.ORIG_PKG_NAME)) { + if (TextUtils.equals(policy.packageName, BuildConfig.APPLICATION_ID)) { finish(); return; } diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index f0e2c3704..72c49060f 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -14,7 +14,6 @@ import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.container.TarEntry; -import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.ZipUtils; @@ -243,7 +242,7 @@ public class InstallMagisk extends ParallelTask { switch (mode) { case PATCH_MODE: String fmt = mm.prefs.getString(Const.Key.BOOT_FORMAT, ".img"); - File dest = new File(Download.EXTERNAL_PATH, "patched_boot" + fmt); + File dest = new File(Const.EXTERNAL_PATH, "patched_boot" + fmt); dest.getParentFile().mkdirs(); OutputStream out; switch (fmt) { diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java index 0f85e607a..8920fb07e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java @@ -5,6 +5,7 @@ import android.app.ProgressDialog; import android.os.AsyncTask; import android.widget.Toast; +import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; @@ -82,11 +83,11 @@ public class PatchAPK { // Generate a new app with random package name SuFile repack = new SuFile("/data/local/tmp/repack.apk"); - String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length()); + String pkg = genPackageName("com.", BuildConfig.APPLICATION_ID.length()); try { JarMap apk = new JarMap(mm.getPackageCodePath()); - if (!patchPackageID(apk, Const.ORIG_PKG_NAME, pkg)) + if (!patchPackageID(apk, BuildConfig.APPLICATION_ID, pkg)) return false; SignAPK.sign(apk, new SuFileOutputStream(repack)); } catch (Exception e) { @@ -101,7 +102,7 @@ public class PatchAPK { mm.mDB.setStrings(Const.Key.SU_MANAGER, pkg); Data.exportPrefs(); - RootUtils.rmAndLaunch(Const.ORIG_PKG_NAME, pkg); + RootUtils.rmAndLaunch(BuildConfig.APPLICATION_ID, pkg); return true; } diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java index 51930cce2..40ca8b284 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java @@ -13,7 +13,6 @@ import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.container.Repo; -import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.ZipUtils; @@ -48,7 +47,7 @@ public class ProcessRepoZip extends ParallelTask { super(context); mRepo = repo; mInstall = install && Shell.rootAccess(); - mFile = new File(Download.EXTERNAL_PATH, repo.getDownloadFilename()); + mFile = new File(Const.EXTERNAL_PATH, repo.getDownloadFilename()); } private void removeTopFolder(File input, File output) throws IOException { diff --git a/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java b/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java index 71efa6278..631dbcbd7 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java @@ -8,11 +8,11 @@ import android.os.Bundle; import android.view.WindowManager; import android.widget.Toast; +import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.NoUIActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.Topic; @@ -91,7 +91,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au granted = false; } if (granted) { - Download.EXTERNAL_PATH.mkdirs(); + Const.EXTERNAL_PATH.mkdirs(); callback.run(); } else { // Passed in context should be an activity if not granted, need to show dialog! diff --git a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java index 4ab1b55de..632aece6f 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java @@ -13,7 +13,6 @@ import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Utils; import java.util.List; @@ -70,7 +69,7 @@ class InstallMethodDialog extends AlertDialog.Builder { Data.remoteMagiskVersionString, Data.remoteMagiskVersionCode); NotificationProgress progress = new NotificationProgress(filename); AndroidNetworking - .download(Data.magiskLink, Download.EXTERNAL_PATH.getPath(), filename) + .download(Data.magiskLink, Const.EXTERNAL_PATH.getPath(), filename) .build() .setDownloadProgressListener(progress) .startDownload(new DownloadListener() { diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java index 40cd619db..10d2b298c 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java @@ -19,7 +19,6 @@ import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.components.BaseFragment; import com.topjohnwu.magisk.components.SnackbarMaker; -import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; @@ -100,7 +99,7 @@ public class MagiskLogFragment extends BaseFragment { now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND)); - File logFile = new File(Download.EXTERNAL_PATH, filename); + File logFile = new File(Const.EXTERNAL_PATH, filename); try { logFile.createNewFile(); } catch (IOException e) { diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java index a4c9323e7..2763afe3c 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java @@ -10,6 +10,7 @@ import android.view.ViewGroup; import android.widget.EditText; import android.widget.Toast; +import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; @@ -151,7 +152,7 @@ public class SettingsFragment extends PreferenceFragmentCompat } if (Shell.rootAccess() && Const.USER_ID == 0) { - if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { + if (mm.getPackageName().equals(BuildConfig.APPLICATION_ID)) { generalCatagory.removePreference(restoreManager); } else { if (!Download.checkNetworkStatus(mm)) diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java b/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java index 5fd985446..b5545cd3b 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java @@ -5,7 +5,7 @@ import android.os.AsyncTask; import com.androidnetworking.AndroidNetworking; import com.androidnetworking.error.ANError; import com.androidnetworking.interfaces.DownloadListener; -import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; @@ -70,7 +70,7 @@ public class DlInstallManager { public void onDownloadComplete(File apk, NotificationProgress progress) { File patched = apk; MagiskManager mm = Data.MM(); - if (!mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { + if (!mm.getPackageName().equals(BuildConfig.APPLICATION_ID)) { progress.getNotification() .setProgress(0, 0, true) .setContentTitle(mm.getString(R.string.hide_manager_title)) @@ -79,7 +79,7 @@ public class DlInstallManager { patched = new File(apk.getParent(), "patched.apk"); try { JarMap jarMap = new JarMap(apk); - PatchAPK.patchPackageID(jarMap, Const.ORIG_PKG_NAME, mm.getPackageName()); + PatchAPK.patchPackageID(jarMap, BuildConfig.APPLICATION_ID, mm.getPackageName()); SignAPK.sign(jarMap, new BufferedOutputStream(new FileOutputStream(patched))); } catch (Exception e) { return; @@ -97,7 +97,7 @@ public class DlInstallManager { progress.dismiss(); Data.exportPrefs(); if (ShellUtils.fastCmdResult("pm install " + apk)) - RootUtils.rmAndLaunch(Data.MM().getPackageName(), Const.ORIG_PKG_NAME); + RootUtils.rmAndLaunch(Data.MM().getPackageName(), BuildConfig.APPLICATION_ID); } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Download.java b/app/src/main/java/com/topjohnwu/magisk/utils/Download.java index 6735d9f56..b917918cd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Download.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Download.java @@ -3,19 +3,9 @@ package com.topjohnwu.magisk.utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.os.Environment; - -import java.io.File; public class Download { - public static final File EXTERNAL_PATH = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); - - static { - EXTERNAL_PATH.mkdirs(); - } - public static String getLegalFilename(CharSequence filename) { return filename.toString().replace(" ", "_").replace("'", "").replace("\"", "") .replace("$", "").replace("`", "").replace("*", "").replace("/", "_")