Add settings for shell logging

This commit is contained in:
topjohnwu 2016-09-30 11:35:46 +08:00
parent ff6bae936d
commit 21504f1329
7 changed files with 24 additions and 85 deletions

View File

@ -84,7 +84,7 @@ public class AutoRootFragment extends ListFragment {
}
private void ToggleApp(String appToCheck, int position, View v) {
Logger.dev("Magisk","AutoRootFragment: ToggleApp called for " + appToCheck);
Logger.dev("Magisk", "AutoRootFragment: ToggleApp called for " + appToCheck);
Set<String> blackListSet = prefs.getStringSet("auto_blacklist", null);
assert blackListSet != null;
arrayBlackList = new ArrayList<>(blackListSet);

View File

@ -63,53 +63,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Snackbar.make(findViewById(android.R.id.content), R.string.no_root_access, Snackbar.LENGTH_LONG).show();
}
this.getFragmentManager().addOnBackStackChangedListener(
() -> {
Fragment hm = getFragmentManager().findFragmentByTag("root");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.root);
}
}
hm = getFragmentManager().findFragmentByTag("autoroot");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.autoroot);
}
}
hm = getFragmentManager().findFragmentByTag("magisk");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.magisk);
}
}
hm = getFragmentManager().findFragmentByTag("modules");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.modules);
}
}
hm = getFragmentManager().findFragmentByTag("downloads");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.downloads);
}
}
hm = getFragmentManager().findFragmentByTag("log");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.log);
}
}
hm = getFragmentManager().findFragmentByTag("settings");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.settings);
}
}
}
);
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@ -146,11 +99,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
mDrawerHandler.removeCallbacksAndMessages(null);
navigate(mSelectedId);
}
@Override
@ -166,15 +116,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
int backStackEntryCount = getFragmentManager().getBackStackEntryCount();
Logger.dev("Welcomeactivity: Entrycount is " + backStackEntryCount);
if (backStackEntryCount >= 2) {
super.onBackPressed();
} else {
finish();
}
finish();
}
}
@Override

View File

@ -22,7 +22,6 @@ import com.topjohnwu.magisk.utils.Utils;
import butterknife.ButterKnife;
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private CheckBoxPreference quickTilePreference, busyboxPreference;
private ListPreference themePreference;
@Override
@ -51,8 +50,8 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
themePreference = (ListPreference) findPreference("theme");
busyboxPreference = (CheckBoxPreference) findPreference("busybox");
quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile") ;
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
CheckBoxPreference quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile");
busyboxPreference.setChecked(Utils.commandExists("unzip"));
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this);
CheckBoxPreference keepRootOffPreference = (CheckBoxPreference) findPreference("keep_root_off");
@ -62,10 +61,12 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
quickTilePreference.setEnabled(false);
keepRootOffPreference.setEnabled(false);
hideRootNotificationPreference.setEnabled(false);
busyboxPreference.setEnabled(false);
} else {
quickTilePreference.setEnabled(true);
keepRootOffPreference.setEnabled(true);
hideRootNotificationPreference.setEnabled(true);
busyboxPreference.setEnabled(true);
}
// calculate margins
@ -142,6 +143,10 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
} else if (key.equals("busybox")) {
boolean checked = sharedPreferences.getBoolean("busybox", false);
new Async.LinkBusyBox(checked).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
} else if (key.equals("developer_logging")) {
Logger.devLog = sharedPreferences.getBoolean("developer_logging", false);
} else if (key.equals("shell_logging")) {
Logger.logShell = sharedPreferences.getBoolean("shell_logging", false);
}
}

View File

@ -25,6 +25,9 @@ public class SplashActivity extends AppCompatActivity {
setTheme(R.style.AppTheme_dh);
}
Logger.devLog = defaultPrefs.getBoolean("developer_logging", false);
Logger.logShell = defaultPrefs.getBoolean("shell_logging", false);
// Set up default preferences,make sure we add "extra" blacklist entries.
if (!defaultPrefs.contains("auto_blacklist")) {
Logger.dev("SplashActivity: Setting default preferences for application");

View File

@ -1,24 +1,15 @@
package com.topjohnwu.magisk.utils;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;
public class Logger {
private static final String LOG_TAG = "Magisk: DEV";
private static final boolean logShell = true;
public static boolean logShell, devLog;
public static void dev(String msg, Object... args) {
Context context = null;
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
if (devLog) {
if (args.length == 1 && args[0] instanceof Throwable) {
Log.d(LOG_TAG, msg, (Throwable) args[0]);
} else {
@ -28,13 +19,7 @@ public class Logger {
}
public static void dev(String msg) {
Context context = null;
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
if (devLog) {
Log.d(LOG_TAG, msg);
}
}
@ -44,9 +29,4 @@ public class Logger {
Log.d(root ? "SU" : "SH", msg);
}
}
private static Application getApplicationUsingReflection() throws Exception {
return (Application) Class.forName("android.app.AppGlobals")
.getMethod("getInitialApplication").invoke(null, (Object[]) null);
}
}

View File

@ -130,5 +130,7 @@
<string name="settings_development_category">Development</string>
<string name="settings_developer_logging_title">Enable advanced debug logging</string>
<string name="settings_developer_logging_summary">Check this to enable more verbose logging.</string>
<string name="settings_shell_logging_title">Enable shell command debug logging</string>
<string name="settings_shell_logging_summary">Check this to enable logging all shell commands and output</string>
</resources>

View File

@ -57,6 +57,12 @@
android:title="@string/settings_developer_logging_title"
android:summary="@string/settings_developer_logging_summary" />
<CheckBoxPreference
android:key="shell_logging"
android:defaultValue="false"
android:title="@string/settings_shell_logging_title"
android:summary="@string/settings_shell_logging_summary" />
</PreferenceCategory>
</PreferenceScreen>