Organize constants

This commit is contained in:
topjohnwu 2017-11-06 04:41:23 +08:00
parent fd19fbf300
commit c39170c42e
33 changed files with 380 additions and 339 deletions

View File

@ -17,6 +17,7 @@ import android.widget.TextView;
import com.topjohnwu.magisk.components.AboutCardRow; import com.topjohnwu.magisk.components.AboutCardRow;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.components.AlertDialogBuilder; import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.utils.Const;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -27,10 +28,6 @@ import butterknife.ButterKnife;
public class AboutActivity extends Activity { public class AboutActivity extends Activity {
private static final String DONATION_URL = "https://www.paypal.me/topjohnwu";
private static final String XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382";
private static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager";
@BindView(R.id.toolbar) Toolbar toolbar; @BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.app_version_info) AboutCardRow appVersionInfo; @BindView(R.id.app_version_info) AboutCardRow appVersionInfo;
@BindView(R.id.app_changelog) AboutCardRow appChangelog; @BindView(R.id.app_changelog) AboutCardRow appChangelog;
@ -120,13 +117,13 @@ public class AboutActivity extends Activity {
} }
appSourceCode.removeSummary(); appSourceCode.removeSummary();
appSourceCode.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(SOURCE_CODE_URL)))); appSourceCode.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.SOURCE_CODE_URL))));
supportThread.removeSummary(); supportThread.removeSummary();
supportThread.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(XDA_THREAD)))); supportThread.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.XDA_THREAD))));
donation.removeSummary(); donation.removeSummary();
donation.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL)))); donation.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.DONATION_URL))));
setFloating(); setFloating();
} }

View File

@ -16,6 +16,7 @@ import com.topjohnwu.magisk.asyncs.FlashZip;
import com.topjohnwu.magisk.asyncs.InstallMagisk; import com.topjohnwu.magisk.asyncs.InstallMagisk;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.container.AdaptiveList; import com.topjohnwu.magisk.container.AdaptiveList;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import butterknife.BindView; import butterknife.BindView;
@ -24,15 +25,6 @@ import butterknife.OnClick;
public class FlashActivity extends Activity { public class FlashActivity extends Activity {
public static final String SET_ACTION = "action";
public static final String SET_BOOT = "boot";
public static final String SET_ENC = "enc";
public static final String SET_VERITY = "verity";
public static final String FLASH_ZIP = "flash";
public static final String PATCH_BOOT = "patch";
public static final String FLASH_MAGISK = "magisk";
@BindView(R.id.toolbar) Toolbar toolbar; @BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.txtLog) TextView flashLogs; @BindView(R.id.txtLog) TextView flashLogs;
@BindView(R.id.button_panel) LinearLayout buttonPanel; @BindView(R.id.button_panel) LinearLayout buttonPanel;
@ -75,22 +67,22 @@ public class FlashActivity extends Activity {
Intent intent = getIntent(); Intent intent = getIntent();
Uri uri = intent.getData(); Uri uri = intent.getData();
boolean keepEnc = intent.getBooleanExtra(SET_ENC, false); boolean keepEnc = intent.getBooleanExtra(Const.Key.FLASH_SET_ENC, false);
boolean keepVerity = intent.getBooleanExtra(SET_VERITY, false); boolean keepVerity = intent.getBooleanExtra(Const.Key.FLASH_SET_VERITY, false);
switch (getIntent().getStringExtra(SET_ACTION)) { switch (getIntent().getStringExtra(Const.Key.FLASH_ACTION)) {
case FLASH_ZIP: case Const.Value.FLASH_ZIP:
new FlashZip(this, uri, rootShellOutput) new FlashZip(this, uri, rootShellOutput)
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE)) .setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
.exec(); .exec();
break; break;
case PATCH_BOOT: case Const.Value.PATCH_BOOT:
new InstallMagisk(this, rootShellOutput, uri, keepEnc, keepVerity, (Uri) intent.getParcelableExtra(SET_BOOT)) new InstallMagisk(this, rootShellOutput, uri, keepEnc, keepVerity, (Uri) intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT))
.setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE)) .setCallBack(() -> buttonPanel.setVisibility(View.VISIBLE))
.exec(); .exec();
break; break;
case FLASH_MAGISK: case Const.Value.FLASH_MAGISK:
String boot = intent.getStringExtra(SET_BOOT); String boot = intent.getStringExtra(Const.Key.FLASH_SET_BOOT);
if (getMagiskManager().remoteMagiskVersionCode < 1370) { if (getMagiskManager().remoteMagiskVersionCode < 1370) {
// Use legacy installation method // Use legacy installation method
Shell.su_raw( Shell.su_raw(

View File

@ -43,13 +43,13 @@ import butterknife.Unbinder;
public class MagiskFragment extends Fragment public class MagiskFragment extends Fragment
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView { implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView {
public static final int CAUSE_SERVICE_DISCONNECTED = 0x01; private static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
public static final int CAUSE_NETWORK_LOST = 0x02; private static final int CAUSE_NETWORK_LOST = 0x02;
public static final int RESPONSE_ERR = 0x04; private static final int RESPONSE_ERR = 0x04;
public static final int CONNECTION_FAIL = 0x08; private static final int CONNECTION_FAIL = 0x08;
public static final int BASIC_PASS = 0x10; private static final int BASIC_PASS = 0x10;
public static final int CTS_PASS = 0x20; private static final int CTS_PASS = 0x20;
private Container expandableContainer = new Container(); private Container expandableContainer = new Container();

View File

@ -22,6 +22,7 @@ import android.widget.Toast;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.components.Fragment; import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -36,8 +37,6 @@ import butterknife.Unbinder;
public class MagiskLogFragment extends Fragment { public class MagiskLogFragment extends Fragment {
private static final String MAGISK_LOG = "/cache/magisk.log";
private Unbinder unbinder; private Unbinder unbinder;
@BindView(R.id.txtLog) TextView txtLog; @BindView(R.id.txtLog) TextView txtLog;
@ -117,11 +116,11 @@ public class MagiskLogFragment extends Fragment {
switch (mode) { switch (mode) {
case 0: case 0:
StringBuildingList logList = new StringBuildingList(); StringBuildingList logList = new StringBuildingList();
Shell.su(logList, "cat " + MAGISK_LOG + " | tail -n 1000"); Shell.su(logList, "cat " + Const.MAGISK_LOG + " | tail -n 1000");
return logList.toString(); return logList.getCharSequence();
case 1: case 1:
Shell.su_raw("echo -n > " + MAGISK_LOG); Shell.su_raw("echo -n > " + Const.MAGISK_LOG);
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show(); SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
return ""; return "";
@ -142,7 +141,7 @@ public class MagiskLogFragment extends Fragment {
try (FileWriter out = new FileWriter(targetFile)) { try (FileWriter out = new FileWriter(targetFile)) {
FileWritingList fileWritingList = new FileWritingList(out); FileWritingList fileWritingList = new FileWritingList(out);
Shell.su(fileWritingList, "cat " + MAGISK_LOG); Shell.su(fileWritingList, "cat " + Const.MAGISK_LOG);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
@ -158,7 +157,7 @@ public class MagiskLogFragment extends Fragment {
switch (mode) { switch (mode) {
case 0: case 0:
case 1: case 1:
String llog = (String) o; CharSequence llog = (CharSequence) o;
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
if (TextUtils.isEmpty(llog)) if (TextUtils.isEmpty(llog))
txtLog.setText(R.string.log_is_empty); txtLog.setText(R.string.log_is_empty);
@ -170,7 +169,7 @@ public class MagiskLogFragment extends Fragment {
case 2: case 2:
boolean bool = (boolean) o; boolean bool = (boolean) o;
if (bool) { if (bool) {
MagiskManager.toast(targetFile.toString(), Toast.LENGTH_LONG); MagiskManager.toast(targetFile.getPath(), Toast.LENGTH_LONG);
} else { } else {
MagiskManager.toast(R.string.logs_save_failed, Toast.LENGTH_LONG); MagiskManager.toast(R.string.logs_save_failed, Toast.LENGTH_LONG);
} }
@ -205,9 +204,8 @@ public class MagiskLogFragment extends Fragment {
return true; return true;
} }
@Override public CharSequence getCharSequence() {
public String toString() { return builder;
return builder.toString();
} }
} }

View File

@ -26,8 +26,7 @@ import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.database.SuDatabaseHelper; import com.topjohnwu.magisk.database.SuDatabaseHelper;
import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.superuser.SuReceiver; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.superuser.SuRequestActivity;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -45,21 +44,6 @@ public class MagiskManager extends Application {
// Global weak reference to self // Global weak reference to self
private static WeakReference<MagiskManager> weakSelf; private static WeakReference<MagiskManager> weakSelf;
public static final String ORIG_PKG_NAME = "com.topjohnwu.magisk";
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 INTENT_SECTION = "section";
public static final String INTENT_VERSION = "version";
public static final String INTENT_LINK = "link";
public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable";
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
public static final String BUSYBOXPATH = "/dev/magisk/bin";
public static final int UPDATE_SERVICE_ID = 1;
public static final int UPDATE_SERVICE_VER = 1;
// Topics // Topics
public final Topic magiskHideDone = new Topic(); public final Topic magiskHideDone = new Topic();
public final Topic reloadActivity = new Topic(); public final Topic reloadActivity = new Topic();
@ -138,9 +122,9 @@ public class MagiskManager extends Application {
} }
// If detect original package, self destruct! // If detect original package, self destruct!
if (!getPackageName().equals(ORIG_PKG_NAME)) { if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
try { try {
getPackageManager().getApplicationInfo(ORIG_PKG_NAME, 0); getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0);
Shell.su(String.format(Locale.US, "pm uninstall --user %d %s", userId, getPackageName())); Shell.su(String.format(Locale.US, "pm uninstall --user %d %s", userId, getPackageName()));
return; return;
} catch (PackageManager.NameNotFoundException ignored) { /* Expected*/ } } catch (PackageManager.NameNotFoundException ignored) { /* Expected*/ }
@ -157,7 +141,7 @@ public class MagiskManager extends Application {
} }
public void setLocale() { public void setLocale() {
localeConfig = prefs.getString("locale", ""); localeConfig = prefs.getString(Const.Key.LOCALE, "");
if (localeConfig.isEmpty()) { if (localeConfig.isEmpty()) {
locale = defaultLocale; locale = defaultLocale;
} else { } else {
@ -170,22 +154,22 @@ public class MagiskManager extends Application {
} }
public void loadConfig() { public void loadConfig() {
isDarkTheme = prefs.getBoolean("dark_theme", false); isDarkTheme = prefs.getBoolean(Const.Key.DARK_THEME, false);
// su // su
suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10); suRequestTimeout = Utils.getPrefsInt(prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]);
suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", SuRequestActivity.PROMPT); suResponseType = Utils.getPrefsInt(prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT);
suNotificationType = Utils.getPrefsInt(prefs, "su_notification", SuReceiver.TOAST); suNotificationType = Utils.getPrefsInt(prefs, Const.Key.SU_NOTIFICATION, Const.Value.NOTIFICATION_TOAST);
suReauth = prefs.getBoolean("su_reauth", false); suReauth = prefs.getBoolean(Const.Key.SU_REAUTH, false);
suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, SuDatabaseHelper.ROOT_ACCESS_APPS_AND_ADB); suAccessState = suDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB);
multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, SuDatabaseHelper.MULTIUSER_MODE_OWNER_ONLY); multiuserMode = suDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY);
suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, SuDatabaseHelper.NAMESPACE_MODE_REQUESTER); suNamespaceMode = suDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER);
updateNotification = prefs.getBoolean("notification", true); updateNotification = prefs.getBoolean(Const.Key.UPDATE_NOTIFICATION, true);
updateChannel = Utils.getPrefsInt(prefs, "update_channel", CheckUpdates.STABLE_CHANNEL); updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL);
bootFormat = prefs.getString("boot_format", ".img"); bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img");
snet_version = prefs.getInt("snet_version", -1); snet_version = prefs.getInt(Const.Key.SNET_VER, -1);
updateServiceVersion = prefs.getInt("update_service_version", -1); updateServiceVersion = prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1);
} }
public static void toast(String msg, int duration) { public static void toast(String msg, int duration) {
@ -217,7 +201,7 @@ public class MagiskManager extends Application {
// Create notification channel on Android O // Create notification channel on Android O
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, NotificationChannel channel = new NotificationChannel(Const.ID.NOTIFICATION_CHANNEL,
getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT); getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT);
getSystemService(NotificationManager.class).createNotificationChannel(channel); getSystemService(NotificationManager.class).createNotificationChannel(channel);
} }
@ -227,7 +211,7 @@ public class MagiskManager extends Application {
// Magisk working as expected // Magisk working as expected
if (Shell.rootAccess() && magiskVersionCode > 0) { if (Shell.rootAccess() && magiskVersionCode > 0) {
// Load utility shell scripts // Load utility shell scripts
try (InputStream in = getAssets().open(Utils.UTIL_FUNCTIONS)) { try (InputStream in = getAssets().open(Const.UTIL_FUNCTIONS)) {
shell.loadInputStream(in); shell.loadInputStream(in);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -237,7 +221,7 @@ public class MagiskManager extends Application {
if (Utils.checkNetworkStatus()) { if (Utils.checkNetworkStatus()) {
// Make sure we have busybox // Make sure we have busybox
if (!Utils.itemExist(BUSYBOXPATH + "/busybox")) { if (!Utils.itemExist(Const.BUSYBOXPATH + "/busybox")) {
try { try {
// Force synchronous, make sure we have busybox to use // Force synchronous, make sure we have busybox to use
new DownloadBusybox().exec().get(); new DownloadBusybox().exec().get();
@ -255,7 +239,7 @@ public class MagiskManager extends Application {
// Root shell initialization // Root shell initialization
Shell.su_raw( Shell.su_raw(
"export PATH=" + BUSYBOXPATH + ":$PATH", "export PATH=" + Const.BUSYBOXPATH + ":$PATH",
"mount_partitions", "mount_partitions",
"BOOTIMAGE=", "BOOTIMAGE=",
"find_boot_image", "find_boot_image",
@ -273,22 +257,22 @@ public class MagiskManager extends Application {
// Check alternative Magisk Manager // Check alternative Magisk Manager
String pkg; String pkg;
if (getPackageName().equals(ORIG_PKG_NAME) && if (getPackageName().equals(Const.ORIG_PKG_NAME) &&
(pkg = suDB.getStrings(SuDatabaseHelper.REQUESTER, null)) != null) { (pkg = suDB.getStrings(Const.Key.SU_REQUESTER, null)) != null) {
Shell.su_raw("pm uninstall " + pkg); Shell.su_raw("pm uninstall " + pkg);
suDB.setStrings(SuDatabaseHelper.REQUESTER, null); suDB.setStrings(Const.Key.SU_REQUESTER, null);
} }
// Add update checking service // Add update checking service
if (UPDATE_SERVICE_VER > updateServiceVersion) { if (Const.Value.UPDATE_SERVICE_VER > updateServiceVersion) {
ComponentName service = new ComponentName(this, UpdateCheckService.class); ComponentName service = new ComponentName(this, UpdateCheckService.class);
JobInfo info = new JobInfo.Builder(UPDATE_SERVICE_ID, service) JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPersisted(true) .setPersisted(true)
.setPeriodic(8 * 60 * 60 * 1000) .setPeriodic(8 * 60 * 60 * 1000)
.build(); .build();
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(info); ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(info);
updateServiceVersion = UPDATE_SERVICE_VER; updateServiceVersion = Const.Value.UPDATE_SERVICE_VER;
} }
// Fire asynctasks // Fire asynctasks
@ -297,22 +281,22 @@ public class MagiskManager extends Application {
// Write back default values // Write back default values
prefs.edit() prefs.edit()
.putBoolean("dark_theme", isDarkTheme) .putBoolean(Const.Key.DARK_THEME, isDarkTheme)
.putBoolean("magiskhide", magiskHide) .putBoolean(Const.Key.MAGISKHIDE, magiskHide)
.putBoolean("notification", updateNotification) .putBoolean(Const.Key.UPDATE_NOTIFICATION, updateNotification)
.putBoolean("hosts", Utils.itemExist(MAGISK_HOST_FILE)) .putBoolean(Const.Key.HOSTS, Utils.itemExist(Const.MAGISK_HOST_FILE))
.putBoolean("disable", Utils.itemExist(MAGISK_DISABLE_FILE)) .putBoolean(Const.Key.DISABLE, Utils.itemExist(Const.MAGISK_DISABLE_FILE))
.putBoolean("su_reauth", suReauth) .putBoolean(Const.Key.SU_REAUTH, suReauth)
.putString("su_request_timeout", String.valueOf(suRequestTimeout)) .putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout))
.putString("su_auto_response", String.valueOf(suResponseType)) .putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType))
.putString("su_notification", String.valueOf(suNotificationType)) .putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType))
.putString("su_access", String.valueOf(suAccessState)) .putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState))
.putString("multiuser_mode", String.valueOf(multiuserMode)) .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode))
.putString("mnt_ns", String.valueOf(suNamespaceMode)) .putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode))
.putString("update_channel", String.valueOf(updateChannel)) .putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel))
.putString("locale", localeConfig) .putString(Const.Key.LOCALE, localeConfig)
.putString("boot_format", bootFormat) .putString(Const.Key.BOOT_FORMAT, bootFormat)
.putInt("update_service_version", updateServiceVersion) .putInt(Const.Key.UPDATE_SERVICE_VER, updateServiceVersion)
.apply(); .apply();
} }
@ -339,16 +323,16 @@ public class MagiskManager extends Application {
magiskVersionCode = Integer.parseInt(ret.get(0)); magiskVersionCode = Integer.parseInt(ret.get(0));
} catch (NumberFormatException ignored) {} } catch (NumberFormatException ignored) {}
} }
ret = Shell.sh("getprop " + DISABLE_INDICATION_PROP); ret = Shell.sh("getprop " + Const.DISABLE_INDICATION_PROP);
try { try {
disabled = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0; disabled = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
disabled = false; disabled = false;
} }
if (magiskVersionCode > 1435) { if (magiskVersionCode > 1435) {
ret = Shell.su("resetprop -p " + MAGISKHIDE_PROP); ret = Shell.su("resetprop -p " + Const.MAGISKHIDE_PROP);
} else { } else {
ret = Shell.sh("getprop " + MAGISKHIDE_PROP); ret = Shell.sh("getprop " + Const.MAGISKHIDE_PROP);
} }
try { try {
magiskHide = !Utils.isValidShellResponse(ret) || Integer.parseInt(ret.get(0)) != 0; magiskHide = !Utils.isValidShellResponse(ret) || Integer.parseInt(ret.get(0)) != 0;

View File

@ -16,6 +16,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -70,7 +71,7 @@ public class MainActivity extends Activity
toggle.syncState(); toggle.syncState();
if (savedInstanceState == null) if (savedInstanceState == null)
navigate(getIntent().getStringExtra(MagiskManager.INTENT_SECTION)); navigate(getIntent().getStringExtra(Const.Key.OPEN_SECTION));
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
@ -115,7 +116,7 @@ public class MainActivity extends Activity
Menu menu = navigationView.getMenu(); Menu menu = navigationView.getMenu();
menu.findItem(R.id.magiskhide).setVisible( menu.findItem(R.id.magiskhide).setVisible(
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 1300 Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 1300
&& prefs.getBoolean("magiskhide", false)); && prefs.getBoolean(Const.Key.MAGISKHIDE, false));
menu.findItem(R.id.modules).setVisible( menu.findItem(R.id.modules).setVisible(
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0); Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus() && menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus() &&
@ -141,7 +142,7 @@ public class MainActivity extends Activity
case "downloads": case "downloads":
itemId = R.id.downloads; itemId = R.id.downloads;
break; break;
case "magiskhide": case Const.Key.MAGISKHIDE:
itemId = R.id.magiskhide; itemId = R.id.magiskhide;
break; break;
case "log": case "log":
@ -176,7 +177,7 @@ public class MainActivity extends Activity
displayFragment(new ReposFragment(), "downloads", true); displayFragment(new ReposFragment(), "downloads", true);
break; break;
case R.id.magiskhide: case R.id.magiskhide:
displayFragment(new MagiskHideFragment(), "magiskhide", true); displayFragment(new MagiskHideFragment(), Const.Key.MAGISKHIDE, true);
break; break;
case R.id.log: case R.id.log:
displayFragment(new LogFragment(), "log", false); displayFragment(new LogFragment(), "log", false);

View File

@ -16,6 +16,7 @@ import com.topjohnwu.magisk.adapters.ModulesAdapter;
import com.topjohnwu.magisk.asyncs.LoadModules; import com.topjohnwu.magisk.asyncs.LoadModules;
import com.topjohnwu.magisk.components.Fragment; import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -29,8 +30,6 @@ import butterknife.Unbinder;
public class ModulesFragment extends Fragment implements Topic.Subscriber { public class ModulesFragment extends Fragment implements Topic.Subscriber {
private static final int FETCH_ZIP_CODE = 2;
private Unbinder unbinder; private Unbinder unbinder;
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout; @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recyclerView) RecyclerView recyclerView; @BindView(R.id.recyclerView) RecyclerView recyclerView;
@ -40,7 +39,7 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
Utils.runWithPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> { Utils.runWithPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/zip"); intent.setType("application/zip");
startActivityForResult(intent, FETCH_ZIP_CODE); startActivityForResult(intent, Const.ID.FETCH_ZIP);
}); });
} }
@ -86,10 +85,10 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FETCH_ZIP_CODE && resultCode == Activity.RESULT_OK && data != null) { if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) {
// Get the URI of the selected file // Get the URI of the selected file
Intent intent = new Intent(getActivity(), FlashActivity.class); Intent intent = new Intent(getActivity(), FlashActivity.class);
intent.setData(data.getData()).putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_ZIP); intent.setData(data.getData()).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
startActivity(intent); startActivity(intent);
} }
} }

View File

@ -17,9 +17,8 @@ import android.widget.Toast;
import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.asyncs.CheckUpdates;
import com.topjohnwu.magisk.asyncs.HideManager; import com.topjohnwu.magisk.asyncs.HideManager;
import com.topjohnwu.magisk.asyncs.UpdateRepos;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.database.SuDatabaseHelper; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -94,16 +93,23 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
generalCatagory = (PreferenceCategory) findPreference("general"); generalCatagory = (PreferenceCategory) findPreference("general");
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk"); PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser"); PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
updateChannel = (ListPreference) findPreference("update_channel");
suAccess = (ListPreference) findPreference("su_access");
autoRes = (ListPreference) findPreference("su_auto_response");
requestTimeout = (ListPreference) findPreference("su_request_timeout");
suNotification = (ListPreference) findPreference("su_notification");
multiuserMode = (ListPreference) findPreference("multiuser_mode");
namespaceMode = (ListPreference) findPreference("mnt_ns");
SwitchPreference reauth = (SwitchPreference) findPreference("su_reauth");
Preference hideManager = findPreference("hide"); Preference hideManager = findPreference("hide");
findPreference("clear").setOnPreferenceClickListener((pref) -> {
mm.prefs.edit().remove(Const.Key.ETAG_KEY).apply();
mm.repoDB.clearRepo();
MagiskManager.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
return true;
});
updateChannel = (ListPreference) findPreference(Const.Key.UPDATE_CHANNEL);
suAccess = (ListPreference) findPreference(Const.Key.ROOT_ACCESS);
autoRes = (ListPreference) findPreference(Const.Key.SU_AUTO_RESPONSE);
requestTimeout = (ListPreference) findPreference(Const.Key.SU_REQUEST_TIMEOUT);
suNotification = (ListPreference) findPreference(Const.Key.SU_NOTIFICATION);
multiuserMode = (ListPreference) findPreference(Const.Key.SU_MULTIUSER_MODE);
namespaceMode = (ListPreference) findPreference(Const.Key.SU_MNT_NS);
SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH);
setSummary(); setSummary();
@ -117,14 +123,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
suCategory.removePreference(reauth); suCategory.removePreference(reauth);
} }
findPreference("clear").setOnPreferenceClickListener((pref) -> { if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) {
mm.prefs.edit().remove(UpdateRepos.ETAG_KEY).apply();
mm.repoDB.clearRepo();
MagiskManager.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
return true;
});
if (mm.getPackageName().equals(MagiskManager.ORIG_PKG_NAME)) {
hideManager.setOnPreferenceClickListener((pref) -> { hideManager.setOnPreferenceClickListener((pref) -> {
Utils.runWithPermission(getActivity(), Utils.runWithPermission(getActivity(),
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
@ -166,7 +165,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
lp.setEntries(entries); lp.setEntries(entries);
lp.setEntryValues(entryValues); lp.setEntryValues(entryValues);
lp.setTitle(R.string.language); lp.setTitle(R.string.language);
lp.setKey("locale"); lp.setKey(Const.Key.LOCALE);
lp.setSummary(MagiskManager.locale.getDisplayName(MagiskManager.locale)); lp.setSummary(MagiskManager.locale.getDisplayName(MagiskManager.locale));
if (isNew) { if (isNew) {
generalCatagory.addPreference(lp); generalCatagory.addPreference(lp);
@ -192,56 +191,56 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
boolean enabled; boolean enabled;
switch (key) { switch (key) {
case "dark_theme": case Const.Key.DARK_THEME:
enabled = prefs.getBoolean("dark_theme", false); enabled = prefs.getBoolean(Const.Key.DARK_THEME, false);
if (mm.isDarkTheme != enabled) { if (mm.isDarkTheme != enabled) {
mm.reloadActivity.publish(false); mm.reloadActivity.publish(false);
} }
break; break;
case "disable": case Const.Key.DISABLE:
enabled = prefs.getBoolean("disable", false); enabled = prefs.getBoolean(Const.Key.DISABLE, false);
if (enabled) { if (enabled) {
Utils.createFile(MagiskManager.MAGISK_DISABLE_FILE); Utils.createFile(Const.MAGISK_DISABLE_FILE);
} else { } else {
Utils.removeItem(MagiskManager.MAGISK_DISABLE_FILE); Utils.removeItem(Const.MAGISK_DISABLE_FILE);
} }
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
break; break;
case "magiskhide": case Const.Key.MAGISKHIDE:
enabled = prefs.getBoolean("magiskhide", false); enabled = prefs.getBoolean(Const.Key.MAGISKHIDE, false);
if (enabled) { if (enabled) {
Shell.su_raw("magiskhide --enable"); Shell.su_raw("magiskhide --enable");
} else { } else {
Shell.su_raw("magiskhide --disable"); Shell.su_raw("magiskhide --disable");
} }
break; break;
case "hosts": case Const.Key.HOSTS:
enabled = prefs.getBoolean("hosts", false); enabled = prefs.getBoolean(Const.Key.HOSTS, false);
if (enabled) { if (enabled) {
Shell.su_raw( Shell.su_raw(
"cp -af /system/etc/hosts " + MagiskManager.MAGISK_HOST_FILE, "cp -af /system/etc/hosts " + Const.MAGISK_HOST_FILE,
"mount -o bind " + MagiskManager.MAGISK_HOST_FILE + " /system/etc/hosts"); "mount -o bind " + Const.MAGISK_HOST_FILE + " /system/etc/hosts");
} else { } else {
Shell.su_raw( Shell.su_raw(
"umount -l /system/etc/hosts", "umount -l /system/etc/hosts",
"rm -f " + MagiskManager.MAGISK_HOST_FILE); "rm -f " + Const.MAGISK_HOST_FILE);
} }
break; break;
case "su_access": case Const.Key.ROOT_ACCESS:
mm.suDB.setSettings(SuDatabaseHelper.ROOT_ACCESS, Utils.getPrefsInt(prefs, "su_access")); mm.suDB.setSettings(Const.Key.ROOT_ACCESS, Utils.getPrefsInt(prefs, Const.Key.ROOT_ACCESS));
break; break;
case "multiuser_mode": case Const.Key.SU_MULTIUSER_MODE:
mm.suDB.setSettings(SuDatabaseHelper.MULTIUSER_MODE, Utils.getPrefsInt(prefs, "multiuser_mode")); mm.suDB.setSettings(Const.Key.SU_MULTIUSER_MODE, Utils.getPrefsInt(prefs, Const.Key.SU_MULTIUSER_MODE));
break; break;
case "mnt_ns": case Const.Key.SU_MNT_NS:
mm.suDB.setSettings(SuDatabaseHelper.MNT_NS, Utils.getPrefsInt(prefs, "mnt_ns")); mm.suDB.setSettings(Const.Key.SU_MNT_NS, Utils.getPrefsInt(prefs, Const.Key.SU_MNT_NS));
break; break;
case "locale": case Const.Key.LOCALE:
mm.setLocale(); mm.setLocale();
mm.reloadActivity.publish(false); mm.reloadActivity.publish(false);
break; break;
case "update_channel": case Const.Key.UPDATE_CHANNEL:
mm.updateChannel = Utils.getPrefsInt(prefs, "update_channel"); mm.updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL);
new CheckUpdates(true).exec(); new CheckUpdates(true).exec();
break; break;
} }
@ -259,7 +258,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
suNotification.setSummary(getResources() suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)[mm.suNotificationType]); .getStringArray(R.array.su_notification)[mm.suNotificationType]);
requestTimeout.setSummary( requestTimeout.setSummary(
getString(R.string.request_timeout_summary, prefs.getString("su_request_timeout", "10"))); getString(R.string.request_timeout_summary, prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10")));
multiuserMode.setSummary(getResources() multiuserMode.setSummary(getResources()
.getStringArray(R.array.multiuser_summary)[mm.multiuserMode]); .getStringArray(R.array.multiuser_summary)[mm.multiuserMode]);
namespaceMode.setSummary(getResources() namespaceMode.setSummary(getResources()
@ -268,7 +267,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
@Override @Override
public void onTopicPublished(Topic topic, Object result) { public void onTopicPublished(Topic topic, Object result) {
setLocalePreference((ListPreference) findPreference("locale")); setLocalePreference((ListPreference) findPreference(Const.Key.LOCALE));
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.utils.Const;
public class SplashActivity extends Activity { public class SplashActivity extends Activity {
@ -14,9 +15,9 @@ public class SplashActivity extends Activity {
getMagiskManager().startup(); getMagiskManager().startup();
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION); String section = getIntent().getStringExtra(Const.Key.OPEN_SECTION);
if (section != null) { if (section != null) {
intent.putExtra(MagiskManager.INTENT_SECTION, section); intent.putExtra(Const.Key.OPEN_SECTION, section);
} }
startActivity(intent); startActivity(intent);
finish(); finish();

View File

@ -17,12 +17,12 @@ import android.widget.TextView;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -32,17 +32,6 @@ import butterknife.ButterKnife;
public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.ViewHolder> { public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.ViewHolder> {
public static final List<String> BLACKLIST = Arrays.asList(
"android",
"com.topjohnwu.magisk",
"com.google.android.gms"
);
private static final List<String> SNLIST = Arrays.asList(
"com.google.android.apps.walletnfcrel",
"com.nianticlabs.pokemongo"
);
private List<ApplicationInfo> mOriginalList, mList; private List<ApplicationInfo> mOriginalList, mList;
private List<String> mHideList; private List<String> mHideList;
private PackageManager pm; private PackageManager pm;
@ -80,7 +69,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
holder.itemView.setOnClickListener(null); holder.itemView.setOnClickListener(null);
holder.checkBox.setOnCheckedChangeListener(null); holder.checkBox.setOnCheckedChangeListener(null);
if (SNLIST.contains(info.packageName)) { if (Const.SN_DEFAULTLIST.contains(info.packageName)) {
holder.checkBox.setChecked(true); holder.checkBox.setChecked(true);
holder.checkBox.setEnabled(false); holder.checkBox.setEnabled(false);
holder.itemView.setOnClickListener(v -> holder.itemView.setOnClickListener(v ->
@ -160,7 +149,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
mOriginalList = pm.getInstalledApplications(0); mOriginalList = pm.getInstalledApplications(0);
for (Iterator<ApplicationInfo> i = mOriginalList.iterator(); i.hasNext(); ) { for (Iterator<ApplicationInfo> i = mOriginalList.iterator(); i.hasNext(); ) {
ApplicationInfo info = i.next(); ApplicationInfo info = i.next();
if (ApplicationAdapter.BLACKLIST.contains(info.packageName) || !info.enabled) { if (Const.SN_BLACKLIST.contains(info.packageName) || !info.enabled) {
i.remove(); i.remove();
} }
} }

View File

@ -4,6 +4,7 @@ import android.app.Activity;
import com.topjohnwu.crypto.ByteArrayStream; import com.topjohnwu.crypto.ByteArrayStream;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -18,11 +19,6 @@ import dalvik.system.DexClassLoader;
public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> { public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
public static final int SNET_VER = 3;
private static final String SNET_URL = "https://www.dropbox.com/s/jg2yhcrn3l9fckc/snet.apk?dl=1";
private static final String PKG = "com.topjohnwu.snet";
private File dexPath; private File dexPath;
private DexClassLoader loader; private DexClassLoader loader;
@ -34,18 +30,18 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
MagiskManager mm = MagiskManager.get(); MagiskManager mm = MagiskManager.get();
if (mm.snet_version != CheckSafetyNet.SNET_VER) { if (mm.snet_version != Const.Value.SNET_VER) {
Shell.sh("rm -rf " + dexPath.getParent()); Shell.sh("rm -rf " + dexPath.getParent());
} }
mm.snet_version = CheckSafetyNet.SNET_VER; mm.snet_version = Const.Value.SNET_VER;
mm.prefs.edit().putInt("snet_version", CheckSafetyNet.SNET_VER).apply(); mm.prefs.edit().putInt(Const.Key.SNET_VER, Const.Value.SNET_VER).apply();
} }
@Override @Override
protected Exception doInBackground(Void... voids) { protected Exception doInBackground(Void... voids) {
try { try {
if (!dexPath.exists()) { if (!dexPath.exists()) {
HttpURLConnection conn = WebService.request(SNET_URL, null); HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
ByteArrayStream bas = new ByteArrayStream(); ByteArrayStream bas = new ByteArrayStream();
bas.readFrom(conn.getInputStream()); bas.readFrom(conn.getInputStream());
conn.disconnect(); conn.disconnect();
@ -68,8 +64,8 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
MagiskManager mm = MagiskManager.get(); MagiskManager mm = MagiskManager.get();
try { try {
if (err != null) throw err; if (err != null) throw err;
Class<?> helperClazz = loader.loadClass(PKG + ".SafetyNetHelper"); Class<?> helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
Class<?> callbackClazz = loader.loadClass(PKG + ".SafetyNetCallback"); Class<?> callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback");
Object helper = helperClazz.getConstructors()[0].newInstance( Object helper = helperClazz.getConstructors()[0].newInstance(
getActivity(), dexPath.getPath(), Proxy.newProxyInstance( getActivity(), dexPath.getPath(), Proxy.newProxyInstance(
loader, new Class[] { callbackClazz }, (proxy, method, args) -> { loader, new Class[] { callbackClazz }, (proxy, method, args) -> {

View File

@ -2,6 +2,7 @@ package com.topjohnwu.magisk.asyncs;
import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ShowUI; import com.topjohnwu.magisk.utils.ShowUI;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -10,12 +11,6 @@ import org.json.JSONObject;
public class CheckUpdates extends ParallelTask<Void, Void, Void> { public class CheckUpdates extends ParallelTask<Void, Void, Void> {
public static final int STABLE_CHANNEL = 0;
public static final int BETA_CHANNEL = 1;
private static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
private static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
private boolean showNotification; private boolean showNotification;
public CheckUpdates() { public CheckUpdates() {
@ -31,11 +26,11 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
MagiskManager mm = MagiskManager.get(); MagiskManager mm = MagiskManager.get();
String jsonStr; String jsonStr;
switch (mm.updateChannel) { switch (mm.updateChannel) {
case STABLE_CHANNEL: case Const.Value.STABLE_CHANNEL:
jsonStr = WebService.getString(STABLE_URL); jsonStr = WebService.getString(Const.Url.STABLE_URL);
break; break;
case BETA_CHANNEL: case Const.Value.BETA_CHANNEL:
jsonStr = WebService.getString(BETA_URL); jsonStr = WebService.getString(Const.Url.BETA_URL);
break; break;
default: default:
jsonStr = null; jsonStr = null;

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.os.Build; import android.os.Build;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -16,9 +17,6 @@ import java.net.HttpURLConnection;
public class DownloadBusybox extends ParallelTask<Void, Void, Void> { public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
private static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.2/busybox-arm";
private static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.2/busybox-x86";
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
Context context = MagiskManager.get(); Context context = MagiskManager.get();
@ -28,8 +26,8 @@ public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
HttpURLConnection conn = WebService.request( HttpURLConnection conn = WebService.request(
Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ? Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ?
BUSYBOX_X86 : Const.Url.BUSYBOX_X86 :
BUSYBOX_ARM, Const.Url.BUSYBOX_ARM,
null null
); );
if (conn == null) throw new IOException(); if (conn == null) throw new IOException();
@ -41,11 +39,11 @@ public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
} }
if (busybox.exists()) { if (busybox.exists()) {
Shell.su( Shell.su(
"rm -rf " + MagiskManager.BUSYBOXPATH, "rm -rf " + Const.BUSYBOXPATH,
"mkdir -p " + MagiskManager.BUSYBOXPATH, "mkdir -p " + Const.BUSYBOXPATH,
"cp " + busybox + " " + MagiskManager.BUSYBOXPATH, "cp " + busybox + " " + Const.BUSYBOXPATH,
"chmod -R 755 " + MagiskManager.BUSYBOXPATH, "chmod -R 755 " + Const.BUSYBOXPATH,
MagiskManager.BUSYBOXPATH + "/busybox --install -s " + MagiskManager.BUSYBOXPATH Const.BUSYBOXPATH + "/busybox --install -s " + Const.BUSYBOXPATH
); );
busybox.delete(); busybox.delete();
} }

View File

@ -7,6 +7,7 @@ import android.text.TextUtils;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.AdaptiveList; import com.topjohnwu.magisk.container.AdaptiveList;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils; import com.topjohnwu.magisk.utils.ZipUtils;
@ -93,7 +94,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
MagiskManager mm = MagiskManager.get(); MagiskManager mm = MagiskManager.get();
Shell.su_raw( Shell.su_raw(
"rm -rf " + mCachedFile.getParent(), "rm -rf " + mCachedFile.getParent(),
"rm -rf " + MagiskManager.TMP_FOLDER_PATH "rm -rf " + Const.TMP_FOLDER_PATH
); );
switch (result) { switch (result) {
case -1: case -1:

View File

@ -6,7 +6,7 @@ import android.widget.Toast;
import com.topjohnwu.crypto.JarMap; import com.topjohnwu.crypto.JarMap;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.database.SuDatabaseHelper; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils; import com.topjohnwu.magisk.utils.ZipUtils;
@ -20,8 +20,6 @@ import java.util.jar.JarEntry;
public class HideManager extends ParallelTask<Void, Void, Boolean> { public class HideManager extends ParallelTask<Void, Void, Boolean> {
private static final String ANDROID_MANIFEST = "AndroidManifest.xml";
private String genPackageName(String prefix, int length) { private String genPackageName(String prefix, int length) {
StringBuilder builder = new StringBuilder(length); StringBuilder builder = new StringBuilder(length);
builder.append(prefix); builder.append(prefix);
@ -101,17 +99,17 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
// Generate a new unhide app with random package name // Generate a new unhide app with random package name
File repack = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", "repack.apk"); File repack = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", "repack.apk");
repack.getParentFile().mkdirs(); repack.getParentFile().mkdirs();
String pkg = genPackageName("com.", MagiskManager.ORIG_PKG_NAME.length()); String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length());
try { try {
// Read whole APK into memory // Read whole APK into memory
JarMap apk = new JarMap(new FileInputStream(mm.getPackageCodePath())); JarMap apk = new JarMap(new FileInputStream(mm.getPackageCodePath()));
JarEntry je = new JarEntry(ANDROID_MANIFEST); JarEntry je = new JarEntry(Const.ANDROID_MANIFEST);
byte xml[] = apk.getRawData(je); byte xml[] = apk.getRawData(je);
if (!findAndPatch(xml, MagiskManager.ORIG_PKG_NAME, pkg)) if (!findAndPatch(xml, Const.ORIG_PKG_NAME, pkg))
return false; return false;
if (!findAndPatch(xml, MagiskManager.ORIG_PKG_NAME + ".provider", pkg + ".provider")) if (!findAndPatch(xml, Const.ORIG_PKG_NAME + ".provider", pkg + ".provider"))
return false; return false;
// Write in changes // Write in changes
@ -133,7 +131,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
if (!Utils.isValidShellResponse(ret) || !Boolean.parseBoolean(ret.get(0))) if (!Utils.isValidShellResponse(ret) || !Boolean.parseBoolean(ret.get(0)))
return false; return false;
mm.suDB.setStrings(SuDatabaseHelper.REQUESTER, pkg); mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
Shell.su_raw(String.format(Locale.US, "pm uninstall --user %d %s", mm.userId, mm.getPackageName())); Shell.su_raw(String.format(Locale.US, "pm uninstall --user %d %s", mm.userId, mm.getPackageName()));
return true; return true;

View File

@ -11,6 +11,7 @@ import com.topjohnwu.crypto.SignBoot;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.AdaptiveList; import com.topjohnwu.magisk.container.AdaptiveList;
import com.topjohnwu.magisk.container.TarEntry; import com.topjohnwu.magisk.container.TarEntry;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils; import com.topjohnwu.magisk.utils.ZipUtils;
@ -204,8 +205,8 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
try ( try (
InputStream in = new FileInputStream(patched_boot); InputStream in = new FileInputStream(patched_boot);
OutputStream out = new BufferedOutputStream(new FileOutputStream(signed)); OutputStream out = new BufferedOutputStream(new FileOutputStream(signed));
InputStream keyIn = assets.open(ZipUtils.PRIVATE_KEY_NAME); InputStream keyIn = assets.open(Const.PRIVATE_KEY_NAME);
InputStream certIn = assets.open(ZipUtils.PUBLIC_KEY_NAME) InputStream certIn = assets.open(Const.PUBLIC_KEY_NAME)
) { ) {
SignBoot.doSignature("/boot", in, out, keyIn, certIn); SignBoot.doSignature("/boot", in, out, keyIn, certIn);
} }

View File

@ -3,6 +3,7 @@ package com.topjohnwu.magisk.asyncs;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.container.ValueSortedMap; import com.topjohnwu.magisk.container.ValueSortedMap;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import java.util.List; import java.util.List;
@ -10,7 +11,7 @@ import java.util.List;
public class LoadModules extends ParallelTask<Void, Void, Void> { public class LoadModules extends ParallelTask<Void, Void, Void> {
private List<String> getModList() { private List<String> getModList() {
String command = "ls -d " + MagiskManager.MAGISK_PATH + "/* | grep -v lost+found"; String command = "ls -d " + Const.MAGISK_PATH + "/* | grep -v lost+found";
return Shell.su(command); return Shell.su(command);
} }

View File

@ -13,6 +13,7 @@ import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.InputStreamWrapper; import com.topjohnwu.magisk.container.InputStreamWrapper;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -165,8 +166,8 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
Uri uri = Uri.fromFile(mFile); Uri uri = Uri.fromFile(mFile);
if (result) { if (result) {
if (Shell.rootAccess() && mInstall) { if (Shell.rootAccess() && mInstall) {
Intent intent = new Intent(getActivity(), FlashActivity.class); Intent intent = new Intent(activity, FlashActivity.class);
intent.setData(uri).putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_ZIP); intent.setData(uri).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
activity.startActivity(intent); activity.startActivity(intent);
} else { } else {
Utils.showUriSnack(activity, uri); Utils.showUriSnack(activity, uri);

View File

@ -7,6 +7,7 @@ import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.ReposFragment; import com.topjohnwu.magisk.ReposFragment;
import com.topjohnwu.magisk.container.Repo; import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -26,12 +27,6 @@ import java.util.Map;
public class UpdateRepos extends ParallelTask<Void, Void, Void> { public class UpdateRepos extends ParallelTask<Void, Void, Void> {
private static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
public static final String ETAG_KEY = "ETag";
private static final String IF_NONE_MATCH = "If-None-Match";
private static final String LINK_KEY = "Link";
private static final int CHECK_ETAG = 0; private static final int CHECK_ETAG = 0;
private static final int LOAD_NEXT = 1; private static final int LOAD_NEXT = 1;
private static final int LOAD_PREV = 2; private static final int LOAD_PREV = 2;
@ -52,7 +47,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
File old = new File(mm.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml"); File old = new File(mm.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml");
if (old.exists() || prefs.getString("repomap", null) != null) { if (old.exists() || prefs.getString("repomap", null) != null) {
old.delete(); old.delete();
prefs.edit().remove("version").remove("repomap").remove(ETAG_KEY).apply(); prefs.edit().remove("version").remove("repomap").remove(Const.Key.ETAG_KEY).apply();
repoDB.clearRepo(); repoDB.clearRepo();
} }
forceUpdate = force; forceUpdate = force;
@ -111,8 +106,8 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
if (mode == CHECK_ETAG && page < etags.size()) { if (mode == CHECK_ETAG && page < etags.size()) {
etag = etags.get(page); etag = etags.get(page);
} }
header.put(IF_NONE_MATCH, etag); header.put(Const.Key.IF_NONE_MATCH, etag);
String url = String.format(Locale.US, REPO_URL, page + 1); String url = String.format(Locale.US, Const.Url.REPO_URL, page + 1);
HttpURLConnection conn = WebService.request(url, header); HttpURLConnection conn = WebService.request(url, header);
try { try {
@ -129,11 +124,11 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
} }
// Update ETAG // Update ETAG
etag = header.get(ETAG_KEY); etag = header.get(Const.Key.ETAG_KEY);
etag = etag.substring(etag.indexOf('\"'), etag.lastIndexOf('\"') + 1); etag = etag.substring(etag.indexOf('\"'), etag.lastIndexOf('\"') + 1);
newEtags.add(etag); newEtags.add(etag);
String links = header.get(LINK_KEY); String links = header.get(Const.Key.LINK_KEY);
if (links != null) { if (links != null) {
for (String s : links.split(", ")) { for (String s : links.split(", ")) {
if (mode != LOAD_PREV && s.contains("next")) { if (mode != LOAD_PREV && s.contains("next")) {
@ -167,7 +162,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
etags = new ArrayList<>(Arrays.asList(prefs.getString(ETAG_KEY, "").split(","))); etags = new ArrayList<>(Arrays.asList(prefs.getString(Const.Key.ETAG_KEY, "").split(",")));
cached = repoDB.getRepoIDList(); cached = repoDB.getRepoIDList();
if (!loadPage(0, CHECK_ETAG)) { if (!loadPage(0, CHECK_ETAG)) {
@ -204,7 +199,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
if (i != 0) etagBuilder.append(","); if (i != 0) etagBuilder.append(",");
etagBuilder.append(newEtags.get(i)); etagBuilder.append(newEtags.get(i));
} }
prefs.edit().putString(ETAG_KEY, etagBuilder.toString()).apply(); prefs.edit().putString(Const.Key.ETAG_KEY, etagBuilder.toString()).apply();
return null; return null;
} }

View File

@ -3,17 +3,13 @@ package com.topjohnwu.magisk.container;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
import java.util.Date; import java.util.Date;
public class Repo extends BaseModule { public class Repo extends BaseModule {
public static final int MIN_TEMPLATE_VER = 4;
private static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
private static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";
private String repoName; private String repoName;
private Date mLastUpdate; private Date mLastUpdate;
@ -44,7 +40,7 @@ public class Repo extends BaseModule {
if (getVersionCode() < 0) { if (getVersionCode() < 0) {
throw new IllegalRepoException("Repo [" + repoName + "] does not contain versionCode"); throw new IllegalRepoException("Repo [" + repoName + "] does not contain versionCode");
} }
if (getTemplateVersion() < MIN_TEMPLATE_VER) { if (getTemplateVersion() < Const.Value.MIN_TEMPLATE_VER) {
throw new IllegalRepoException("Repo [" + repoName + "] is outdated"); throw new IllegalRepoException("Repo [" + repoName + "] is outdated");
} }
} }
@ -70,15 +66,15 @@ public class Repo extends BaseModule {
} }
public String getZipUrl() { public String getZipUrl() {
return String.format(ZIP_URL, repoName); return String.format(Const.Url.ZIP_URL, repoName);
} }
public String getManifestUrl() { public String getManifestUrl() {
return String.format(FILE_URL, repoName, "module.prop"); return String.format(Const.Url.FILE_URL, repoName, "module.prop");
} }
public String getDetailUrl() { public String getDetailUrl() {
return String.format(FILE_URL, repoName, "README.md"); return String.format(Const.Url.FILE_URL, repoName, "README.md");
} }
public Date getLastUpdate() { public Date getLastUpdate() {

View File

@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.Repo; import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.util.LinkedList; import java.util.LinkedList;
@ -27,7 +28,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
// Clear bad repos // Clear bad repos
mDb.delete(TABLE_NAME, "template<?", mDb.delete(TABLE_NAME, "template<?",
new String[] { String.valueOf(Repo.MIN_TEMPLATE_VER) }); new String[] { String.valueOf(Const.Value.MIN_TEMPLATE_VER) });
} }
@Override @Override

View File

@ -25,25 +25,8 @@ import java.util.List;
public class SuDatabaseHelper extends SQLiteOpenHelper { public class SuDatabaseHelper extends SQLiteOpenHelper {
public static final String ROOT_ACCESS = "root_access";
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 String MULTIUSER_MODE = "multiuser_mode";
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 String MNT_NS = "mnt_ns";
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 String REQUESTER = "requester";
public static final String DB_NAME = "su.db"; public static final String DB_NAME = "su.db";
private static final int DATABASE_VER = 5; private static final int DATABASE_VER = 5;
private static final String POLICY_TABLE = "policies"; private static final String POLICY_TABLE = "policies";
private static final String LOG_TABLE = "logs"; private static final String LOG_TABLE = "logs";

View File

@ -7,7 +7,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File; import java.io.File;
@ -35,8 +35,8 @@ public class ManagerUpdate extends BroadcastReceiver {
} }
} }
}, },
intent.getStringExtra(MagiskManager.INTENT_LINK), intent.getStringExtra(Const.Key.INTENT_SET_LINK),
Utils.getLegalFilename("MagiskManager-v" + Utils.getLegalFilename("MagiskManager-v" +
intent.getStringExtra(MagiskManager.INTENT_VERSION) + ".apk")); intent.getStringExtra(Const.Key.INTENT_SET_VERSION) + ".apk"));
} }
} }

View File

@ -5,13 +5,11 @@ import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Const;
public class OnBootIntentService extends IntentService { public class OnBootIntentService extends IntentService {
private static final int ONBOOT_NOTIFICATION_ID = 3;
public OnBootIntentService() { public OnBootIntentService() {
super("OnBootIntentService"); super("OnBootIntentService");
} }
@ -21,11 +19,11 @@ public class OnBootIntentService extends IntentService {
super.onCreate(); super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, MagiskManager.NOTIFICATION_CHANNEL); new NotificationCompat.Builder(this, Const.ID.NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk) builder.setSmallIcon(R.drawable.ic_magisk)
.setContentTitle("onBoot") .setContentTitle("onBoot")
.setContentText("Running onBoot operations..."); .setContentText("Running onBoot operations...");
startForeground(ONBOOT_NOTIFICATION_ID, builder.build()); startForeground(Const.ID.ONBOOT_NOTIFICATION_ID, builder.build());
} }
} }

View File

@ -11,32 +11,27 @@ import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.container.Policy;
import com.topjohnwu.magisk.container.SuLogEntry; import com.topjohnwu.magisk.container.SuLogEntry;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils;
import java.util.Date; import java.util.Date;
public class SuReceiver extends BroadcastReceiver { public class SuReceiver extends BroadcastReceiver {
public static final int NO_NOTIFICATION = 0;
public static final int TOAST = 1;
private static final int NOTIFY_NORMAL_LOG = 0;
private static final int NOTIFY_USER_TOASTS = 1;
private static final int NOTIFY_USER_TO_OWNER = 2;
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
int fromUid, toUid, pid, mode; int fromUid, toUid, pid, mode;
String command, action; String command, action;
Policy policy; Policy policy;
MagiskManager magiskManager = (MagiskManager) context.getApplicationContext(); MagiskManager mm = Utils.getMagiskManager(context);
if (intent == null) return; if (intent == null) return;
mode = intent.getIntExtra("mode", -1); mode = intent.getIntExtra("mode", -1);
if (mode < 0) return; if (mode < 0) return;
if (mode == NOTIFY_USER_TO_OWNER) { if (mode == Const.Value.NOTIFY_USER_TO_OWNER) {
MagiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG); MagiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
return; return;
} }
@ -48,7 +43,7 @@ public class SuReceiver extends BroadcastReceiver {
action = intent.getStringExtra("action"); action = intent.getStringExtra("action");
if (action == null) return; if (action == null) return;
policy = magiskManager.suDB.getPolicy(fromUid); policy = mm.suDB.getPolicy(fromUid);
if (policy == null) { if (policy == null) {
try { try {
policy = new Policy(fromUid, context.getPackageManager()); policy = new Policy(fromUid, context.getPackageManager());
@ -74,11 +69,11 @@ public class SuReceiver extends BroadcastReceiver {
return; return;
} }
if (policy.notification && magiskManager.suNotificationType == TOAST) { if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
magiskManager.toast(message, Toast.LENGTH_SHORT); MagiskManager.toast(message, Toast.LENGTH_SHORT);
} }
if (mode == NOTIFY_NORMAL_LOG && policy.logging) { if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
toUid = intent.getIntExtra("to.uid", -1); toUid = intent.getIntExtra("to.uid", -1);
if (toUid < 0) return; if (toUid < 0) return;
pid = intent.getIntExtra("pid", -1); pid = intent.getIntExtra("pid", -1);
@ -89,7 +84,7 @@ public class SuReceiver extends BroadcastReceiver {
log.fromPid = pid; log.fromPid = pid;
log.command = command; log.command = command;
log.date = new Date(); log.date = new Date();
magiskManager.suDB.addLog(log); mm.suDB.addLog(log);
} }
} }
} }

View File

@ -22,6 +22,7 @@ import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.container.Policy;
import com.topjohnwu.magisk.utils.Const;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -31,12 +32,6 @@ import butterknife.ButterKnife;
public class SuRequestActivity extends Activity { public class SuRequestActivity extends Activity {
public static final int PROMPT = 0;
public static final int AUTO_DENY = 1;
public static final int AUTO_ALLOW = 2;
private static final int[] timeoutList = {0, -1, 10, 20, 30, 60};
@BindView(R.id.su_popup) LinearLayout suPopup; @BindView(R.id.su_popup) LinearLayout suPopup;
@BindView(R.id.timeout) Spinner timeout; @BindView(R.id.timeout) Spinner timeout;
@BindView(R.id.app_icon) ImageView appIcon; @BindView(R.id.app_icon) ImageView appIcon;
@ -86,13 +81,13 @@ public class SuRequestActivity extends Activity {
private void showRequest() { private void showRequest() {
switch (mm.suResponseType) { switch (mm.suResponseType) {
case AUTO_DENY: case Const.Value.SU_AUTO_DENY:
handleAction(Policy.DENY, 0); handleAction(Policy.DENY, 0);
return; return;
case AUTO_ALLOW: case Const.Value.SU_AUTO_ALLOW:
handleAction(Policy.ALLOW, 0); handleAction(Policy.ALLOW, 0);
return; return;
case PROMPT: case Const.Value.SU_PROMPT:
default: default:
} }
@ -169,7 +164,7 @@ public class SuRequestActivity extends Activity {
} }
void handleAction(int action) { void handleAction(int action) {
handleAction(action, timeoutList[timeout.getSelectedItemPosition()]); handleAction(action, Const.Value.timeoutList[timeout.getSelectedItemPosition()]);
} }
void handleAction(int action, int time) { void handleAction(int action, int time) {

View File

@ -31,8 +31,8 @@ public class BootSigner {
} else { } else {
/* Use internal test keys */ /* Use internal test keys */
JarFile apk = new JarFile(System.getProperty("java.class.path")); JarFile apk = new JarFile(System.getProperty("java.class.path"));
JarEntry keyEntry = apk.getJarEntry("assets/" + ZipUtils.PRIVATE_KEY_NAME); JarEntry keyEntry = apk.getJarEntry("assets/" + Const.PRIVATE_KEY_NAME);
JarEntry sigEntry = apk.getJarEntry("assets/" + ZipUtils.PUBLIC_KEY_NAME); JarEntry sigEntry = apk.getJarEntry("assets/" + Const.PUBLIC_KEY_NAME);
keyIn = apk.getInputStream(keyEntry); keyIn = apk.getInputStream(keyEntry);
certIn = apk.getInputStream(sigEntry); certIn = apk.getInputStream(sigEntry);

View File

@ -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;
}
}

View File

@ -6,11 +6,10 @@ import java.util.Locale;
public class Logger { public class Logger {
public static final String DEBUG_TAG = "MagiskManager";
private static final boolean SHELL_LOGGING = false; private static final boolean SHELL_LOGGING = false;
public static void debug(String line) { 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) { public static void debug(String fmt, Object... args) {
@ -18,7 +17,7 @@ public class Logger {
} }
public static void error(String line) { 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) { public static void error(String fmt, Object... args) {
@ -27,7 +26,7 @@ public class Logger {
public static void shell(boolean in, String line) { public static void shell(boolean in, String line) {
if (SHELL_LOGGING) { if (SHELL_LOGGING) {
Log.d(DEBUG_TAG, (in ? "SHELLIN : " : "SHELLOUT: ") + line); Log.d(Const.DEBUG_TAG, (in ? "SHELLIN : " : "SHELLOUT: ") + line);
} }
} }

View File

@ -29,49 +29,45 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ShowUI { 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() { public static void showMagiskUpdateNotification() {
MagiskManager mm = MagiskManager.get(); 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) builder.setSmallIcon(R.drawable.ic_magisk)
.setContentTitle(mm.getString(R.string.magisk_update_title)) .setContentTitle(mm.getString(R.string.magisk_update_title))
.setContentText(mm.getString(R.string.magisk_update_available, mm.remoteMagiskVersionString)) .setContentText(mm.getString(R.string.magisk_update_available, mm.remoteMagiskVersionString))
.setVibrate(new long[]{0, 100, 100, 100}) .setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true); .setAutoCancel(true);
Intent intent = new Intent(mm, SplashActivity.class); 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); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mm);
stackBuilder.addParentStack(SplashActivity.class); stackBuilder.addParentStack(SplashActivity.class);
stackBuilder.addNextIntent(intent); 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); PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent); builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE); (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() { public static void showManagerUpdateNotification() {
MagiskManager mm = MagiskManager.get(); 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) builder.setSmallIcon(R.drawable.ic_magisk)
.setContentTitle(mm.getString(R.string.manager_update_title)) .setContentTitle(mm.getString(R.string.manager_update_title))
.setContentText(mm.getString(R.string.manager_download_install)) .setContentText(mm.getString(R.string.manager_download_install))
.setVibrate(new long[]{0, 100, 100, 100}) .setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true); .setAutoCancel(true);
Intent intent = new Intent(mm, ManagerUpdate.class); Intent intent = new Intent(mm, ManagerUpdate.class);
intent.putExtra(MagiskManager.INTENT_LINK, mm.managerLink); intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
intent.putExtra(MagiskManager.INTENT_VERSION, mm.remoteManagerVersionString); intent.putExtra(Const.Key.INTENT_SET_VERSION, mm.remoteManagerVersionString);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, 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); builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE); (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) { 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); MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*"); intent.setType("*/*");
fragment.startActivityForResult(intent, SELECT_BOOT_IMG, fragment.startActivityForResult(intent, Const.ID.SELECT_BOOT,
(requestCode, resultCode, data) -> { (requestCode, resultCode, data) -> {
if (requestCode == SELECT_BOOT_IMG if (requestCode == Const.ID.SELECT_BOOT
&& resultCode == Activity.RESULT_OK && data != null) { && resultCode == Activity.RESULT_OK && data != null) {
Utils.dlAndReceive( Utils.dlAndReceive(
fragment.getActivity(), fragment.getActivity(),
@ -121,10 +117,10 @@ public class ShowUI {
Intent intent = new Intent(mm, FlashActivity.class); Intent intent = new Intent(mm, FlashActivity.class);
intent.setData(uri) intent.setData(uri)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(FlashActivity.SET_BOOT, data.getData()) .putExtra(Const.Key.FLASH_SET_BOOT, data.getData())
.putExtra(FlashActivity.SET_ENC, enc) .putExtra(Const.Key.FLASH_SET_ENC, enc)
.putExtra(FlashActivity.SET_VERITY, verity) .putExtra(Const.Key.FLASH_SET_VERITY, verity)
.putExtra(FlashActivity.SET_ACTION, FlashActivity.PATCH_BOOT); .putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT);
mm.startActivity(intent); mm.startActivity(intent);
} }
}, },
@ -152,10 +148,10 @@ public class ShowUI {
Intent intent = new Intent(mm, FlashActivity.class); Intent intent = new Intent(mm, FlashActivity.class);
intent.setData(uri) intent.setData(uri)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(FlashActivity.SET_BOOT, boot) .putExtra(Const.Key.FLASH_SET_BOOT, boot)
.putExtra(FlashActivity.SET_ENC, enc) .putExtra(Const.Key.FLASH_SET_ENC, enc)
.putExtra(FlashActivity.SET_VERITY, verity) .putExtra(Const.Key.FLASH_SET_VERITY, verity)
.putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_MAGISK); .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
mm.startActivity(intent); mm.startActivity(intent);
} }
}; };
@ -182,10 +178,10 @@ public class ShowUI {
Intent intent = new Intent(mm, FlashActivity.class); Intent intent = new Intent(mm, FlashActivity.class);
intent.setData(uri) intent.setData(uri)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(FlashActivity.SET_BOOT, boot) .putExtra(Const.Key.FLASH_SET_BOOT, boot)
.putExtra(FlashActivity.SET_ENC, enc) .putExtra(Const.Key.FLASH_SET_ENC, enc)
.putExtra(FlashActivity.SET_VERITY, verity) .putExtra(Const.Key.FLASH_SET_VERITY, verity)
.putExtra(FlashActivity.SET_ACTION, FlashActivity.FLASH_MAGISK); .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
mm.startActivity(intent); mm.startActivity(intent);
} }
}; };
@ -221,8 +217,8 @@ public class ShowUI {
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.install, (d, i) -> { .setPositiveButton(R.string.install, (d, i) -> {
Intent intent = new Intent(mm, ManagerUpdate.class); Intent intent = new Intent(mm, ManagerUpdate.class);
intent.putExtra(MagiskManager.INTENT_LINK, mm.managerLink); intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
intent.putExtra(MagiskManager.INTENT_VERSION, mm.remoteManagerVersionString); intent.putExtra(Const.Key.INTENT_SET_VERSION, mm.remoteManagerVersionString);
mm.sendBroadcast(intent); mm.sendBroadcast(intent);
}) })
.setNegativeButton(R.string.no_thanks, null) .setNegativeButton(R.string.no_thanks, null)
@ -236,8 +232,8 @@ public class ShowUI {
.setMessage(R.string.uninstall_magisk_msg) .setMessage(R.string.uninstall_magisk_msg)
.setPositiveButton(R.string.complete_uninstall, (d, i) -> { .setPositiveButton(R.string.complete_uninstall, (d, i) -> {
try { try {
InputStream in = mm.getAssets().open(UNINSTALLER); InputStream in = mm.getAssets().open(Const.UNINSTALLER);
File uninstaller = new File(mm.getCacheDir(), UNINSTALLER); File uninstaller = new File(mm.getCacheDir(), Const.UNINSTALLER);
FileOutputStream out = new FileOutputStream(uninstaller); FileOutputStream out = new FileOutputStream(uninstaller);
byte[] bytes = new byte[1024]; byte[] bytes = new byte[1024];
int read; int read;
@ -246,8 +242,8 @@ public class ShowUI {
} }
in.close(); in.close();
out.close(); out.close();
in = mm.getAssets().open(Utils.UTIL_FUNCTIONS); in = mm.getAssets().open(Const.UTIL_FUNCTIONS);
File utils = new File(mm.getCacheDir(), Utils.UTIL_FUNCTIONS); File utils = new File(mm.getCacheDir(), Const.UTIL_FUNCTIONS);
out = new FileOutputStream(utils); out = new FileOutputStream(utils);
while ((read = in.read(bytes)) != -1) { while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read); out.write(bytes, 0, read);
@ -255,8 +251,8 @@ public class ShowUI {
in.close(); in.close();
out.close(); out.close();
Shell.su( Shell.su(
"cat " + uninstaller + " > /cache/" + UNINSTALLER, "cat " + uninstaller + " > /cache/" + Const.UNINSTALLER,
"cat " + utils + " > /data/magisk/" + Utils.UTIL_FUNCTIONS "cat " + utils + " > /data/magisk/" + Const.UTIL_FUNCTIONS
); );
MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG); MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
Shell.su_raw( Shell.su_raw(

View File

@ -39,7 +39,6 @@ import java.util.Locale;
public class Utils { public class Utils {
public static final String UTIL_FUNCTIONS= "util_functions.sh";
public static boolean isDownloading = false; public static boolean isDownloading = false;
public static boolean itemExist(String path) { public static boolean itemExist(String path) {

View File

@ -15,9 +15,6 @@ import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
public class ZipUtils { 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 { static {
System.loadLibrary("zipadjust"); System.loadLibrary("zipadjust");
@ -69,7 +66,7 @@ public class ZipUtils {
public static void signZip(JarMap input, File output, boolean minSign) throws Exception { public static void signZip(JarMap input, File output, boolean minSign) throws Exception {
AssetManager assets = MagiskManager.get().getAssets(); AssetManager assets = MagiskManager.get().getAssets();
SignAPK.signZip( 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); input, output, minSign);
} }
} }

View File

@ -72,7 +72,7 @@
android:title="@string/superuser"> android:title="@string/superuser">
<ListPreference <ListPreference
android:key="su_access" android:key="root_access"
android:title="@string/superuser_access" android:title="@string/superuser_access"
android:entries="@array/su_access" android:entries="@array/su_access"
android:entryValues="@array/value_array" /> android:entryValues="@array/value_array" />