From 21504f132932d5cbf1cc554cbd6900fea2a941ef Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 30 Sep 2016 11:35:46 +0800 Subject: [PATCH] Add settings for shell logging --- .../topjohnwu/magisk/AutoRootFragment.java | 2 +- .../com/topjohnwu/magisk/MainActivity.java | 59 +------------------ .../topjohnwu/magisk/SettingsFragment.java | 11 +++- .../com/topjohnwu/magisk/SplashActivity.java | 3 + .../com/topjohnwu/magisk/utils/Logger.java | 26 +------- app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/uisettings.xml | 6 ++ 7 files changed, 24 insertions(+), 85 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java b/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java index 7a35c8784..ff6691c30 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java @@ -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 blackListSet = prefs.getStringSet("auto_blacklist", null); assert blackListSet != null; arrayBlackList = new ArrayList<>(blackListSet); diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index ac07e9432..5a1198b71 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java index 7dcbed811..2b2d33972 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java @@ -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); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 302abc7ee..a9fafc004 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -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"); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java index 066abb5af..b1861ec8d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java @@ -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); - } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 560bd492e..7aea07243 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -130,5 +130,7 @@ Development Enable advanced debug logging Check this to enable more verbose logging. + Enable shell command debug logging + Check this to enable logging all shell commands and output diff --git a/app/src/main/res/xml/uisettings.xml b/app/src/main/res/xml/uisettings.xml index 9b3797708..19157c3b4 100644 --- a/app/src/main/res/xml/uisettings.xml +++ b/app/src/main/res/xml/uisettings.xml @@ -57,6 +57,12 @@ android:title="@string/settings_developer_logging_title" android:summary="@string/settings_developer_logging_summary" /> + + \ No newline at end of file