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) { 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); Set<String> blackListSet = prefs.getStringSet("auto_blacklist", null);
assert blackListSet != null; assert blackListSet != null;
arrayBlackList = new ArrayList<>(blackListSet); 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(); 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); setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { 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); mDrawerHandler.removeCallbacksAndMessages(null);
navigate(mSelectedId); navigate(mSelectedId);
} }
@Override @Override
@ -166,15 +116,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (drawer.isDrawerOpen(GravityCompat.START)) { if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
} else { } else {
int backStackEntryCount = getFragmentManager().getBackStackEntryCount(); finish();
Logger.dev("Welcomeactivity: Entrycount is " + backStackEntryCount);
if (backStackEntryCount >= 2) {
super.onBackPressed();
} else {
finish();
}
} }
} }
@Override @Override

View File

@ -22,7 +22,6 @@ import com.topjohnwu.magisk.utils.Utils;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private CheckBoxPreference quickTilePreference, busyboxPreference;
private ListPreference themePreference; private ListPreference themePreference;
@Override @Override
@ -51,8 +50,8 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
themePreference = (ListPreference) findPreference("theme"); themePreference = (ListPreference) findPreference("theme");
busyboxPreference = (CheckBoxPreference) findPreference("busybox"); CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile") ; CheckBoxPreference quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile");
busyboxPreference.setChecked(Utils.commandExists("unzip")); busyboxPreference.setChecked(Utils.commandExists("unzip"));
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this);
CheckBoxPreference keepRootOffPreference = (CheckBoxPreference) findPreference("keep_root_off"); CheckBoxPreference keepRootOffPreference = (CheckBoxPreference) findPreference("keep_root_off");
@ -62,10 +61,12 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
quickTilePreference.setEnabled(false); quickTilePreference.setEnabled(false);
keepRootOffPreference.setEnabled(false); keepRootOffPreference.setEnabled(false);
hideRootNotificationPreference.setEnabled(false); hideRootNotificationPreference.setEnabled(false);
busyboxPreference.setEnabled(false);
} else { } else {
quickTilePreference.setEnabled(true); quickTilePreference.setEnabled(true);
keepRootOffPreference.setEnabled(true); keepRootOffPreference.setEnabled(true);
hideRootNotificationPreference.setEnabled(true); hideRootNotificationPreference.setEnabled(true);
busyboxPreference.setEnabled(true);
} }
// calculate margins // calculate margins
@ -142,6 +143,10 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
} else if (key.equals("busybox")) { } else if (key.equals("busybox")) {
boolean checked = sharedPreferences.getBoolean("busybox", false); boolean checked = sharedPreferences.getBoolean("busybox", false);
new Async.LinkBusyBox(checked).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); 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); 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. // Set up default preferences,make sure we add "extra" blacklist entries.
if (!defaultPrefs.contains("auto_blacklist")) { if (!defaultPrefs.contains("auto_blacklist")) {
Logger.dev("SplashActivity: Setting default preferences for application"); Logger.dev("SplashActivity: Setting default preferences for application");

View File

@ -1,24 +1,15 @@
package com.topjohnwu.magisk.utils; package com.topjohnwu.magisk.utils;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
public class Logger { public class Logger {
private static final String LOG_TAG = "Magisk: DEV"; 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) { public static void dev(String msg, Object... args) {
Context context = null; if (devLog) {
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
if (args.length == 1 && args[0] instanceof Throwable) { if (args.length == 1 && args[0] instanceof Throwable) {
Log.d(LOG_TAG, msg, (Throwable) args[0]); Log.d(LOG_TAG, msg, (Throwable) args[0]);
} else { } else {
@ -28,13 +19,7 @@ public class Logger {
} }
public static void dev(String msg) { public static void dev(String msg) {
Context context = null; if (devLog) {
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
Log.d(LOG_TAG, msg); Log.d(LOG_TAG, msg);
} }
} }
@ -44,9 +29,4 @@ public class Logger {
Log.d(root ? "SU" : "SH", msg); 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_development_category">Development</string>
<string name="settings_developer_logging_title">Enable advanced debug logging</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_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> </resources>

View File

@ -57,6 +57,12 @@
android:title="@string/settings_developer_logging_title" android:title="@string/settings_developer_logging_title"
android:summary="@string/settings_developer_logging_summary" /> 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> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>