2016-09-29 20:18:41 +00:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
2017-07-01 10:06:23 +00:00
|
|
|
import android.os.Build;
|
2016-09-29 20:18:41 +00:00
|
|
|
import android.os.Bundle;
|
2017-01-28 14:02:33 +00:00
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.PreferenceCategory;
|
2016-09-29 20:18:41 +00:00
|
|
|
import android.preference.PreferenceFragment;
|
|
|
|
import android.preference.PreferenceManager;
|
2017-01-27 22:13:07 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
2017-07-01 10:06:23 +00:00
|
|
|
import android.preference.SwitchPreference;
|
2016-09-29 20:18:41 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
2016-11-08 21:17:50 +00:00
|
|
|
import android.widget.Toast;
|
2016-09-29 20:18:41 +00:00
|
|
|
|
2017-02-06 18:01:32 +00:00
|
|
|
import com.topjohnwu.magisk.components.Activity;
|
2017-05-31 19:18:41 +00:00
|
|
|
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
2017-07-22 14:14:02 +00:00
|
|
|
import com.topjohnwu.magisk.utils.CallbackEvent;
|
2016-09-29 20:18:41 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Logger;
|
2016-11-08 21:17:50 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Shell;
|
2016-09-29 20:18:41 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
|
|
|
|
2017-07-22 14:14:02 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2016-09-29 20:18:41 +00:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
2017-02-06 18:01:32 +00:00
|
|
|
public class SettingsActivity extends Activity {
|
2016-09-29 20:18:41 +00:00
|
|
|
|
|
|
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-02-17 00:51:51 +00:00
|
|
|
if (getApplicationContext().isDarkTheme) {
|
2017-05-26 10:20:53 +00:00
|
|
|
setTheme(R.style.AppTheme_Transparent_Dark);
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 10:20:53 +00:00
|
|
|
setContentView(R.layout.activity_settings);
|
2016-09-29 20:18:41 +00:00
|
|
|
ButterKnife.bind(this);
|
|
|
|
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
toolbar.setNavigationOnClickListener(view -> finish());
|
|
|
|
|
|
|
|
ActionBar ab = getSupportActionBar();
|
|
|
|
if (ab != null) {
|
|
|
|
ab.setTitle(R.string.settings);
|
|
|
|
ab.setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
setFloating();
|
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
getFragmentManager().beginTransaction().add(R.id.container, new SettingsFragment()).commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-11 12:38:15 +00:00
|
|
|
public static class SettingsFragment extends PreferenceFragment
|
2017-07-22 14:14:02 +00:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
2017-07-22 16:12:15 +00:00
|
|
|
CallbackEvent.Listener {
|
2016-09-29 20:18:41 +00:00
|
|
|
|
2016-12-11 12:38:15 +00:00
|
|
|
private SharedPreferences prefs;
|
2017-01-27 22:13:07 +00:00
|
|
|
private PreferenceScreen prefScreen;
|
2016-09-29 20:18:41 +00:00
|
|
|
|
2017-06-08 14:27:24 +00:00
|
|
|
private ListPreference suAccess, autoRes, suNotification, requestTimeout, multiuserMode, namespaceMode;
|
2017-05-26 18:41:24 +00:00
|
|
|
private MagiskManager magiskManager;
|
2017-07-22 14:14:02 +00:00
|
|
|
private PreferenceCategory generalCatagory;
|
2017-02-06 18:01:32 +00:00
|
|
|
|
2016-09-29 20:18:41 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-10-17 02:11:26 +00:00
|
|
|
addPreferencesFromResource(R.xml.app_settings);
|
2016-12-11 12:38:15 +00:00
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
2017-01-27 22:13:07 +00:00
|
|
|
prefScreen = getPreferenceScreen();
|
2017-05-26 18:41:24 +00:00
|
|
|
magiskManager = Utils.getMagiskManager(getActivity());
|
2016-09-29 20:18:41 +00:00
|
|
|
|
2017-07-22 14:14:02 +00:00
|
|
|
generalCatagory = (PreferenceCategory) findPreference("general");
|
2017-01-28 14:02:33 +00:00
|
|
|
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
|
|
|
|
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
|
2017-05-11 18:25:07 +00:00
|
|
|
PreferenceCategory developer = (PreferenceCategory) findPreference("developer");
|
2017-01-28 14:02:33 +00:00
|
|
|
|
2017-01-29 08:20:41 +00:00
|
|
|
suAccess = (ListPreference) findPreference("su_access");
|
|
|
|
autoRes = (ListPreference) findPreference("su_auto_response");
|
|
|
|
requestTimeout = (ListPreference) findPreference("su_request_timeout");
|
|
|
|
suNotification = (ListPreference) findPreference("su_notification");
|
2017-05-26 18:41:24 +00:00
|
|
|
multiuserMode = (ListPreference) findPreference("multiuser_mode");
|
2017-06-08 14:27:24 +00:00
|
|
|
namespaceMode = (ListPreference) findPreference("mnt_ns");
|
2017-07-01 10:06:23 +00:00
|
|
|
SwitchPreference reauth = (SwitchPreference) findPreference("su_reauth");
|
2017-01-28 14:02:33 +00:00
|
|
|
|
2017-01-29 08:20:41 +00:00
|
|
|
setSummary();
|
2017-01-28 14:02:33 +00:00
|
|
|
|
2017-05-27 16:16:10 +00:00
|
|
|
// Disable dangerous settings in user mode if selected owner manage
|
|
|
|
if (getActivity().getApplicationInfo().uid > 99999) {
|
|
|
|
prefScreen.removePreference(magiskCategory);
|
|
|
|
prefScreen.removePreference(suCategory);
|
|
|
|
}
|
|
|
|
|
2017-07-01 10:06:23 +00:00
|
|
|
// Remove re-authentication option on Android O, it will not work
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
suCategory.removePreference(reauth);
|
|
|
|
}
|
|
|
|
|
2017-01-28 14:02:33 +00:00
|
|
|
findPreference("clear").setOnPreferenceClickListener((pref) -> {
|
2017-02-12 12:53:41 +00:00
|
|
|
Utils.clearRepoCache(getActivity());
|
2017-01-11 11:10:30 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2017-05-11 18:25:07 +00:00
|
|
|
if (!BuildConfig.DEBUG) {
|
|
|
|
prefScreen.removePreference(developer);
|
|
|
|
}
|
|
|
|
|
2017-01-25 20:17:51 +00:00
|
|
|
if (!Shell.rootAccess()) {
|
2017-01-28 14:02:33 +00:00
|
|
|
prefScreen.removePreference(magiskCategory);
|
|
|
|
prefScreen.removePreference(suCategory);
|
2016-09-29 20:18:41 +00:00
|
|
|
} else {
|
2017-05-26 18:41:24 +00:00
|
|
|
if (!magiskManager.isSuClient) {
|
2017-01-28 14:02:33 +00:00
|
|
|
prefScreen.removePreference(suCategory);
|
2017-02-20 19:30:37 +00:00
|
|
|
}
|
2017-06-07 19:20:04 +00:00
|
|
|
if (magiskManager.magiskVersionCode < 1300) {
|
2017-02-01 15:54:32 +00:00
|
|
|
prefScreen.removePreference(magiskCategory);
|
2017-02-20 19:30:37 +00:00
|
|
|
}
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 14:14:02 +00:00
|
|
|
private ListPreference setLocalePreference(ListPreference lp) {
|
|
|
|
if (lp == null) {
|
|
|
|
lp = new ListPreference(getActivity());
|
|
|
|
}
|
|
|
|
CharSequence[] entries = new CharSequence[magiskManager.locales.size() + 1];
|
|
|
|
CharSequence[] entryValues = new CharSequence[magiskManager.locales.size() + 1];
|
|
|
|
entries[0] = getString(R.string.system_default);
|
|
|
|
entryValues[0] = "";
|
|
|
|
int i = 1;
|
|
|
|
for (Locale locale : magiskManager.locales) {
|
|
|
|
entries[i] = locale.getDisplayName(locale);
|
|
|
|
entryValues[i++] = locale.toLanguageTag();
|
|
|
|
}
|
|
|
|
lp.setEntries(entries);
|
|
|
|
lp.setEntryValues(entryValues);
|
|
|
|
lp.setTitle(R.string.language);
|
|
|
|
lp.setKey("locale");
|
|
|
|
lp.setSummary(MagiskManager.locale.getDisplayName(MagiskManager.locale));
|
|
|
|
return lp;
|
|
|
|
}
|
|
|
|
|
2016-09-29 20:18:41 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2016-12-11 12:38:15 +00:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2017-07-22 16:12:15 +00:00
|
|
|
registerEvents();
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-26 05:46:54 +00:00
|
|
|
public void onPause() {
|
2016-12-11 12:38:15 +00:00
|
|
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
2017-07-22 16:12:15 +00:00
|
|
|
unregisterEvents();
|
|
|
|
super.onPause();
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-11 12:38:15 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2016-09-29 20:18:41 +00:00
|
|
|
Logger.dev("Settings: Prefs change " + key);
|
2017-01-27 22:13:07 +00:00
|
|
|
boolean enabled;
|
2016-09-29 20:18:41 +00:00
|
|
|
|
|
|
|
switch (key) {
|
2017-01-25 20:17:51 +00:00
|
|
|
case "dark_theme":
|
2017-01-27 22:13:07 +00:00
|
|
|
enabled = prefs.getBoolean("dark_theme", false);
|
2017-05-26 18:41:24 +00:00
|
|
|
if (magiskManager.isDarkTheme != enabled) {
|
|
|
|
magiskManager.isDarkTheme = enabled;
|
2017-07-22 16:12:15 +00:00
|
|
|
magiskManager.reloadMainActivity.trigger(false);
|
2017-02-20 19:30:37 +00:00
|
|
|
getActivity().recreate();
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-02 11:19:22 +00:00
|
|
|
case "disable":
|
|
|
|
enabled = prefs.getBoolean("disable", false);
|
2017-06-05 19:06:23 +00:00
|
|
|
if (enabled) {
|
2017-07-17 19:34:06 +00:00
|
|
|
Utils.createFile(magiskManager.shell, MagiskManager.MAGISK_DISABLE_FILE);
|
2017-06-05 19:06:23 +00:00
|
|
|
} else {
|
2017-07-17 19:34:06 +00:00
|
|
|
Utils.removeItem(magiskManager.shell, MagiskManager.MAGISK_DISABLE_FILE);
|
2017-06-05 19:06:23 +00:00
|
|
|
}
|
2017-02-02 11:19:22 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
2016-10-17 02:11:26 +00:00
|
|
|
break;
|
2017-02-02 11:19:22 +00:00
|
|
|
case "magiskhide":
|
|
|
|
enabled = prefs.getBoolean("magiskhide", false);
|
2017-02-05 14:30:14 +00:00
|
|
|
if (enabled) {
|
2017-07-20 21:08:39 +00:00
|
|
|
Utils.enableMagiskHide(magiskManager.shell);
|
2017-02-20 19:30:37 +00:00
|
|
|
} else {
|
2017-07-20 21:08:39 +00:00
|
|
|
Utils.disableMagiskHide(magiskManager.shell);
|
2017-02-20 19:30:37 +00:00
|
|
|
}
|
2017-02-02 11:19:22 +00:00
|
|
|
break;
|
2016-11-08 21:17:50 +00:00
|
|
|
case "hosts":
|
2017-01-27 22:13:07 +00:00
|
|
|
enabled = prefs.getBoolean("hosts", false);
|
2017-06-05 19:06:23 +00:00
|
|
|
if (enabled) {
|
2017-07-17 19:34:06 +00:00
|
|
|
magiskManager.shell.su_raw(
|
2017-06-05 19:06:23 +00:00
|
|
|
"cp -af /system/etc/hosts /magisk/.core/hosts",
|
|
|
|
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
|
|
|
} else {
|
2017-07-17 19:34:06 +00:00
|
|
|
magiskManager.shell.su_raw(
|
2017-06-05 19:06:23 +00:00
|
|
|
"umount -l /system/etc/hosts",
|
|
|
|
"rm -f /magisk/.core/hosts");
|
|
|
|
}
|
2016-09-29 20:18:41 +00:00
|
|
|
break;
|
2017-01-27 22:13:07 +00:00
|
|
|
case "su_access":
|
2017-05-31 19:18:41 +00:00
|
|
|
magiskManager.suAccessState = Utils.getPrefsInt(prefs, "su_access", 3);
|
|
|
|
magiskManager.suDB.setSettings(SuDatabaseHelper.ROOT_ACCESS, magiskManager.suAccessState);
|
2017-01-27 22:13:07 +00:00
|
|
|
break;
|
2017-05-26 18:41:24 +00:00
|
|
|
case "multiuser_mode":
|
|
|
|
magiskManager.multiuserMode = Utils.getPrefsInt(prefs, "multiuser_mode", 0);
|
2017-05-31 19:18:41 +00:00
|
|
|
magiskManager.suDB.setSettings(SuDatabaseHelper.MULTIUSER_MODE, magiskManager.multiuserMode);
|
2017-06-08 14:27:24 +00:00
|
|
|
break;
|
|
|
|
case "mnt_ns":
|
|
|
|
magiskManager.suNamespaceMode = Utils.getPrefsInt(prefs, "mnt_ns", 1);
|
|
|
|
magiskManager.suDB.setSettings(SuDatabaseHelper.MNT_NS, magiskManager.suNamespaceMode);
|
|
|
|
break;
|
2017-01-27 22:13:07 +00:00
|
|
|
case "su_request_timeout":
|
2017-05-26 18:41:24 +00:00
|
|
|
magiskManager.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
|
2017-01-27 22:13:07 +00:00
|
|
|
break;
|
|
|
|
case "su_auto_response":
|
2017-05-26 18:41:24 +00:00
|
|
|
magiskManager.suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
|
2017-01-27 22:13:07 +00:00
|
|
|
break;
|
|
|
|
case "su_notification":
|
2017-05-26 18:41:24 +00:00
|
|
|
magiskManager.suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
|
2017-01-27 22:13:07 +00:00
|
|
|
break;
|
2016-09-29 20:18:41 +00:00
|
|
|
case "developer_logging":
|
2017-02-12 19:12:10 +00:00
|
|
|
MagiskManager.devLogging = prefs.getBoolean("developer_logging", false);
|
2016-09-29 20:18:41 +00:00
|
|
|
break;
|
|
|
|
case "shell_logging":
|
2017-02-12 19:12:10 +00:00
|
|
|
MagiskManager.shellLogging = prefs.getBoolean("shell_logging", false);
|
2016-09-29 20:18:41 +00:00
|
|
|
break;
|
2017-07-22 14:14:02 +00:00
|
|
|
case "locale":
|
|
|
|
magiskManager.setLocale();
|
2017-07-22 16:12:15 +00:00
|
|
|
magiskManager.reloadMainActivity.trigger(false);
|
2017-07-22 14:14:02 +00:00
|
|
|
getActivity().recreate();
|
|
|
|
break;
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
2017-01-29 08:20:41 +00:00
|
|
|
setSummary();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSummary() {
|
|
|
|
suAccess.setSummary(getResources()
|
2017-05-26 18:41:24 +00:00
|
|
|
.getStringArray(R.array.su_access)[magiskManager.suAccessState]);
|
2017-01-29 08:20:41 +00:00
|
|
|
autoRes.setSummary(getResources()
|
2017-05-26 18:41:24 +00:00
|
|
|
.getStringArray(R.array.auto_response)[magiskManager.suResponseType]);
|
2017-01-29 08:20:41 +00:00
|
|
|
suNotification.setSummary(getResources()
|
2017-05-26 18:41:24 +00:00
|
|
|
.getStringArray(R.array.su_notification)[magiskManager.suNotificationType]);
|
2017-01-29 08:20:41 +00:00
|
|
|
requestTimeout.setSummary(
|
|
|
|
getString(R.string.request_timeout_summary, prefs.getString("su_request_timeout", "10")));
|
2017-05-26 18:41:24 +00:00
|
|
|
multiuserMode.setSummary(getResources()
|
|
|
|
.getStringArray(R.array.multiuser_summary)[magiskManager.multiuserMode]);
|
2017-06-08 14:27:24 +00:00
|
|
|
namespaceMode.setSummary(getResources()
|
|
|
|
.getStringArray(R.array.namespace_summary)[magiskManager.suNamespaceMode]);
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
2017-07-22 14:14:02 +00:00
|
|
|
|
|
|
|
@Override
|
2017-07-22 16:12:15 +00:00
|
|
|
public void onTrigger(CallbackEvent event) {
|
2017-07-22 14:14:02 +00:00
|
|
|
ListPreference language = setLocalePreference(null);
|
|
|
|
language.setOnPreferenceClickListener((pref) -> {
|
|
|
|
setLocalePreference((ListPreference) pref);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
generalCatagory.addPreference(language);
|
|
|
|
}
|
2017-07-22 16:12:15 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public CallbackEvent[] getRegisterEvents() {
|
|
|
|
return new CallbackEvent[] { magiskManager.localeDone };
|
|
|
|
}
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|