You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Organize constants
This commit is contained in:
@@ -31,8 +31,8 @@ public class BootSigner {
|
||||
} else {
|
||||
/* Use internal test keys */
|
||||
JarFile apk = new JarFile(System.getProperty("java.class.path"));
|
||||
JarEntry keyEntry = apk.getJarEntry("assets/" + ZipUtils.PRIVATE_KEY_NAME);
|
||||
JarEntry sigEntry = apk.getJarEntry("assets/" + ZipUtils.PUBLIC_KEY_NAME);
|
||||
JarEntry keyEntry = apk.getJarEntry("assets/" + Const.PRIVATE_KEY_NAME);
|
||||
JarEntry sigEntry = apk.getJarEntry("assets/" + Const.PUBLIC_KEY_NAME);
|
||||
|
||||
keyIn = apk.getInputStream(keyEntry);
|
||||
certIn = apk.getInputStream(sigEntry);
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Const {
|
||||
|
||||
public static final String DEBUG_TAG = "MagiskManager";
|
||||
public static final String ORIG_PKG_NAME = "com.topjohnwu.magisk";
|
||||
public static final String SNET_PKG = "com.topjohnwu.snet";
|
||||
public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
|
||||
public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable";
|
||||
|
||||
// APK content
|
||||
public static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem";
|
||||
public static final String PRIVATE_KEY_NAME = "private.key.pk8";
|
||||
public static final String UNINSTALLER = "magisk_uninstaller.sh";
|
||||
public static final String UTIL_FUNCTIONS= "util_functions.sh";
|
||||
public static final String ANDROID_MANIFEST = "AndroidManifest.xml";
|
||||
|
||||
// Paths
|
||||
public static final String MAGISK_DISABLE_FILE = "/cache/.disable_magisk";
|
||||
public static final String MAGISK_HOST_FILE = "/magisk/.core/hosts";
|
||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
||||
public static final String MAGISK_PATH = "/magisk";
|
||||
public static final String MAGISK_LOG = "/cache/magisk.log";
|
||||
public static final String BUSYBOXPATH = "/dev/magisk/bin";
|
||||
|
||||
/* A list of apps that should not be shown as hide-able */
|
||||
public static final List<String> SN_BLACKLIST = Arrays.asList(
|
||||
"android",
|
||||
"com.topjohnwu.magisk",
|
||||
"com.google.android.gms"
|
||||
);
|
||||
|
||||
/* A list of apps that already uses SafetyNet
|
||||
* They DO NOT need to be added to hide list */
|
||||
public static final List<String> SN_DEFAULTLIST = Arrays.asList(
|
||||
"com.google.android.apps.walletnfcrel",
|
||||
"com.nianticlabs.pokemongo"
|
||||
);
|
||||
|
||||
public static class ID {
|
||||
public static final int UPDATE_SERVICE_ID = 1;
|
||||
public static final int FETCH_ZIP = 2;
|
||||
public static final int SELECT_BOOT = 3;
|
||||
|
||||
// notifications
|
||||
public static final int MAGISK_UPDATE_NOTIFICATION_ID = 4;
|
||||
public static final int APK_UPDATE_NOTIFICATION_ID = 5;
|
||||
public static final int ONBOOT_NOTIFICATION_ID = 6;
|
||||
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
||||
}
|
||||
|
||||
public static class Url {
|
||||
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
||||
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
||||
public static final String SNET_URL = "https://www.dropbox.com/s/jg2yhcrn3l9fckc/snet.apk?dl=1";
|
||||
public static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.2/busybox-arm";
|
||||
public static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.2/busybox-x86";
|
||||
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
|
||||
public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
|
||||
public static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";
|
||||
public static final String DONATION_URL = "https://www.paypal.me/topjohnwu";
|
||||
public static final String XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382";
|
||||
public static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager";
|
||||
}
|
||||
|
||||
|
||||
public static class Key {
|
||||
// su
|
||||
public static final String ROOT_ACCESS = "root_access";
|
||||
public static final String SU_MULTIUSER_MODE = "multiuser_mode";
|
||||
public static final String SU_MNT_NS = "mnt_ns";
|
||||
public static final String SU_REQUESTER = "requester";
|
||||
public static final String SU_REQUEST_TIMEOUT = "su_request_timeout";
|
||||
public static final String SU_AUTO_RESPONSE = "su_auto_response";
|
||||
public static final String SU_NOTIFICATION = "su_notification";
|
||||
public static final String SU_REAUTH = "su_reauth";
|
||||
|
||||
// intents
|
||||
public static final String OPEN_SECTION = "section";
|
||||
public static final String INTENT_SET_VERSION = "version";
|
||||
public static final String INTENT_SET_LINK = "link";
|
||||
public static final String FLASH_ACTION = "action";
|
||||
public static final String FLASH_SET_BOOT = "boot";
|
||||
public static final String FLASH_SET_ENC = "enc";
|
||||
public static final String FLASH_SET_VERITY = "verity";
|
||||
|
||||
// others
|
||||
public static final String UPDATE_NOTIFICATION = "notification";
|
||||
public static final String UPDATE_CHANNEL = "update_channel";
|
||||
public static final String BOOT_FORMAT = "boot_format";
|
||||
public static final String SNET_VER = "snet_version";
|
||||
public static final String UPDATE_SERVICE_VER = "update_service_version";
|
||||
public static final String MAGISKHIDE = "magiskhide";
|
||||
public static final String HOSTS = "hosts";
|
||||
public static final String DISABLE = "disable";
|
||||
public static final String LOCALE = "locale";
|
||||
public static final String DARK_THEME = "dark_theme";
|
||||
public static final String ETAG_KEY = "ETag";
|
||||
public static final String LINK_KEY = "Link";
|
||||
public static final String IF_NONE_MATCH = "If-None-Match";
|
||||
}
|
||||
|
||||
|
||||
public static class Value {
|
||||
public static final int STABLE_CHANNEL = 0;
|
||||
public static final int BETA_CHANNEL = 1;
|
||||
public static final int ROOT_ACCESS_DISABLED = 0;
|
||||
public static final int ROOT_ACCESS_APPS_ONLY = 1;
|
||||
public static final int ROOT_ACCESS_ADB_ONLY = 2;
|
||||
public static final int ROOT_ACCESS_APPS_AND_ADB = 3;
|
||||
public static final int MULTIUSER_MODE_OWNER_ONLY = 0;
|
||||
public static final int MULTIUSER_MODE_OWNER_MANAGED = 1;
|
||||
public static final int MULTIUSER_MODE_USER = 2;
|
||||
public static final int NAMESPACE_MODE_GLOBAL = 0;
|
||||
public static final int NAMESPACE_MODE_REQUESTER = 1;
|
||||
public static final int NAMESPACE_MODE_ISOLATE = 2;
|
||||
public static final int NO_NOTIFICATION = 0;
|
||||
public static final int NOTIFICATION_TOAST = 1;
|
||||
public static final int NOTIFY_NORMAL_LOG = 0;
|
||||
public static final int NOTIFY_USER_TOASTS = 1;
|
||||
public static final int NOTIFY_USER_TO_OWNER = 2;
|
||||
public static final int SU_PROMPT = 0;
|
||||
public static final int SU_AUTO_DENY = 1;
|
||||
public static final int SU_AUTO_ALLOW = 2;
|
||||
public static final String FLASH_ZIP = "flash";
|
||||
public static final String PATCH_BOOT = "patch";
|
||||
public static final String FLASH_MAGISK = "magisk";
|
||||
public static final int[] timeoutList = {0, -1, 10, 20, 30, 60};
|
||||
public static final int UPDATE_SERVICE_VER = 1;
|
||||
public static final int SNET_VER = 3;
|
||||
public static final int MIN_TEMPLATE_VER = 4;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,10 @@ import java.util.Locale;
|
||||
|
||||
public class Logger {
|
||||
|
||||
public static final String DEBUG_TAG = "MagiskManager";
|
||||
private static final boolean SHELL_LOGGING = false;
|
||||
|
||||
public static void debug(String line) {
|
||||
Log.d(DEBUG_TAG, "DEBUG: " + line);
|
||||
Log.d(Const.DEBUG_TAG, "DEBUG: " + line);
|
||||
}
|
||||
|
||||
public static void debug(String fmt, Object... args) {
|
||||
@@ -18,7 +17,7 @@ public class Logger {
|
||||
}
|
||||
|
||||
public static void error(String line) {
|
||||
Log.e(DEBUG_TAG, "ERROR: " + line);
|
||||
Log.e(Const.DEBUG_TAG, "ERROR: " + line);
|
||||
}
|
||||
|
||||
public static void error(String fmt, Object... args) {
|
||||
@@ -27,7 +26,7 @@ public class Logger {
|
||||
|
||||
public static void shell(boolean in, String line) {
|
||||
if (SHELL_LOGGING) {
|
||||
Log.d(DEBUG_TAG, (in ? "SHELLIN : " : "SHELLOUT: ") + line);
|
||||
Log.d(Const.DEBUG_TAG, (in ? "SHELLIN : " : "SHELLOUT: ") + line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,49 +29,45 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShowUI {
|
||||
private static final int SELECT_BOOT_IMG = 3;
|
||||
private static final String UNINSTALLER = "magisk_uninstaller.sh";
|
||||
private static final int MAGISK_UPDATE_NOTIFICATION_ID = 1;
|
||||
private static final int APK_UPDATE_NOTIFICATION_ID = 2;
|
||||
|
||||
public static void showMagiskUpdateNotification() {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, MagiskManager.NOTIFICATION_CHANNEL);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
|
||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
||||
.setContentTitle(mm.getString(R.string.magisk_update_title))
|
||||
.setContentText(mm.getString(R.string.magisk_update_available, mm.remoteMagiskVersionString))
|
||||
.setVibrate(new long[]{0, 100, 100, 100})
|
||||
.setAutoCancel(true);
|
||||
Intent intent = new Intent(mm, SplashActivity.class);
|
||||
intent.putExtra(MagiskManager.INTENT_SECTION, "magisk");
|
||||
intent.putExtra(Const.Key.OPEN_SECTION, "magisk");
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mm);
|
||||
stackBuilder.addParentStack(SplashActivity.class);
|
||||
stackBuilder.addNextIntent(intent);
|
||||
PendingIntent pendingIntent = stackBuilder.getPendingIntent(MAGISK_UPDATE_NOTIFICATION_ID,
|
||||
PendingIntent pendingIntent = stackBuilder.getPendingIntent(Const.ID.MAGISK_UPDATE_NOTIFICATION_ID,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(MAGISK_UPDATE_NOTIFICATION_ID, builder.build());
|
||||
notificationManager.notify(Const.ID.MAGISK_UPDATE_NOTIFICATION_ID, builder.build());
|
||||
}
|
||||
|
||||
public static void showManagerUpdateNotification() {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, MagiskManager.NOTIFICATION_CHANNEL);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
|
||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
||||
.setContentTitle(mm.getString(R.string.manager_update_title))
|
||||
.setContentText(mm.getString(R.string.manager_download_install))
|
||||
.setVibrate(new long[]{0, 100, 100, 100})
|
||||
.setAutoCancel(true);
|
||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
||||
intent.putExtra(MagiskManager.INTENT_LINK, mm.managerLink);
|
||||
intent.putExtra(MagiskManager.INTENT_VERSION, mm.remoteManagerVersionString);
|
||||
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
||||
intent.putExtra(Const.Key.INTENT_SET_VERSION, mm.remoteManagerVersionString);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
|
||||
APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(APK_UPDATE_NOTIFICATION_ID, builder.build());
|
||||
notificationManager.notify(Const.ID.APK_UPDATE_NOTIFICATION_ID, builder.build());
|
||||
}
|
||||
|
||||
public static void showMagiskInstallDialog(MagiskFragment fragment, boolean enc, boolean verity) {
|
||||
@@ -109,9 +105,9 @@ public class ShowUI {
|
||||
MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
fragment.startActivityForResult(intent, SELECT_BOOT_IMG,
|
||||
fragment.startActivityForResult(intent, Const.ID.SELECT_BOOT,
|
||||
(requestCode, resultCode, data) -> {
|
||||
if (requestCode == SELECT_BOOT_IMG
|
||||
if (requestCode == Const.ID.SELECT_BOOT
|
||||
&& resultCode == Activity.RESULT_OK && data != null) {
|
||||
Utils.dlAndReceive(
|
||||
fragment.getActivity(),
|
||||
@@ -121,10 +117,10 @@ public class ShowUI {
|
||||
Intent intent = new Intent(mm, FlashActivity.class);
|
||||
intent.setData(uri)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(FlashActivity.SET_BOOT, data.getData())
|
||||
.putExtra(FlashActivity.SET_ENC, enc)
|
||||
.putExtra(FlashActivity.SET_VERITY, verity)
|
||||
.putExtra(FlashActivity.SET_ACTION, FlashActivity.PATCH_BOOT);
|
||||
.putExtra(Const.Key.FLASH_SET_BOOT, data.getData())
|
||||
.putExtra(Const.Key.FLASH_SET_ENC, enc)
|
||||
.putExtra(Const.Key.FLASH_SET_VERITY, verity)
|
||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT);
|
||||
mm.startActivity(intent);
|
||||
}
|
||||
},
|
||||
@@ -152,10 +148,10 @@ public class ShowUI {
|
||||
Intent intent = new Intent(mm, FlashActivity.class);
|
||||
intent.setData(uri)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(FlashActivity.SET_BOOT, boot)
|
||||
.putExtra(FlashActivity.SET_ENC, enc)
|
||||
.putExtra(FlashActivity.SET_VERITY, verity)
|
||||
.putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_MAGISK);
|
||||
.putExtra(Const.Key.FLASH_SET_BOOT, boot)
|
||||
.putExtra(Const.Key.FLASH_SET_ENC, enc)
|
||||
.putExtra(Const.Key.FLASH_SET_VERITY, verity)
|
||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
|
||||
mm.startActivity(intent);
|
||||
}
|
||||
};
|
||||
@@ -182,10 +178,10 @@ public class ShowUI {
|
||||
Intent intent = new Intent(mm, FlashActivity.class);
|
||||
intent.setData(uri)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(FlashActivity.SET_BOOT, boot)
|
||||
.putExtra(FlashActivity.SET_ENC, enc)
|
||||
.putExtra(FlashActivity.SET_VERITY, verity)
|
||||
.putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_MAGISK);
|
||||
.putExtra(Const.Key.FLASH_SET_BOOT, boot)
|
||||
.putExtra(Const.Key.FLASH_SET_ENC, enc)
|
||||
.putExtra(Const.Key.FLASH_SET_VERITY, verity)
|
||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
|
||||
mm.startActivity(intent);
|
||||
}
|
||||
};
|
||||
@@ -221,8 +217,8 @@ public class ShowUI {
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.install, (d, i) -> {
|
||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
||||
intent.putExtra(MagiskManager.INTENT_LINK, mm.managerLink);
|
||||
intent.putExtra(MagiskManager.INTENT_VERSION, mm.remoteManagerVersionString);
|
||||
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
||||
intent.putExtra(Const.Key.INTENT_SET_VERSION, mm.remoteManagerVersionString);
|
||||
mm.sendBroadcast(intent);
|
||||
})
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
@@ -236,8 +232,8 @@ public class ShowUI {
|
||||
.setMessage(R.string.uninstall_magisk_msg)
|
||||
.setPositiveButton(R.string.complete_uninstall, (d, i) -> {
|
||||
try {
|
||||
InputStream in = mm.getAssets().open(UNINSTALLER);
|
||||
File uninstaller = new File(mm.getCacheDir(), UNINSTALLER);
|
||||
InputStream in = mm.getAssets().open(Const.UNINSTALLER);
|
||||
File uninstaller = new File(mm.getCacheDir(), Const.UNINSTALLER);
|
||||
FileOutputStream out = new FileOutputStream(uninstaller);
|
||||
byte[] bytes = new byte[1024];
|
||||
int read;
|
||||
@@ -246,8 +242,8 @@ public class ShowUI {
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
in = mm.getAssets().open(Utils.UTIL_FUNCTIONS);
|
||||
File utils = new File(mm.getCacheDir(), Utils.UTIL_FUNCTIONS);
|
||||
in = mm.getAssets().open(Const.UTIL_FUNCTIONS);
|
||||
File utils = new File(mm.getCacheDir(), Const.UTIL_FUNCTIONS);
|
||||
out = new FileOutputStream(utils);
|
||||
while ((read = in.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
@@ -255,8 +251,8 @@ public class ShowUI {
|
||||
in.close();
|
||||
out.close();
|
||||
Shell.su(
|
||||
"cat " + uninstaller + " > /cache/" + UNINSTALLER,
|
||||
"cat " + utils + " > /data/magisk/" + Utils.UTIL_FUNCTIONS
|
||||
"cat " + uninstaller + " > /cache/" + Const.UNINSTALLER,
|
||||
"cat " + utils + " > /data/magisk/" + Const.UTIL_FUNCTIONS
|
||||
);
|
||||
MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
|
||||
Shell.su_raw(
|
||||
|
||||
@@ -39,7 +39,6 @@ import java.util.Locale;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final String UTIL_FUNCTIONS= "util_functions.sh";
|
||||
public static boolean isDownloading = false;
|
||||
|
||||
public static boolean itemExist(String path) {
|
||||
|
||||
@@ -15,9 +15,6 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
public class ZipUtils {
|
||||
// File name in assets
|
||||
public static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem";
|
||||
public static final String PRIVATE_KEY_NAME = "private.key.pk8";
|
||||
|
||||
static {
|
||||
System.loadLibrary("zipadjust");
|
||||
@@ -69,7 +66,7 @@ public class ZipUtils {
|
||||
public static void signZip(JarMap input, File output, boolean minSign) throws Exception {
|
||||
AssetManager assets = MagiskManager.get().getAssets();
|
||||
SignAPK.signZip(
|
||||
assets.open(PUBLIC_KEY_NAME), assets.open(PRIVATE_KEY_NAME),
|
||||
assets.open(Const.PUBLIC_KEY_NAME), assets.open(Const.PRIVATE_KEY_NAME),
|
||||
input, output, minSign);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user