Centralize configuration management

This commit is contained in:
topjohnwu
2019-01-21 15:49:03 -05:00
parent 858216796a
commit a189dec1c8
32 changed files with 583 additions and 418 deletions

View File

@@ -9,8 +9,8 @@ import android.view.MenuItem;
import android.view.View;
import com.google.android.material.navigation.NavigationView;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.Topic;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.components.BaseActivity;
@@ -125,10 +125,10 @@ public class MainActivity extends BaseActivity
public void checkHideSection() {
Menu menu = navigationView.getMenu();
menu.findItem(R.id.magiskhide).setVisible(Shell.rootAccess() &&
app.prefs.getBoolean(Const.Key.MAGISKHIDE, false));
menu.findItem(R.id.modules).setVisible(Shell.rootAccess() && Data.magiskVersionCode >= 0);
(boolean) Config.get(Config.Key.MAGISKHIDE));
menu.findItem(R.id.modules).setVisible(Shell.rootAccess() && Config.magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(Networking.checkNetworkStatus(this)
&& Shell.rootAccess() && Data.magiskVersionCode >= 0);
&& Shell.rootAccess() && Config.magiskVersionCode >= 0);
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
menu.findItem(R.id.superuser).setVisible(Utils.showSuperUser());
}

View File

@@ -5,8 +5,8 @@ import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.tasks.CheckUpdates;
import com.topjohnwu.core.tasks.UpdateRepos;
import com.topjohnwu.core.utils.LocaleManager;
@@ -27,9 +27,9 @@ public class SplashActivity extends BaseActivity {
// Dynamic detect all locales
LocaleManager.loadAvailableLocales(R.string.app_changelog);
String pkg = app.mDB.getStrings(Const.Key.SU_MANAGER, null);
String pkg = Config.get(Config.Key.SU_MANAGER);
if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) {
app.mDB.setStrings(Const.Key.SU_MANAGER, null);
Config.remove(Config.Key.SU_MANAGER);
Shell.su("pm uninstall " + pkg).exec();
}
if (TextUtils.equals(pkg, getPackageName())) {
@@ -41,12 +41,13 @@ public class SplashActivity extends BaseActivity {
}
// Magisk working as expected
if (Shell.rootAccess() && Data.magiskVersionCode > 0) {
if (Shell.rootAccess() && Config.magiskVersionCode > 0) {
// Load modules
Utils.loadModules();
}
Data.importPrefs();
// Set default configs
Config.initialize();
// Create notification channel on Android O
Notifications.setup(this);
@@ -64,9 +65,6 @@ public class SplashActivity extends BaseActivity {
new UpdateRepos().exec();
}
// Write back default values
Data.writeConfig();
app.init = true;
Intent intent = new Intent(this, ClassMap.get(MainActivity.class));

View File

@@ -15,8 +15,7 @@ import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.container.Policy;
import com.topjohnwu.magisk.components.BaseActivity;
import com.topjohnwu.magisk.utils.FingerprintHelper;
@@ -103,14 +102,14 @@ public class SuRequestActivity extends BaseActivity {
return;
}
switch (Data.suResponseType) {
case Const.Value.SU_AUTO_DENY:
switch ((int) Config.get(Config.Key.SU_AUTO_RESPONSE)) {
case Config.Value.SU_AUTO_DENY:
handleAction(Policy.DENY, 0);
return;
case Const.Value.SU_AUTO_ALLOW:
case Config.Value.SU_AUTO_ALLOW:
handleAction(Policy.ALLOW, 0);
return;
case Const.Value.SU_PROMPT:
case Config.Value.SU_PROMPT:
default:
}
@@ -134,7 +133,7 @@ public class SuRequestActivity extends BaseActivity {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeout.setAdapter(adapter);
timer = new CountDownTimer(Data.suRequestTimeout * 1000, 1000) {
timer = new CountDownTimer((int) Config.get(Config.Key.SU_REQUEST_TIMEOUT) * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
deny_btn.setText(getString(R.string.deny_with_str, "(" + millisUntilFinished / 1000 + ")"));
@@ -210,7 +209,7 @@ public class SuRequestActivity extends BaseActivity {
}
private void handleAction(int action) {
handleAction(action, Const.Value.timeoutList[timeout.getSelectedItemPosition()]);
handleAction(action, Config.Value.TIMEOUT_LIST[timeout.getSelectedItemPosition()]);
}
private void handleAction(int action, int time) {

View File

@@ -10,8 +10,8 @@ import android.view.WindowManager;
import android.widget.Toast;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.LocaleManager;
import com.topjohnwu.core.utils.Topic;
import com.topjohnwu.magisk.R;
@@ -59,7 +59,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Topic.subscribe(this);
if (Data.isDarkTheme && getDarkTheme() != -1) {
if (getDarkTheme() != -1 && (boolean) Config.get(Config.Key.DARK_THEME)) {
setTheme(getDarkTheme());
}
super.onCreate(savedInstanceState);

View File

@@ -5,8 +5,8 @@ import android.content.Intent;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.FlashActivity;
@@ -65,10 +65,10 @@ class InstallMethodDialog extends AlertDialog.Builder {
private void downloadOnly(BaseActivity a) {
a.runWithExternalRW(() -> {
String filename = Utils.fmt("Magisk-v%s(%d).zip",
Data.remoteMagiskVersionString, Data.remoteMagiskVersionCode);
Config.remoteMagiskVersionString, Config.remoteMagiskVersionCode);
File zip = new File(Const.EXTERNAL_PATH, filename);
ProgressNotification progress = new ProgressNotification(filename);
Networking.get(Data.magiskLink)
Networking.get(Config.magiskLink)
.setDownloadProgressListener(progress)
.setErrorHandler(((conn, e) -> progress.dlFail()))
.getAsFile(zip, f -> {

View File

@@ -3,7 +3,7 @@ package com.topjohnwu.magisk.components;
import android.net.Uri;
import android.text.TextUtils;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.AppUtils;
@@ -17,7 +17,7 @@ public class MagiskInstallDialog extends CustomAlertDialog {
public MagiskInstallDialog(BaseActivity a) {
super(a);
String filename = Utils.fmt("Magisk-v%s(%d).zip",
Data.remoteMagiskVersionString, Data.remoteMagiskVersionCode);
Config.remoteMagiskVersionString, Config.remoteMagiskVersionCode);
setTitle(a.getString(R.string.repo_install_title, a.getString(R.string.magisk)));
setMessage(a.getString(R.string.repo_install_msg, filename));
setCancelable(true);
@@ -35,13 +35,13 @@ public class MagiskInstallDialog extends CustomAlertDialog {
new InstallMethodDialog(a, options).show();
});
setNegativeButton(R.string.no_thanks, null);
if (!TextUtils.isEmpty(Data.magiskNoteLink)) {
if (!TextUtils.isEmpty(Config.magiskNoteLink)) {
setNeutralButton(R.string.release_notes, (d, i) -> {
if (Data.magiskNoteLink.contains("forum.xda-developers")) {
if (Config.magiskNoteLink.contains("forum.xda-developers")) {
// Open forum links in browser
AppUtils.openLink(a, Uri.parse(Data.magiskNoteLink));
AppUtils.openLink(a, Uri.parse(Config.magiskNoteLink));
} else {
MarkDownWindow.show(a, null, Data.magiskNoteLink);
MarkDownWindow.show(a, null, Config.magiskNoteLink);
}
});
}

View File

@@ -2,7 +2,7 @@ package com.topjohnwu.magisk.components;
import android.text.TextUtils;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.DownloadApp;
@@ -14,14 +14,14 @@ public class ManagerInstallDialog extends CustomAlertDialog {
public ManagerInstallDialog(@NonNull BaseActivity a) {
super(a);
String name = Utils.fmt("MagiskManager v%s(%d)",
Data.remoteManagerVersionString, Data.remoteManagerVersionCode);
Config.remoteManagerVersionString, Config.remoteManagerVersionCode);
setTitle(a.getString(R.string.repo_install_title, a.getString(R.string.app_name)));
setMessage(a.getString(R.string.repo_install_msg, name));
setCancelable(true);
setPositiveButton(R.string.install, (d, i) -> DownloadApp.upgrade(name));
setNegativeButton(R.string.no_thanks, null);
if (!TextUtils.isEmpty(Data.managerNoteLink)) {
setNeutralButton(R.string.app_changelog, (d, i) -> MarkDownWindow.show(a, null, Data.managerNoteLink));
if (!TextUtils.isEmpty(Config.managerNoteLink)) {
setNeutralButton(R.string.app_changelog, (d, i) -> MarkDownWindow.show(a, null, Config.managerNoteLink));
}
}
}

View File

@@ -8,8 +8,8 @@ import android.content.Intent;
import android.os.Build;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.R;
@@ -52,7 +52,7 @@ public class Notifications {
NotificationCompat.Builder builder = new NotificationCompat.Builder(app, Const.ID.UPDATE_NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk_outline)
.setContentTitle(app.getString(R.string.magisk_update_title))
.setContentText(app.getString(R.string.magisk_update_available, Data.remoteMagiskVersionString))
.setContentText(app.getString(R.string.magisk_update_available, Config.remoteMagiskVersionString))
.setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true)
.setContentIntent(pendingIntent);
@@ -63,11 +63,11 @@ public class Notifications {
public static void managerUpdate() {
App app = App.self;
String name = Utils.fmt("MagiskManager v%s(%d)",
Data.remoteManagerVersionString, Data.remoteManagerVersionCode);
Config.remoteManagerVersionString, Config.remoteManagerVersionCode);
Intent intent = new Intent(app, ClassMap.get(GeneralReceiver.class));
intent.setAction(Const.Key.BROADCAST_MANAGER_UPDATE);
intent.putExtra(Const.Key.INTENT_SET_LINK, Data.managerLink);
intent.putExtra(Const.Key.INTENT_SET_LINK, Config.managerLink);
intent.putExtra(Const.Key.INTENT_SET_NAME, name);
PendingIntent pendingIntent = PendingIntent.getBroadcast(app,
Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@@ -7,8 +7,8 @@ import android.net.Uri;
import android.text.TextUtils;
import android.widget.Toast;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.FlashActivity;
@@ -39,11 +39,11 @@ public class UninstallDialog extends CustomAlertDialog {
}
});
});
if (!TextUtils.isEmpty(Data.uninstallerLink)) {
if (!TextUtils.isEmpty(Config.uninstallerLink)) {
setPositiveButton(R.string.complete_uninstall, (d, i) -> {
File zip = new File(activity.getFilesDir(), "uninstaller.zip");
ProgressNotification progress = new ProgressNotification(zip.getName());
Networking.get(Data.uninstallerLink)
Networking.get(Config.uninstallerLink)
.setDownloadProgressListener(progress)
.setErrorHandler(((conn, e) -> progress.dlFail()))
.getAsFile(zip, f -> {

View File

@@ -15,8 +15,7 @@ import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.tasks.CheckUpdates;
import com.topjohnwu.core.tasks.SafetyNet;
import com.topjohnwu.core.utils.ISafetyNetHelper;
@@ -112,7 +111,7 @@ public class MagiskFragment extends BaseFragment
@OnClick(R.id.install_button)
void install() {
// Show Manager update first
if (Data.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
if (Config.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
new ManagerInstallDialog((BaseActivity) requireActivity()).show();
return;
}
@@ -137,10 +136,10 @@ public class MagiskFragment extends BaseFragment
expandableContainer.expandLayout = expandLayout;
setupExpandable();
keepVerityChkbox.setChecked(Data.keepVerity);
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Data.keepVerity = checked);
keepEncChkbox.setChecked(Data.keepEnc);
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Data.keepEnc = checked);
keepVerityChkbox.setChecked(Config.keepVerity);
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Config.keepVerity = checked);
keepEncChkbox.setChecked(Config.keepEnc);
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Config.keepEnc = checked);
mSwipeRefreshLayout.setOnRefreshListener(this);
updateUI();
@@ -150,7 +149,7 @@ public class MagiskFragment extends BaseFragment
@Override
public void onRefresh() {
Data.loadMagiskInfo();
Config.loadMagiskInfo();
updateUI();
magiskUpdateText.setText(R.string.checking_for_updates);
@@ -160,8 +159,8 @@ public class MagiskFragment extends BaseFragment
safetyNetStatusText.setText(R.string.safetyNet_check_text);
Topic.reset(getSubscribedTopics());
Data.remoteMagiskVersionString = null;
Data.remoteMagiskVersionCode = -1;
Config.remoteMagiskVersionString = null;
Config.remoteMagiskVersionCode = -1;
collapse();
shownDialog = false;
@@ -216,18 +215,18 @@ public class MagiskFragment extends BaseFragment
magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
uninstallButton.setVisibility(hasRoot ? View.VISIBLE : View.GONE);
coreOnlyNotice.setVisibility(app.prefs.getBoolean(Const.Key.COREONLY, false) ? View.VISIBLE : View.GONE);
coreOnlyNotice.setVisibility(Config.get(Config.Key.COREONLY) ? View.VISIBLE : View.GONE);
int image, color;
if (Data.magiskVersionCode < 0) {
if (Config.magiskVersionCode < 0) {
color = colorBad;
image = R.drawable.ic_cancel;
magiskVersionText.setText(R.string.magisk_version_error);
} else {
color = colorOK;
image = R.drawable.ic_check_circle;
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + Data.magiskVersionString));
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + Config.magiskVersionString));
}
magiskStatusIcon.setImageResource(image);
@@ -239,7 +238,7 @@ public class MagiskFragment extends BaseFragment
safetyNetCard.setVisibility(hasGms() ? View.VISIBLE : View.GONE);
if (Data.remoteMagiskVersionCode < 0) {
if (Config.remoteMagiskVersionCode < 0) {
color = colorNeutral;
image = R.drawable.ic_help;
magiskUpdateText.setText(R.string.invalid_update_channel);
@@ -247,11 +246,11 @@ public class MagiskFragment extends BaseFragment
} else {
color = colorOK;
image = R.drawable.ic_check_circle;
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + Data.remoteMagiskVersionString));
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + Config.remoteMagiskVersionString));
installButton.setVisibility(View.VISIBLE);
if (Data.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
if (Config.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
installText.setText(getString(R.string.update, getString(R.string.app_name)));
} else if (Data.magiskVersionCode > 0 && Data.remoteMagiskVersionCode > Data.magiskVersionCode) {
} else if (Config.magiskVersionCode > 0 && Config.remoteMagiskVersionCode > Config.magiskVersionCode) {
installText.setText(getString(R.string.update, getString(R.string.magisk)));
} else {
installText.setText(R.string.install);

View File

@@ -11,8 +11,7 @@ import android.view.ViewGroup;
import android.widget.SearchView;
import android.widget.TextView;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.container.Module;
import com.topjohnwu.core.tasks.UpdateRepos;
import com.topjohnwu.core.utils.Topic;
@@ -106,9 +105,9 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber {
if (item.getItemId() == R.id.repo_sort) {
new AlertDialog.Builder(getActivity())
.setTitle(R.string.sorting_order)
.setSingleChoiceItems(R.array.sorting_orders, Data.repoOrder, (d, which) -> {
Data.repoOrder = which;
app.prefs.edit().putInt(Const.Key.REPO_ORDER, Data.repoOrder).apply();
.setSingleChoiceItems(R.array.sorting_orders,
Config.get(Config.Key.REPO_ORDER), (d, which) -> {
Config.set(Config.Key.REPO_ORDER, which);
adapter.notifyDBChanged();
d.dismiss();
}).show();

View File

@@ -11,8 +11,8 @@ import android.widget.EditText;
import android.widget.Toast;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.tasks.CheckUpdates;
import com.topjohnwu.core.utils.LocaleManager;
import com.topjohnwu.core.utils.Topic;
@@ -49,27 +49,15 @@ public class SettingsFragment extends PreferenceFragmentCompat
private ListPreference updateChannel, autoRes, suNotification,
requestTimeout, rootConfig, multiuserConfig, nsConfig;
private int rootState, namespaceState;
private boolean showSuperuser;
private void prefsSync() {
rootState = app.mDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB);
namespaceState = app.mDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER);
showSuperuser = Utils.showSuperUser();
app.prefs.edit()
.putString(Const.Key.ROOT_ACCESS, String.valueOf(rootState))
.putString(Const.Key.SU_MNT_NS, String.valueOf(namespaceState))
.putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(Data.multiuserState))
.putBoolean(Const.Key.SU_FINGERPRINT, FingerprintHelper.useFingerPrint())
.apply();
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
prefsSync();
setPreferencesFromResource(R.xml.app_settings, rootKey);
boolean showSuperuser = Utils.showSuperUser();
app.prefs.edit()
.putBoolean(Config.Key.SU_FINGERPRINT, FingerprintHelper.useFingerPrint())
.apply();
PreferenceScreen prefScreen = getPreferenceScreen();
PreferenceCategory generalCatagory = (PreferenceCategory) findPreference("general");
@@ -86,7 +74,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
return true;
});
findPreference("clear").setOnPreferenceClickListener(pref -> {
app.prefs.edit().remove(Const.Key.ETAG_KEY).apply();
app.prefs.edit().remove(Config.Key.ETAG_KEY).apply();
app.repoDB.clearRepo();
Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
return true;
@@ -98,33 +86,32 @@ public class SettingsFragment extends PreferenceFragmentCompat
return true;
});
updateChannel = (ListPreference) findPreference(Const.Key.UPDATE_CHANNEL);
rootConfig = (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);
multiuserConfig = (ListPreference) findPreference(Const.Key.SU_MULTIUSER_MODE);
nsConfig = (ListPreference) findPreference(Const.Key.SU_MNT_NS);
SwitchPreferenceCompat reauth = (SwitchPreferenceCompat) findPreference(Const.Key.SU_REAUTH);
SwitchPreferenceCompat fingerprint = (SwitchPreferenceCompat) findPreference(Const.Key.SU_FINGERPRINT);
updateChannel = (ListPreference) findPreference(Config.Key.UPDATE_CHANNEL);
rootConfig = (ListPreference) findPreference(Config.Key.ROOT_ACCESS);
autoRes = (ListPreference) findPreference(Config.Key.SU_AUTO_RESPONSE);
requestTimeout = (ListPreference) findPreference(Config.Key.SU_REQUEST_TIMEOUT);
suNotification = (ListPreference) findPreference(Config.Key.SU_NOTIFICATION);
multiuserConfig = (ListPreference) findPreference(Config.Key.SU_MULTIUSER_MODE);
nsConfig = (ListPreference) findPreference(Config.Key.SU_MNT_NS);
SwitchPreferenceCompat reauth = (SwitchPreferenceCompat) findPreference(Config.Key.SU_REAUTH);
SwitchPreferenceCompat fingerprint = (SwitchPreferenceCompat) findPreference(Config.Key.SU_FINGERPRINT);
updateChannel.setOnPreferenceChangeListener((p, o) -> {
String prev =String.valueOf(Data.updateChannel);
int prev = Config.get(Config.Key.UPDATE_CHANNEL);
int channel = Integer.parseInt((String) o);
if (channel == Const.Value.CUSTOM_CHANNEL) {
if (channel == Config.Value.CUSTOM_CHANNEL) {
View v = LayoutInflater.from(requireActivity()).inflate(R.layout.custom_channel_dialog, null);
EditText url = v.findViewById(R.id.custom_url);
url.setText(app.prefs.getString(Const.Key.CUSTOM_CHANNEL, ""));
url.setText(app.prefs.getString(Config.Key.CUSTOM_CHANNEL, ""));
new AlertDialog.Builder(requireActivity())
.setTitle(R.string.settings_update_custom)
.setView(v)
.setPositiveButton(R.string.ok, (d, i) ->
app.prefs.edit().putString(Const.Key.CUSTOM_CHANNEL,
url.getText().toString()).apply())
Config.set(Config.Key.CUSTOM_CHANNEL, url.getText().toString()))
.setNegativeButton(R.string.close, (d, i) ->
app.prefs.edit().putString(Const.Key.UPDATE_CHANNEL, prev).apply())
Config.set(Config.Key.UPDATE_CHANNEL, prev))
.setOnCancelListener(d ->
app.prefs.edit().putString(Const.Key.UPDATE_CHANNEL, prev).apply())
Config.set(Config.Key.UPDATE_CHANNEL, prev))
.show();
}
return true;
@@ -207,26 +194,15 @@ public class SettingsFragment extends PreferenceFragmentCompat
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
switch (key) {
case Const.Key.ROOT_ACCESS:
case Const.Key.SU_MULTIUSER_MODE:
case Const.Key.SU_MNT_NS:
case Config.Key.ROOT_ACCESS:
case Config.Key.SU_MULTIUSER_MODE:
case Config.Key.SU_MNT_NS:
app.mDB.setSettings(key, Utils.getPrefsInt(prefs, key));
break;
}
switch (key) {
case Const.Key.ROOT_ACCESS:
rootState = Utils.getPrefsInt(prefs, key);
break;
case Const.Key.SU_MULTIUSER_MODE:
Data.multiuserState = Utils.getPrefsInt(prefs, key);
break;
case Const.Key.SU_MNT_NS:
namespaceState = Utils.getPrefsInt(prefs, key);
break;
case Const.Key.DARK_THEME:
case Config.Key.DARK_THEME:
requireActivity().recreate();
break;
case Const.Key.COREONLY:
case Config.Key.COREONLY:
if (prefs.getBoolean(key, false)) {
try {
Const.MAGISK_DISABLE_FILE.createNewFile();
@@ -236,66 +212,97 @@ public class SettingsFragment extends PreferenceFragmentCompat
}
Utils.toast(R.string.settings_reboot_toast, Toast.LENGTH_LONG);
break;
case Const.Key.MAGISKHIDE:
case Config.Key.MAGISKHIDE:
if (prefs.getBoolean(key, false)) {
Shell.su("magiskhide --enable").submit();
} else {
Shell.su("magiskhide --disable").submit();
}
break;
case Const.Key.LOCALE:
case Config.Key.LOCALE:
LocaleManager.setLocale(app);
requireActivity().recreate();
break;
case Const.Key.UPDATE_CHANNEL:
case Const.Key.CUSTOM_CHANNEL:
case Config.Key.UPDATE_CHANNEL:
case Config.Key.CUSTOM_CHANNEL:
CheckUpdates.check();
break;
case Const.Key.CHECK_UPDATES:
case Config.Key.CHECK_UPDATES:
AppUtils.scheduleUpdateCheck();
break;
}
Data.loadConfig();
setSummary();
setSummary(key);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
String key = preference.getKey();
switch (key) {
case Const.Key.SU_FINGERPRINT:
case Config.Key.SU_FINGERPRINT:
boolean checked = ((SwitchPreferenceCompat) preference).isChecked();
((SwitchPreferenceCompat) preference).setChecked(!checked);
FingerprintHelper.showAuthDialog(requireActivity(), () -> {
((SwitchPreferenceCompat) preference).setChecked(checked);
app.mDB.setSettings(key, checked ? 1 : 0);
Config.set(key, checked);
});
break;
}
return true;
}
private void setSummary(String key) {
switch (key) {
case Config.Key.UPDATE_CHANNEL:
updateChannel.setSummary(getResources()
.getStringArray(R.array.update_channel)
[(int) Config.get(Config.Key.UPDATE_CHANNEL)]);
break;
case Config.Key.ROOT_ACCESS:
rootConfig.setSummary(getResources()
.getStringArray(R.array.su_access)
[(int) Config.get(Config.Key.ROOT_ACCESS)]);
break;
case Config.Key.SU_AUTO_RESPONSE:
autoRes.setSummary(getResources()
.getStringArray(R.array.auto_response)
[(int) Config.get(Config.Key.SU_AUTO_RESPONSE)]);
break;
case Config.Key.SU_NOTIFICATION:
suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)
[(int) Config.get(Config.Key.SU_NOTIFICATION)]);
break;
case Config.Key.SU_REQUEST_TIMEOUT:
requestTimeout.setSummary(
getString(R.string.request_timeout_summary,
app.prefs.getString(Config.Key.SU_REQUEST_TIMEOUT, "10")));
break;
case Config.Key.SU_MULTIUSER_MODE:
multiuserConfig.setSummary(getResources()
.getStringArray(R.array.multiuser_summary)
[(int) Config.get(Config.Key.SU_MULTIUSER_MODE)]);
break;
case Config.Key.SU_MNT_NS:
nsConfig.setSummary(getResources()
.getStringArray(R.array.namespace_summary)
[(int) Config.get(Config.Key.SU_MNT_NS)]);
break;
}
}
private void setSummary() {
updateChannel.setSummary(getResources()
.getStringArray(R.array.update_channel)[Data.updateChannel]);
rootConfig.setSummary(getResources()
.getStringArray(R.array.su_access)[rootState]);
autoRes.setSummary(getResources()
.getStringArray(R.array.auto_response)[Data.suResponseType]);
suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)[Data.suNotificationType]);
requestTimeout.setSummary(
getString(R.string.request_timeout_summary,
app.prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10")));
multiuserConfig.setSummary(getResources()
.getStringArray(R.array.multiuser_summary)[Data.multiuserState]);
nsConfig.setSummary(getResources()
.getStringArray(R.array.namespace_summary)[namespaceState]);
setSummary(Config.Key.UPDATE_CHANNEL);
setSummary(Config.Key.ROOT_ACCESS);
setSummary(Config.Key.SU_AUTO_RESPONSE);
setSummary(Config.Key.SU_NOTIFICATION);
setSummary(Config.Key.SU_REQUEST_TIMEOUT);
setSummary(Config.Key.SU_MULTIUSER_MODE);
setSummary(Config.Key.SU_MNT_NS);
}
@Override
public void onPublish(int topic, Object[] result) {
setLocalePreference((ListPreference) findPreference(Const.Key.LOCALE));
setLocalePreference((ListPreference) findPreference(Config.Key.LOCALE));
}
@Override

View File

@@ -6,8 +6,8 @@ import android.content.Intent;
import android.os.AsyncTask;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.SuRequestActivity;
import com.topjohnwu.magisk.components.Notifications;
@@ -66,7 +66,7 @@ public class GeneralReceiver extends BroadcastReceiver {
break;
case Intent.ACTION_PACKAGE_REPLACED:
// This will only work pre-O
if (app.prefs.getBoolean(Const.Key.SU_REAUTH, false)) {
if (Config.get(Config.Key.SU_REAUTH)) {
app.mDB.deletePolicy(getPkg(intent));
}
break;
@@ -76,7 +76,7 @@ public class GeneralReceiver extends BroadcastReceiver {
Shell.su("magiskhide --rm " + pkg).submit();
break;
case Const.Key.BROADCAST_MANAGER_UPDATE:
Data.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK);
Config.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK);
DownloadApp.upgrade(intent.getStringExtra(Const.Key.INTENT_SET_NAME));
break;
case Const.Key.BROADCAST_REBOOT:

View File

@@ -9,8 +9,8 @@ import android.graphics.drawable.Icon;
import android.os.Build;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.R;
@@ -45,7 +45,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
.setRank(0)
.build());
}
if (root && app.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) {
if (root && (boolean) Config.get(Config.Key.MAGISKHIDE)) {
shortCuts.add(new ShortcutInfo.Builder(app, "magiskhide")
.setShortLabel(app.getString(R.string.magiskhide))
.setIntent(new Intent(app, ClassMap.get(SplashActivity.class))
@@ -56,7 +56,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
.setRank(1)
.build());
}
if (!app.prefs.getBoolean(Const.Key.COREONLY, false) && root && Data.magiskVersionCode >= 0) {
if (!(boolean) Config.get(Config.Key.COREONLY) && root && Config.magiskVersionCode >= 0) {
shortCuts.add(new ShortcutInfo.Builder(app, "modules")
.setShortLabel(app.getString(R.string.modules))
.setIntent(new Intent(app, ClassMap.get(SplashActivity.class))

View File

@@ -1,6 +1,6 @@
package com.topjohnwu.magisk.services;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.tasks.CheckUpdates;
import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.components.Notifications;
@@ -20,9 +20,9 @@ public class UpdateCheckService extends DelegateWorker {
}
private void onCheckDone() {
if (BuildConfig.VERSION_CODE < Data.remoteManagerVersionCode) {
if (BuildConfig.VERSION_CODE < Config.remoteManagerVersionCode) {
Notifications.managerUpdate();
} else if (Data.magiskVersionCode < Data.remoteMagiskVersionCode) {
} else if (Config.magiskVersionCode < Config.remoteMagiskVersionCode) {
Notifications.magiskUpdate();
}
}

View File

@@ -5,7 +5,7 @@ import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.ClassMap;
@@ -23,7 +23,7 @@ import androidx.work.WorkManager;
public class AppUtils {
public static void scheduleUpdateCheck() {
if (App.self.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) {
if (Config.get(Config.Key.CHECK_UPDATES)) {
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();

View File

@@ -3,7 +3,7 @@ package com.topjohnwu.magisk.utils;
import android.os.AsyncTask;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.utils.RootUtils;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.BuildConfig;
@@ -25,7 +25,7 @@ public class DownloadApp {
public static void restore() {
String name = Utils.fmt("MagiskManager v%s(%d)",
Data.remoteManagerVersionString, Data.remoteManagerVersionCode);
Config.remoteManagerVersionString, Config.remoteManagerVersionCode);
dlInstall(name, new RestoreManager());
}
@@ -33,7 +33,7 @@ public class DownloadApp {
File apk = new File(App.self.getCacheDir(), "manager.apk");
ProgressNotification progress = new ProgressNotification(name);
listener.progress = progress;
Networking.get(Data.managerLink)
Networking.get(Config.managerLink)
.setExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.setDownloadProgressListener(progress)
.setErrorHandler((conn, e) -> progress.dlFail())
@@ -85,7 +85,7 @@ public class DownloadApp {
.setContentTitle(app.getString(R.string.restore_img_msg))
.setContentText("");
progress.update();
Data.exportPrefs();
Config.export();
// Make it world readable
apk.setReadable(true, false);
if (ShellUtils.fastCmdResult("pm install " + apk))

View File

@@ -17,6 +17,7 @@ import android.view.Gravity;
import android.widget.Toast;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.R;
@@ -36,9 +37,9 @@ public abstract class FingerprintHelper {
private CancellationSignal cancel;
public static boolean useFingerPrint() {
boolean fp = App.self.mDB.getSettings(Const.Key.SU_FINGERPRINT, 0) != 0;
boolean fp = Config.get(Config.Key.SU_FINGERPRINT);
if (fp && !canUseFingerprint()) {
App.self.mDB.setSettings(Const.Key.SU_FINGERPRINT, 0);
Config.set(Config.Key.SU_FINGERPRINT, false);
fp = false;
}
return fp;

View File

@@ -4,8 +4,8 @@ import android.os.AsyncTask;
import android.widget.Toast;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.utils.RootUtils;
import com.topjohnwu.core.utils.Utils;
import com.topjohnwu.magisk.BuildConfig;
@@ -110,8 +110,8 @@ public class PatchAPK {
if (!ShellUtils.fastCmdResult("pm install " + repack))
return false;
app.mDB.setStrings(Const.Key.SU_MANAGER, pkg);
Data.exportPrefs();
Config.set(Config.Key.SU_MANAGER, pkg);
Config.export();
RootUtils.rmAndLaunch(BuildConfig.APPLICATION_ID, pkg);
return true;

View File

@@ -10,8 +10,7 @@ import android.text.TextUtils;
import android.widget.Toast;
import com.topjohnwu.core.App;
import com.topjohnwu.core.Const;
import com.topjohnwu.core.Data;
import com.topjohnwu.core.Config;
import com.topjohnwu.core.container.Policy;
import com.topjohnwu.core.container.SuLogEntry;
import com.topjohnwu.core.utils.Utils;
@@ -123,7 +122,8 @@ public abstract class SuConnector {
private static void handleNotify(Policy policy) {
String message = App.self.getString(policy.policy == Policy.ALLOW ?
R.string.su_allow_toast : R.string.su_deny_toast, policy.appName);
if (policy.notification && Data.suNotificationType == Const.Value.NOTIFICATION_TOAST)
if (policy.notification &&
(int) Config.get(Config.Key.SU_NOTIFICATION) == Config.Value.NOTIFICATION_TOAST)
Utils.toast(message, Toast.LENGTH_SHORT);
}