2016-09-29 20:18:41 +00:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.CheckBoxPreference;
|
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-01-25 20:17:51 +00:00
|
|
|
import android.preference.SwitchPreference;
|
2016-09-29 20:18:41 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
import android.view.WindowManager;
|
2016-11-08 21:17:50 +00:00
|
|
|
import android.widget.Toast;
|
2016-09-29 20:18:41 +00:00
|
|
|
|
2017-01-24 20:27:05 +00:00
|
|
|
import com.topjohnwu.magisk.module.ModuleHelper;
|
2016-09-29 20:18:41 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Async;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
|
|
|
public class SettingsActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-01-25 05:16:50 +00:00
|
|
|
if (Global.Configs.isDarkTheme) {
|
2016-09-29 20:18:41 +00:00
|
|
|
setTheme(R.style.AppTheme_dh);
|
|
|
|
}
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_container);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFloating() {
|
|
|
|
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
|
|
|
if (isTablet) {
|
|
|
|
WindowManager.LayoutParams params = getWindow().getAttributes();
|
|
|
|
params.height = getResources().getDimensionPixelSize(R.dimen.floating_height);
|
|
|
|
params.width = getResources().getDimensionPixelSize(R.dimen.floating_width);
|
|
|
|
params.alpha = 1.0f;
|
|
|
|
params.dimAmount = 0.6f;
|
|
|
|
params.flags |= 2;
|
|
|
|
getWindow().setAttributes(params);
|
|
|
|
setFinishOnTouchOutside(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 12:38:15 +00:00
|
|
|
public static class SettingsFragment extends PreferenceFragment
|
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
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-01-29 08:20:41 +00:00
|
|
|
private ListPreference suAccess, autoRes, suNotification, requestTimeout;
|
|
|
|
|
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();
|
2016-09-29 20:18:41 +00:00
|
|
|
|
2017-01-28 14:02:33 +00:00
|
|
|
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
|
|
|
|
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
|
|
|
|
|
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-01-28 14:02:33 +00:00
|
|
|
|
2017-01-29 08:20:41 +00:00
|
|
|
setSummary();
|
2017-01-28 14:02:33 +00:00
|
|
|
|
|
|
|
findPreference("clear").setOnPreferenceClickListener((pref) -> {
|
2017-01-25 20:17:51 +00:00
|
|
|
ModuleHelper.clearRepoCache(getActivity());
|
2017-01-11 11:10:30 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
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-02-01 15:54:32 +00:00
|
|
|
if (!Global.Info.isSuClient)
|
2017-01-28 14:02:33 +00:00
|
|
|
prefScreen.removePreference(suCategory);
|
2017-02-01 15:54:32 +00:00
|
|
|
if (Global.Info.magiskVersion < 11)
|
|
|
|
prefScreen.removePreference(magiskCategory);
|
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);
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-26 05:46:54 +00:00
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
2016-12-11 12:38:15 +00:00
|
|
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
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);
|
|
|
|
if (Global.Configs.isDarkTheme != enabled) {
|
|
|
|
Global.Configs.isDarkTheme = enabled;
|
2017-01-11 11:10:30 +00:00
|
|
|
getActivity().recreate();
|
2017-01-24 20:27:05 +00:00
|
|
|
Global.Events.reloadMainActivity.trigger();
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-10-17 02:11:26 +00:00
|
|
|
case "magiskhide":
|
2017-01-27 22:13:07 +00:00
|
|
|
enabled = prefs.getBoolean("magiskhide", false);
|
2017-02-01 15:54:32 +00:00
|
|
|
if (enabled)
|
|
|
|
new Async.MagiskHide().enable();
|
|
|
|
else
|
|
|
|
new Async.MagiskHide().disable();
|
2016-10-17 02:11:26 +00:00
|
|
|
break;
|
2016-09-29 20:18:41 +00:00
|
|
|
case "busybox":
|
2017-01-27 22:13:07 +00:00
|
|
|
enabled = prefs.getBoolean("busybox", false);
|
2017-01-11 11:10:30 +00:00
|
|
|
new Async.RootTask<Void, Void, Void>() {
|
2017-01-27 22:13:07 +00:00
|
|
|
private boolean enable = enabled;
|
2017-01-11 11:10:30 +00:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-02-01 15:54:32 +00:00
|
|
|
if (enable)
|
2016-11-08 21:17:50 +00:00
|
|
|
Utils.createFile("/magisk/.core/busybox/enable");
|
2017-02-01 15:54:32 +00:00
|
|
|
else
|
2016-11-08 21:17:50 +00:00
|
|
|
Utils.removeItem("/magisk/.core/busybox/enable");
|
2017-01-11 11:10:30 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.exec();
|
2016-11-08 21:17:50 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
|
|
|
break;
|
|
|
|
case "hosts":
|
2017-01-27 22:13:07 +00:00
|
|
|
enabled = prefs.getBoolean("hosts", false);
|
2017-01-11 11:10:30 +00:00
|
|
|
new Async.RootTask<Void, Void, Void>() {
|
2017-01-27 22:13:07 +00:00
|
|
|
private boolean enable = enabled;
|
2017-01-11 11:10:30 +00:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... voids) {
|
|
|
|
if (enable) {
|
|
|
|
Shell.su("cp -af /system/etc/hosts /magisk/.core/hosts",
|
|
|
|
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
|
|
|
} else {
|
|
|
|
Shell.su("umount -l /system/etc/hosts",
|
|
|
|
"rm -f /magisk/.core/hosts");
|
2016-11-08 21:17:50 +00:00
|
|
|
}
|
2017-01-11 11:10:30 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.exec();
|
2016-09-29 20:18:41 +00:00
|
|
|
break;
|
2017-01-27 22:13:07 +00:00
|
|
|
case "su_access":
|
|
|
|
Global.Configs.suAccessState = Utils.getPrefsInt(prefs, "su_access", 0);
|
|
|
|
Shell.su("setprop persist.sys.root_access " + Global.Configs.suAccessState);
|
2017-01-29 08:20:41 +00:00
|
|
|
suAccess.setSummary(getResources()
|
|
|
|
.getStringArray(R.array.su_access)[Global.Configs.suAccessState]);
|
2017-01-27 22:13:07 +00:00
|
|
|
break;
|
|
|
|
case "su_request_timeout":
|
|
|
|
Global.Configs.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
|
|
|
|
break;
|
|
|
|
case "su_auto_response":
|
|
|
|
Global.Configs.suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0);
|
|
|
|
break;
|
|
|
|
case "su_notification":
|
|
|
|
Global.Configs.suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1);
|
|
|
|
break;
|
2016-09-29 20:18:41 +00:00
|
|
|
case "developer_logging":
|
2017-01-25 05:16:50 +00:00
|
|
|
Global.Configs.devLogging = prefs.getBoolean("developer_logging", false);
|
2016-09-29 20:18:41 +00:00
|
|
|
break;
|
|
|
|
case "shell_logging":
|
2017-01-25 05:16:50 +00:00
|
|
|
Global.Configs.shellLogging = prefs.getBoolean("shell_logging", false);
|
2016-09-29 20:18:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-29 08:20:41 +00:00
|
|
|
setSummary();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSummary() {
|
|
|
|
suAccess.setSummary(getResources()
|
|
|
|
.getStringArray(R.array.su_access)[Global.Configs.suAccessState]);
|
|
|
|
autoRes.setSummary(getResources()
|
|
|
|
.getStringArray(R.array.auto_response)[Global.Configs.suResponseType]);
|
|
|
|
suNotification.setSummary(getResources()
|
|
|
|
.getStringArray(R.array.su_notification)[Global.Configs.suNotificationType]);
|
|
|
|
requestTimeout.setSummary(
|
|
|
|
getString(R.string.request_timeout_summary, prefs.getString("su_request_timeout", "10")));
|
2016-09-29 20:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|