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.Activity;
import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.utils.Const;
import java.io.IOException;
import java.io.InputStream;
@ -27,10 +28,6 @@ import butterknife.ButterKnife;
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.app_version_info) AboutCardRow appVersionInfo;
@BindView(R.id.app_changelog) AboutCardRow appChangelog;
@ -120,13 +117,13 @@ public class AboutActivity extends Activity {
}
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.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.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();
}

View File

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

View File

@ -43,13 +43,13 @@ import butterknife.Unbinder;
public class MagiskFragment extends Fragment
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView {
public static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
public static final int CAUSE_NETWORK_LOST = 0x02;
public static final int RESPONSE_ERR = 0x04;
public static final int CONNECTION_FAIL = 0x08;
private static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
private static final int CAUSE_NETWORK_LOST = 0x02;
private static final int RESPONSE_ERR = 0x04;
private static final int CONNECTION_FAIL = 0x08;
public static final int BASIC_PASS = 0x10;
public static final int CTS_PASS = 0x20;
private static final int BASIC_PASS = 0x10;
private static final int CTS_PASS = 0x20;
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.components.Fragment;
import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
@ -36,8 +37,6 @@ import butterknife.Unbinder;
public class MagiskLogFragment extends Fragment {
private static final String MAGISK_LOG = "/cache/magisk.log";
private Unbinder unbinder;
@BindView(R.id.txtLog) TextView txtLog;
@ -117,11 +116,11 @@ public class MagiskLogFragment extends Fragment {
switch (mode) {
case 0:
StringBuildingList logList = new StringBuildingList();
Shell.su(logList, "cat " + MAGISK_LOG + " | tail -n 1000");
return logList.toString();
Shell.su(logList, "cat " + Const.MAGISK_LOG + " | tail -n 1000");
return logList.getCharSequence();
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();
return "";
@ -142,7 +141,7 @@ public class MagiskLogFragment extends Fragment {
try (FileWriter out = new FileWriter(targetFile)) {
FileWritingList fileWritingList = new FileWritingList(out);
Shell.su(fileWritingList, "cat " + MAGISK_LOG);
Shell.su(fileWritingList, "cat " + Const.MAGISK_LOG);
} catch (IOException e) {
e.printStackTrace();
return false;
@ -158,7 +157,7 @@ public class MagiskLogFragment extends Fragment {
switch (mode) {
case 0:
case 1:
String llog = (String) o;
CharSequence llog = (CharSequence) o;
progressBar.setVisibility(View.GONE);
if (TextUtils.isEmpty(llog))
txtLog.setText(R.string.log_is_empty);
@ -170,7 +169,7 @@ public class MagiskLogFragment extends Fragment {
case 2:
boolean bool = (boolean) o;
if (bool) {
MagiskManager.toast(targetFile.toString(), Toast.LENGTH_LONG);
MagiskManager.toast(targetFile.getPath(), Toast.LENGTH_LONG);
} else {
MagiskManager.toast(R.string.logs_save_failed, Toast.LENGTH_LONG);
}
@ -205,9 +204,8 @@ public class MagiskLogFragment extends Fragment {
return true;
}
@Override
public String toString() {
return builder.toString();
public CharSequence getCharSequence() {
return builder;
}
}

View File

@ -26,8 +26,7 @@ import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.database.SuDatabaseHelper;
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.superuser.SuReceiver;
import com.topjohnwu.magisk.superuser.SuRequestActivity;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
@ -45,21 +44,6 @@ public class MagiskManager extends Application {
// Global weak reference to self
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
public final Topic magiskHideDone = new Topic();
public final Topic reloadActivity = new Topic();
@ -138,9 +122,9 @@ public class MagiskManager extends Application {
}
// If detect original package, self destruct!
if (!getPackageName().equals(ORIG_PKG_NAME)) {
if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
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()));
return;
} catch (PackageManager.NameNotFoundException ignored) { /* Expected*/ }
@ -157,7 +141,7 @@ public class MagiskManager extends Application {
}
public void setLocale() {
localeConfig = prefs.getString("locale", "");
localeConfig = prefs.getString(Const.Key.LOCALE, "");
if (localeConfig.isEmpty()) {
locale = defaultLocale;
} else {
@ -170,22 +154,22 @@ public class MagiskManager extends Application {
}
public void loadConfig() {
isDarkTheme = prefs.getBoolean("dark_theme", false);
isDarkTheme = prefs.getBoolean(Const.Key.DARK_THEME, false);
// su
suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", SuRequestActivity.PROMPT);
suNotificationType = Utils.getPrefsInt(prefs, "su_notification", SuReceiver.TOAST);
suReauth = prefs.getBoolean("su_reauth", false);
suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, SuDatabaseHelper.ROOT_ACCESS_APPS_AND_ADB);
multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, SuDatabaseHelper.MULTIUSER_MODE_OWNER_ONLY);
suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, SuDatabaseHelper.NAMESPACE_MODE_REQUESTER);
suRequestTimeout = Utils.getPrefsInt(prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]);
suResponseType = Utils.getPrefsInt(prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT);
suNotificationType = Utils.getPrefsInt(prefs, Const.Key.SU_NOTIFICATION, Const.Value.NOTIFICATION_TOAST);
suReauth = prefs.getBoolean(Const.Key.SU_REAUTH, false);
suAccessState = suDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB);
multiuserMode = suDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY);
suNamespaceMode = suDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER);
updateNotification = prefs.getBoolean("notification", true);
updateChannel = Utils.getPrefsInt(prefs, "update_channel", CheckUpdates.STABLE_CHANNEL);
bootFormat = prefs.getString("boot_format", ".img");
snet_version = prefs.getInt("snet_version", -1);
updateServiceVersion = prefs.getInt("update_service_version", -1);
updateNotification = prefs.getBoolean(Const.Key.UPDATE_NOTIFICATION, true);
updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL);
bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img");
snet_version = prefs.getInt(Const.Key.SNET_VER, -1);
updateServiceVersion = prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1);
}
public static void toast(String msg, int duration) {
@ -217,7 +201,7 @@ public class MagiskManager extends Application {
// Create notification channel on Android 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);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
@ -227,7 +211,7 @@ public class MagiskManager extends Application {
// Magisk working as expected
if (Shell.rootAccess() && magiskVersionCode > 0) {
// Load utility shell scripts
try (InputStream in = getAssets().open(Utils.UTIL_FUNCTIONS)) {
try (InputStream in = getAssets().open(Const.UTIL_FUNCTIONS)) {
shell.loadInputStream(in);
} catch (IOException e) {
e.printStackTrace();
@ -237,7 +221,7 @@ public class MagiskManager extends Application {
if (Utils.checkNetworkStatus()) {
// Make sure we have busybox
if (!Utils.itemExist(BUSYBOXPATH + "/busybox")) {
if (!Utils.itemExist(Const.BUSYBOXPATH + "/busybox")) {
try {
// Force synchronous, make sure we have busybox to use
new DownloadBusybox().exec().get();
@ -255,7 +239,7 @@ public class MagiskManager extends Application {
// Root shell initialization
Shell.su_raw(
"export PATH=" + BUSYBOXPATH + ":$PATH",
"export PATH=" + Const.BUSYBOXPATH + ":$PATH",
"mount_partitions",
"BOOTIMAGE=",
"find_boot_image",
@ -273,22 +257,22 @@ public class MagiskManager extends Application {
// Check alternative Magisk Manager
String pkg;
if (getPackageName().equals(ORIG_PKG_NAME) &&
(pkg = suDB.getStrings(SuDatabaseHelper.REQUESTER, null)) != null) {
if (getPackageName().equals(Const.ORIG_PKG_NAME) &&
(pkg = suDB.getStrings(Const.Key.SU_REQUESTER, null)) != null) {
Shell.su_raw("pm uninstall " + pkg);
suDB.setStrings(SuDatabaseHelper.REQUESTER, null);
suDB.setStrings(Const.Key.SU_REQUESTER, null);
}
// Add update checking service
if (UPDATE_SERVICE_VER > updateServiceVersion) {
if (Const.Value.UPDATE_SERVICE_VER > updateServiceVersion) {
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)
.setPersisted(true)
.setPeriodic(8 * 60 * 60 * 1000)
.build();
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(info);
updateServiceVersion = UPDATE_SERVICE_VER;
updateServiceVersion = Const.Value.UPDATE_SERVICE_VER;
}
// Fire asynctasks
@ -297,22 +281,22 @@ public class MagiskManager extends Application {
// Write back default values
prefs.edit()
.putBoolean("dark_theme", isDarkTheme)
.putBoolean("magiskhide", magiskHide)
.putBoolean("notification", updateNotification)
.putBoolean("hosts", Utils.itemExist(MAGISK_HOST_FILE))
.putBoolean("disable", Utils.itemExist(MAGISK_DISABLE_FILE))
.putBoolean("su_reauth", suReauth)
.putString("su_request_timeout", String.valueOf(suRequestTimeout))
.putString("su_auto_response", String.valueOf(suResponseType))
.putString("su_notification", String.valueOf(suNotificationType))
.putString("su_access", String.valueOf(suAccessState))
.putString("multiuser_mode", String.valueOf(multiuserMode))
.putString("mnt_ns", String.valueOf(suNamespaceMode))
.putString("update_channel", String.valueOf(updateChannel))
.putString("locale", localeConfig)
.putString("boot_format", bootFormat)
.putInt("update_service_version", updateServiceVersion)
.putBoolean(Const.Key.DARK_THEME, isDarkTheme)
.putBoolean(Const.Key.MAGISKHIDE, magiskHide)
.putBoolean(Const.Key.UPDATE_NOTIFICATION, updateNotification)
.putBoolean(Const.Key.HOSTS, Utils.itemExist(Const.MAGISK_HOST_FILE))
.putBoolean(Const.Key.DISABLE, Utils.itemExist(Const.MAGISK_DISABLE_FILE))
.putBoolean(Const.Key.SU_REAUTH, suReauth)
.putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout))
.putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType))
.putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType))
.putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState))
.putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode))
.putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode))
.putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel))
.putString(Const.Key.LOCALE, localeConfig)
.putString(Const.Key.BOOT_FORMAT, bootFormat)
.putInt(Const.Key.UPDATE_SERVICE_VER, updateServiceVersion)
.apply();
}
@ -339,16 +323,16 @@ public class MagiskManager extends Application {
magiskVersionCode = Integer.parseInt(ret.get(0));
} catch (NumberFormatException ignored) {}
}
ret = Shell.sh("getprop " + DISABLE_INDICATION_PROP);
ret = Shell.sh("getprop " + Const.DISABLE_INDICATION_PROP);
try {
disabled = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0;
} catch (NumberFormatException e) {
disabled = false;
}
if (magiskVersionCode > 1435) {
ret = Shell.su("resetprop -p " + MAGISKHIDE_PROP);
ret = Shell.su("resetprop -p " + Const.MAGISKHIDE_PROP);
} else {
ret = Shell.sh("getprop " + MAGISKHIDE_PROP);
ret = Shell.sh("getprop " + Const.MAGISKHIDE_PROP);
}
try {
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 com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
@ -70,7 +71,7 @@ public class MainActivity extends Activity
toggle.syncState();
if (savedInstanceState == null)
navigate(getIntent().getStringExtra(MagiskManager.INTENT_SECTION));
navigate(getIntent().getStringExtra(Const.Key.OPEN_SECTION));
navigationView.setNavigationItemSelectedListener(this);
@ -115,7 +116,7 @@ public class MainActivity extends Activity
Menu menu = navigationView.getMenu();
menu.findItem(R.id.magiskhide).setVisible(
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 1300
&& prefs.getBoolean("magiskhide", false));
&& prefs.getBoolean(Const.Key.MAGISKHIDE, false));
menu.findItem(R.id.modules).setVisible(
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus() &&
@ -141,7 +142,7 @@ public class MainActivity extends Activity
case "downloads":
itemId = R.id.downloads;
break;
case "magiskhide":
case Const.Key.MAGISKHIDE:
itemId = R.id.magiskhide;
break;
case "log":
@ -176,7 +177,7 @@ public class MainActivity extends Activity
displayFragment(new ReposFragment(), "downloads", true);
break;
case R.id.magiskhide:
displayFragment(new MagiskHideFragment(), "magiskhide", true);
displayFragment(new MagiskHideFragment(), Const.Key.MAGISKHIDE, true);
break;
case R.id.log:
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.components.Fragment;
import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
@ -29,8 +30,6 @@ import butterknife.Unbinder;
public class ModulesFragment extends Fragment implements Topic.Subscriber {
private static final int FETCH_ZIP_CODE = 2;
private Unbinder unbinder;
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@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, () -> {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
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
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
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);
}
}

View File

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

View File

@ -4,6 +4,7 @@ import android.content.Intent;
import android.os.Bundle;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.utils.Const;
public class SplashActivity extends Activity {
@ -14,9 +15,9 @@ public class SplashActivity extends Activity {
getMagiskManager().startup();
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) {
intent.putExtra(MagiskManager.INTENT_SECTION, section);
intent.putExtra(Const.Key.OPEN_SECTION, section);
}
startActivity(intent);
finish();

View File

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

View File

@ -4,6 +4,7 @@ import android.app.Activity;
import com.topjohnwu.crypto.ByteArrayStream;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.WebService;
@ -18,11 +19,6 @@ import dalvik.system.DexClassLoader;
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 DexClassLoader loader;
@ -34,18 +30,18 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
@Override
protected void onPreExecute() {
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());
}
mm.snet_version = CheckSafetyNet.SNET_VER;
mm.prefs.edit().putInt("snet_version", CheckSafetyNet.SNET_VER).apply();
mm.snet_version = Const.Value.SNET_VER;
mm.prefs.edit().putInt(Const.Key.SNET_VER, Const.Value.SNET_VER).apply();
}
@Override
protected Exception doInBackground(Void... voids) {
try {
if (!dexPath.exists()) {
HttpURLConnection conn = WebService.request(SNET_URL, null);
HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
ByteArrayStream bas = new ByteArrayStream();
bas.readFrom(conn.getInputStream());
conn.disconnect();
@ -68,8 +64,8 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
MagiskManager mm = MagiskManager.get();
try {
if (err != null) throw err;
Class<?> helperClazz = loader.loadClass(PKG + ".SafetyNetHelper");
Class<?> callbackClazz = loader.loadClass(PKG + ".SafetyNetCallback");
Class<?> helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
Class<?> callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback");
Object helper = helperClazz.getConstructors()[0].newInstance(
getActivity(), dexPath.getPath(), Proxy.newProxyInstance(
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.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ShowUI;
import com.topjohnwu.magisk.utils.WebService;
@ -10,12 +11,6 @@ import org.json.JSONObject;
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;
public CheckUpdates() {
@ -31,11 +26,11 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
MagiskManager mm = MagiskManager.get();
String jsonStr;
switch (mm.updateChannel) {
case STABLE_CHANNEL:
jsonStr = WebService.getString(STABLE_URL);
case Const.Value.STABLE_CHANNEL:
jsonStr = WebService.getString(Const.Url.STABLE_URL);
break;
case BETA_CHANNEL:
jsonStr = WebService.getString(BETA_URL);
case Const.Value.BETA_CHANNEL:
jsonStr = WebService.getString(Const.Url.BETA_URL);
break;
default:
jsonStr = null;

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import android.widget.Toast;
import com.topjohnwu.crypto.JarMap;
import com.topjohnwu.magisk.MagiskManager;
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.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
@ -20,8 +20,6 @@ import java.util.jar.JarEntry;
public class HideManager extends ParallelTask<Void, Void, Boolean> {
private static final String ANDROID_MANIFEST = "AndroidManifest.xml";
private String genPackageName(String prefix, int length) {
StringBuilder builder = new StringBuilder(length);
builder.append(prefix);
@ -101,17 +99,17 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
// Generate a new unhide app with random package name
File repack = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", "repack.apk");
repack.getParentFile().mkdirs();
String pkg = genPackageName("com.", MagiskManager.ORIG_PKG_NAME.length());
String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length());
try {
// Read whole APK into memory
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);
if (!findAndPatch(xml, MagiskManager.ORIG_PKG_NAME, pkg))
if (!findAndPatch(xml, Const.ORIG_PKG_NAME, pkg))
return false;
if (!findAndPatch(xml, MagiskManager.ORIG_PKG_NAME + ".provider", pkg + ".provider"))
if (!findAndPatch(xml, Const.ORIG_PKG_NAME + ".provider", pkg + ".provider"))
return false;
// Write in changes
@ -133,7 +131,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
if (!Utils.isValidShellResponse(ret) || !Boolean.parseBoolean(ret.get(0)))
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()));
return true;

View File

@ -11,6 +11,7 @@ import com.topjohnwu.crypto.SignBoot;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.AdaptiveList;
import com.topjohnwu.magisk.container.TarEntry;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
@ -202,10 +203,10 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
File signed = new File(install.getParent(), "signed.img");
AssetManager assets = mm.getAssets();
try (
InputStream in = new FileInputStream(patched_boot);
OutputStream out = new BufferedOutputStream(new FileOutputStream(signed));
InputStream keyIn = assets.open(ZipUtils.PRIVATE_KEY_NAME);
InputStream certIn = assets.open(ZipUtils.PUBLIC_KEY_NAME)
InputStream in = new FileInputStream(patched_boot);
OutputStream out = new BufferedOutputStream(new FileOutputStream(signed));
InputStream keyIn = assets.open(Const.PRIVATE_KEY_NAME);
InputStream certIn = assets.open(Const.PUBLIC_KEY_NAME)
) {
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.container.Module;
import com.topjohnwu.magisk.container.ValueSortedMap;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
import java.util.List;
@ -10,7 +11,7 @@ import java.util.List;
public class LoadModules extends ParallelTask<Void, Void, Void> {
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);
}

View File

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

View File

@ -7,6 +7,7 @@ import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.ReposFragment;
import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.WebService;
@ -26,12 +27,6 @@ import java.util.Map;
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 LOAD_NEXT = 1;
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");
if (old.exists() || prefs.getString("repomap", null) != null) {
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();
}
forceUpdate = force;
@ -111,8 +106,8 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
if (mode == CHECK_ETAG && page < etags.size()) {
etag = etags.get(page);
}
header.put(IF_NONE_MATCH, etag);
String url = String.format(Locale.US, REPO_URL, page + 1);
header.put(Const.Key.IF_NONE_MATCH, etag);
String url = String.format(Locale.US, Const.Url.REPO_URL, page + 1);
HttpURLConnection conn = WebService.request(url, header);
try {
@ -129,11 +124,11 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
}
// Update ETAG
etag = header.get(ETAG_KEY);
etag = header.get(Const.Key.ETAG_KEY);
etag = etag.substring(etag.indexOf('\"'), etag.lastIndexOf('\"') + 1);
newEtags.add(etag);
String links = header.get(LINK_KEY);
String links = header.get(Const.Key.LINK_KEY);
if (links != null) {
for (String s : links.split(", ")) {
if (mode != LOAD_PREV && s.contains("next")) {
@ -167,7 +162,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
@Override
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();
if (!loadPage(0, CHECK_ETAG)) {
@ -204,7 +199,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
if (i != 0) etagBuilder.append(",");
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;
}

View File

@ -3,17 +3,13 @@ package com.topjohnwu.magisk.container;
import android.content.ContentValues;
import android.database.Cursor;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.WebService;
import java.util.Date;
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 Date mLastUpdate;
@ -44,7 +40,7 @@ public class Repo extends BaseModule {
if (getVersionCode() < 0) {
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");
}
}
@ -70,15 +66,15 @@ public class Repo extends BaseModule {
}
public String getZipUrl() {
return String.format(ZIP_URL, repoName);
return String.format(Const.Url.ZIP_URL, repoName);
}
public String getManifestUrl() {
return String.format(FILE_URL, repoName, "module.prop");
return String.format(Const.Url.FILE_URL, repoName, "module.prop");
}
public String getDetailUrl() {
return String.format(FILE_URL, repoName, "README.md");
return String.format(Const.Url.FILE_URL, repoName, "README.md");
}
public Date getLastUpdate() {

View File

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

View File

@ -25,25 +25,8 @@ import java.util.List;
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";
private static final int DATABASE_VER = 5;
private static final String POLICY_TABLE = "policies";
private static final String LOG_TABLE = "logs";

View File

@ -7,7 +7,7 @@ import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils;
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" +
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.support.v4.app.NotificationCompat;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Const;
public class OnBootIntentService extends IntentService {
private static final int ONBOOT_NOTIFICATION_ID = 3;
public OnBootIntentService() {
super("OnBootIntentService");
}
@ -21,11 +19,11 @@ public class OnBootIntentService extends IntentService {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, MagiskManager.NOTIFICATION_CHANNEL);
new NotificationCompat.Builder(this, Const.ID.NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk)
.setContentTitle("onBoot")
.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.container.Policy;
import com.topjohnwu.magisk.container.SuLogEntry;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils;
import java.util.Date;
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
public void onReceive(Context context, Intent intent) {
int fromUid, toUid, pid, mode;
String command, action;
Policy policy;
MagiskManager magiskManager = (MagiskManager) context.getApplicationContext();
MagiskManager mm = Utils.getMagiskManager(context);
if (intent == null) return;
mode = intent.getIntExtra("mode", -1);
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);
return;
}
@ -48,7 +43,7 @@ public class SuReceiver extends BroadcastReceiver {
action = intent.getStringExtra("action");
if (action == null) return;
policy = magiskManager.suDB.getPolicy(fromUid);
policy = mm.suDB.getPolicy(fromUid);
if (policy == null) {
try {
policy = new Policy(fromUid, context.getPackageManager());
@ -74,11 +69,11 @@ public class SuReceiver extends BroadcastReceiver {
return;
}
if (policy.notification && magiskManager.suNotificationType == TOAST) {
magiskManager.toast(message, Toast.LENGTH_SHORT);
if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
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);
if (toUid < 0) return;
pid = intent.getIntExtra("pid", -1);
@ -89,7 +84,7 @@ public class SuReceiver extends BroadcastReceiver {
log.fromPid = pid;
log.command = command;
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.components.Activity;
import com.topjohnwu.magisk.container.Policy;
import com.topjohnwu.magisk.utils.Const;
import java.io.DataInputStream;
import java.io.IOException;
@ -31,12 +32,6 @@ import butterknife.ButterKnife;
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.timeout) Spinner timeout;
@BindView(R.id.app_icon) ImageView appIcon;
@ -86,13 +81,13 @@ public class SuRequestActivity extends Activity {
private void showRequest() {
switch (mm.suResponseType) {
case AUTO_DENY:
case Const.Value.SU_AUTO_DENY:
handleAction(Policy.DENY, 0);
return;
case AUTO_ALLOW:
case Const.Value.SU_AUTO_ALLOW:
handleAction(Policy.ALLOW, 0);
return;
case PROMPT:
case Const.Value.SU_PROMPT:
default:
}
@ -169,7 +164,7 @@ public class SuRequestActivity extends Activity {
}
void handleAction(int action) {
handleAction(action, timeoutList[timeout.getSelectedItemPosition()]);
handleAction(action, Const.Value.timeoutList[timeout.getSelectedItemPosition()]);
}
void handleAction(int action, int time) {

View File

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

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

View File

@ -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(

View File

@ -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) {

View File

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

View File

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