From cdcdc3c1c8e5a28a74c74d4d219e391300e5a517 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Tue, 19 Feb 2019 08:14:21 +0100 Subject: [PATCH] Add pref to enable verbose logging (#303) * Add prefs: verbose_log, expert_mode * Update prefs in Constants * Add service.AppPrefs * Update fragments to read verbose log pref * Update classes with context or inject to read verbose log pref * Inherit ENABLE_VERBOSE_LOG from RestApi to Completion * Restart whole app if verbose log pref was changed * A line too much * Revert expert mode pref (DELTA REVERT) --- .../syncthingandroid/DaggerComponent.java | 6 ++++ .../activities/SettingsActivity.java | 21 +++++++++++- .../fragments/DeviceListFragment.java | 17 +++++++++- .../fragments/DrawerFragment.java | 22 +++++++++++-- .../fragments/FolderListFragment.java | 17 +++++++++- .../fragments/StatusFragment.java | 17 +++++++++- .../syncthingandroid/http/ApiRequest.java | 5 ++- .../syncthingandroid/model/Completion.java | 6 +++- .../syncthingandroid/service/AppPrefs.java | 32 +++++++++++++++++++ .../syncthingandroid/service/Constants.java | 2 +- .../service/EventProcessor.java | 3 +- .../syncthingandroid/service/RestApi.java | 6 ++-- .../service/RunConditionMonitor.java | 5 +-- .../service/SyncthingRunnable.java | 3 +- .../service/SyncthingService.java | 6 ++-- .../syncthingandroid/util/ConfigXml.java | 4 ++- app/src/main/res/values/strings.xml | 8 +++++ app/src/main/res/xml/app_settings.xml | 15 +++++++++ 18 files changed, 175 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/com/nutomic/syncthingandroid/service/AppPrefs.java diff --git a/app/src/main/java/com/nutomic/syncthingandroid/DaggerComponent.java b/app/src/main/java/com/nutomic/syncthingandroid/DaggerComponent.java index bb2245229..8a805939f 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/DaggerComponent.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/DaggerComponent.java @@ -7,6 +7,9 @@ import com.nutomic.syncthingandroid.activities.MainActivity; import com.nutomic.syncthingandroid.activities.SettingsActivity; import com.nutomic.syncthingandroid.activities.SyncConditionsActivity; +import com.nutomic.syncthingandroid.fragments.DeviceListFragment; +import com.nutomic.syncthingandroid.fragments.FolderListFragment; +import com.nutomic.syncthingandroid.fragments.StatusFragment; import com.nutomic.syncthingandroid.receiver.AppConfigReceiver; import com.nutomic.syncthingandroid.service.RunConditionMonitor; import com.nutomic.syncthingandroid.service.EventProcessor; @@ -31,6 +34,9 @@ public interface DaggerComponent { void inject(FolderActivity activity); void inject(FolderPickerActivity activity); void inject(SyncConditionsActivity activity); + void inject(DeviceListFragment fragment); + void inject(FolderListFragment fragment); + void inject(StatusFragment fragment); void inject(Languages languages); void inject(SyncthingService service); void inject(RunConditionMonitor runConditionMonitor); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index e3c0aec46..20f20f06d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -70,6 +70,8 @@ public class SettingsActivity extends SyncthingActivity { private SettingsFragment mSettingsFragment; + public static final int RESULT_RESTART_APP = 3461; + public static final String EXTRA_OPEN_SUB_PREF_SCREEN = "com.github.catfriend1.syncthingandroid.activities.SettingsActivity.OPEN_SUB_PREF_SCREEN"; @@ -153,6 +155,7 @@ public static class SettingsFragment extends PreferenceFragment private Dialog mCurrentPrefScreenDialog = null; + /* Run conditions */ private Preference mCategoryRunConditions; private ListPreference mPowerSource; private CheckBoxPreference mRunOnMobileData; @@ -332,13 +335,15 @@ public void onActivityCreated(Bundle savedInstanceState) { exportConfig.setOnPreferenceClickListener(this); importConfig.setOnPreferenceClickListener(this); - /* Debugging */ + /* Troubleshooting */ + Preference verboseLog = findPreference(Constants.PREF_VERBOSE_LOG); Preference openIssueTracker = findPreference(KEY_OPEN_ISSUE_TRACKER); Preference debugFacilitiesEnabled = findPreference(Constants.PREF_DEBUG_FACILITIES_ENABLED); Preference environmentVariables = findPreference("environment_variables"); Preference stResetDatabase = findPreference("st_reset_database"); Preference stResetDeltas = findPreference("st_reset_deltas"); + verboseLog.setOnPreferenceClickListener(this); openIssueTracker.setOnPreferenceClickListener(this); debugFacilitiesEnabled.setOnPreferenceChangeListener(this); environmentVariables.setOnPreferenceChangeListener(this); @@ -739,6 +744,20 @@ public boolean onPreferenceChange(Preference preference, Object o) { public boolean onPreferenceClick(Preference preference) { final Intent intent; switch (preference.getKey()) { + case Constants.PREF_VERBOSE_LOG: + new AlertDialog.Builder(getActivity()) + .setTitle(R.string.dialog_settings_restart_app_title) + .setMessage(R.string.dialog_settings_restart_app_question) + .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + getActivity().setResult(RESULT_RESTART_APP); + getActivity().finish(); + }) + .setNegativeButton(android.R.string.no, (dialogInterface, i) -> { + // Revert. + ((CheckBoxPreference) preference).setChecked(!((CheckBoxPreference) preference).isChecked()); + }) + .show(); + return true; case KEY_OPEN_ISSUE_TRACKER: intent = new Intent(getActivity(), WebViewActivity.class); intent.putExtra(WebViewActivity.EXTRA_WEB_URL, getString(R.string.issue_tracker_url)); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java b/app/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java index c19061f0f..53241adb6 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java @@ -1,8 +1,10 @@ package com.nutomic.syncthingandroid.fragments; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.Nullable; import android.support.v4.app.ListFragment; import android.util.Log; import android.view.Menu; @@ -13,10 +15,12 @@ import android.widget.ListView; import com.nutomic.syncthingandroid.R; +import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.activities.DeviceActivity; import com.nutomic.syncthingandroid.activities.MainActivity; import com.nutomic.syncthingandroid.activities.SyncthingActivity; import com.nutomic.syncthingandroid.model.Device; +import com.nutomic.syncthingandroid.service.AppPrefs; import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.SyncthingService; @@ -27,6 +31,8 @@ import java.util.Comparator; import java.util.List; +import javax.inject.Inject; + /** * Displays a list of all existing devices. */ @@ -35,7 +41,9 @@ public class DeviceListFragment extends ListFragment implements SyncthingService private final static String TAG = "DeviceListFragment"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; + + @Inject SharedPreferences mPreferences; /** * Compares devices by name, uses the device ID as fallback if the name is empty @@ -59,6 +67,13 @@ public void run() { private DevicesAdapter mAdapter; private SyncthingService.State mServiceState = SyncthingService.State.INIT; + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ((SyncthingApp) getActivity().getApplication()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); + } + @Override public void setUserVisibleHint(boolean isVisibleToUser) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java b/app/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java index 30f1d501a..de4d62d9d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java @@ -39,6 +39,8 @@ public class DrawerFragment extends Fragment implements SyncthingService.OnServi private static final String TAG = "DrawerFragment"; + private static final int SETTINGS_SCREEN_REQUEST = 3460; + /** * These buttons might be accessible if the screen is big enough * or the user can scroll the drawer to access them. @@ -194,7 +196,7 @@ public void onClick(View v) { mActivity.closeDrawer(); break; case R.id.drawerActionSettings: - startActivity(new Intent(mActivity, SettingsActivity.class)); + startActivityForResult(new Intent(mActivity, SettingsActivity.class), SETTINGS_SCREEN_REQUEST); mActivity.closeDrawer(); break; case R.id.drawerActionExit: @@ -220,12 +222,26 @@ public void onClick(View v) { } } - private void doExit() { + private Boolean doExit() { if (mActivity == null || mActivity.isFinishing()) { - return; + return false; } Log.i(TAG, "Exiting app on user request"); mActivity.stopService(new Intent(mActivity, SyncthingService.class)); mActivity.finish(); + return true; + } + + /** + * Receives result of SettingsActivity. + */ + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + if (requestCode == SETTINGS_SCREEN_REQUEST && resultCode == SettingsActivity.RESULT_RESTART_APP) { + Log.d(TAG, "Got request to restart MainActivity"); + if (doExit()) { + startActivity(new Intent(getActivity(), MainActivity.class)); + } + } } } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java b/app/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java index a79510db1..f870a7db1 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java @@ -1,8 +1,10 @@ package com.nutomic.syncthingandroid.fragments; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.Nullable; import android.support.v4.app.ListFragment; import android.util.Log; import android.view.Menu; @@ -12,10 +14,12 @@ import android.widget.AdapterView; import com.nutomic.syncthingandroid.R; +import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.activities.FolderActivity; import com.nutomic.syncthingandroid.activities.MainActivity; import com.nutomic.syncthingandroid.activities.SyncthingActivity; import com.nutomic.syncthingandroid.model.Folder; +import com.nutomic.syncthingandroid.service.AppPrefs; import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.SyncthingService; @@ -24,6 +28,8 @@ import java.util.List; +import javax.inject.Inject; + /** * Displays a list of all existing folders. */ @@ -32,7 +38,9 @@ public class FolderListFragment extends ListFragment implements SyncthingService private static final String TAG = "FolderListFragment"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; + + @Inject SharedPreferences mPreferences; private Runnable mUpdateListRunnable = new Runnable() { @Override @@ -47,6 +55,13 @@ public void run() { private FoldersAdapter mAdapter; private SyncthingService.State mServiceState = SyncthingService.State.INIT; + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ((SyncthingApp) getActivity().getApplication()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); + } + @Override public void setUserVisibleHint(boolean isVisibleToUser) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/fragments/StatusFragment.java b/app/src/main/java/com/nutomic/syncthingandroid/fragments/StatusFragment.java index 349092469..934d9c84d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/fragments/StatusFragment.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/fragments/StatusFragment.java @@ -1,8 +1,10 @@ package com.nutomic.syncthingandroid.fragments; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.Nullable; import android.support.v4.app.ListFragment; import android.text.TextUtils; import android.util.Log; @@ -16,11 +18,13 @@ import com.google.common.base.Optional; import com.nutomic.syncthingandroid.R; +import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.activities.MainActivity; import com.nutomic.syncthingandroid.activities.SettingsActivity; import com.nutomic.syncthingandroid.activities.SyncthingActivity; import com.nutomic.syncthingandroid.model.Connections; import com.nutomic.syncthingandroid.model.SystemStatus; +import com.nutomic.syncthingandroid.service.AppPrefs; import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.SyncthingService; @@ -32,6 +36,8 @@ import java.util.Map; import java.text.NumberFormat; +import javax.inject.Inject; + /** * Displays why syncthing is running or disabled. */ @@ -39,7 +45,9 @@ public class StatusFragment extends ListFragment implements SyncthingService.OnS private static final String TAG = "StatusFragment"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; + + @Inject SharedPreferences mPreferences; private Runnable mRestApiQueryRunnable = new Runnable() { @Override @@ -70,6 +78,13 @@ public void run() { private String mAnnounceServer = ""; private String mUptime = ""; + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ((SyncthingApp) getActivity().getApplication()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); + } + @Override public void setUserVisibleHint(boolean isVisibleToUser) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java b/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java index f8a5e938d..8b6dd0c7a 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java @@ -18,6 +18,8 @@ import com.android.volley.toolbox.Volley; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; + +import com.nutomic.syncthingandroid.service.AppPrefs; import com.nutomic.syncthingandroid.service.Constants; import java.io.File; @@ -38,7 +40,7 @@ public abstract class ApiRequest { private static final String TAG = "ApiRequest"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; /** * The name of the HTTP header used for the syncthing API key. @@ -77,6 +79,7 @@ private RequestQueue getVolleyQueue() { mUrl = url; mPath = path; mApiKey = apiKey; + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(context); } Uri buildUri(Map params) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/model/Completion.java b/app/src/main/java/com/nutomic/syncthingandroid/model/Completion.java index d223927a4..acdc46dc0 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/model/Completion.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/model/Completion.java @@ -17,11 +17,15 @@ public class Completion { private static final String TAG = "Completion"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; HashMap> deviceFolderMap = new HashMap>(); + public Completion(Boolean enableVerboseLog) { + ENABLE_VERBOSE_LOG = enableVerboseLog; + } + /** * Removes a folder from the cache model. */ diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/AppPrefs.java b/app/src/main/java/com/nutomic/syncthingandroid/service/AppPrefs.java new file mode 100644 index 000000000..198ef9717 --- /dev/null +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/AppPrefs.java @@ -0,0 +1,32 @@ + +package com.nutomic.syncthingandroid.service; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.util.Log; + +/** + * Provides preference getters and setters. + */ +public class AppPrefs { + private static final String TAG = "AppPrefs"; + + private static final Boolean PREF_VERBOSE_LOG_DEFAULT = false; + + public static final boolean getPrefVerboseLog(Context context) { + if (context == null) { + Log.e(TAG, "getPrefVerboseLog: context == null"); + return PREF_VERBOSE_LOG_DEFAULT; + } + return getPrefVerboseLog(PreferenceManager.getDefaultSharedPreferences(context)); + } + + public static final boolean getPrefVerboseLog(SharedPreferences sharedPreferences) { + if (sharedPreferences == null) { + Log.e(TAG, "getPrefVerboseLog: sharedPreferences == null"); + return PREF_VERBOSE_LOG_DEFAULT; + } + return sharedPreferences.getBoolean(Constants.PREF_VERBOSE_LOG, PREF_VERBOSE_LOG_DEFAULT); + } +} diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java index 8d8eb10be..4bd37ee18 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java @@ -33,8 +33,8 @@ public class Constants { public static final String PREF_SUGGEST_NEW_FOLDER_ROOT_DATA = "external_android_data"; public static final String PREF_SUGGEST_NEW_FOLDER_ROOT_MEDIA = "external_android_media"; - // Preferences - Troubleshooting + public static final String PREF_VERBOSE_LOG = "verbose_log"; public static final String PREF_ENVIRONMENT_VARIABLES = "environment_variables"; public static final String PREF_DEBUG_FACILITIES_ENABLED = "debug_facilities_enabled"; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java index 11eb90e49..432f63c0b 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java @@ -38,7 +38,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener private static final String TAG = "EventProcessor"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; /** * Minimum interval in seconds at which the events are polled from syncthing and processed. @@ -62,6 +62,7 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener public EventProcessor(Context context, RestApi restApi) { ((SyncthingApp) context.getApplicationContext()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); mContext = context; mRestApi = restApi; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index 64260dc4c..a1b7f2e45 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -65,7 +65,7 @@ public class RestApi { private static final String TAG = "RestApi"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; /** * Compares folders by labels, uses the folder ID as fallback if the label is empty @@ -143,18 +143,20 @@ public interface OnResultListener2 { /** * Stores the latest result of device and folder completion events. */ - private Completion mCompletion = new Completion(); + private Completion mCompletion; private Gson mGson; public RestApi(Context context, URL url, String apiKey, OnApiAvailableListener apiListener, OnConfigChangedListener configListener) { ((SyncthingApp) context.getApplicationContext()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(context); mContext = context; mUrl = url; mApiKey = apiKey; mOnApiAvailableListener = apiListener; mOnConfigChangedListener = configListener; + mCompletion = new Completion(ENABLE_VERBOSE_LOG); mGson = getGson(); } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java index 153e39f90..d674c665f 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java @@ -39,7 +39,7 @@ public class RunConditionMonitor { private static final String TAG = "RunConditionMonitor"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; private static final String POWER_SOURCE_CHARGER_BATTERY = "ac_and_battery_power"; private static final String POWER_SOURCE_CHARGER = "ac_power"; @@ -111,8 +111,9 @@ private class SyncConditionResult { public RunConditionMonitor(Context context, OnShouldRunChangedListener onShouldRunChangedListener, OnSyncPreconditionChangedListener onSyncPreconditionChangedListener) { - LogV("Created new instance"); ((SyncthingApp) context.getApplicationContext()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); + LogV("Created new instance"); mContext = context; res = mContext.getResources(); mOnShouldRunChangedListener = onShouldRunChangedListener; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java index f9b38eb94..14ff744c8 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java @@ -53,7 +53,7 @@ public class SyncthingRunnable implements Runnable { private static final String TAG_NATIVE = "SyncthingNativeCode"; private static final String TAG_NICE = "SyncthingRunnableIoNice"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; private static final int LOG_FILE_MAX_LINES = 10; private static final AtomicReference mSyncthing = new AtomicReference<>(); @@ -84,6 +84,7 @@ public enum Command { */ public SyncthingRunnable(Context context, Command command) { ((SyncthingApp) context.getApplicationContext()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); mContext = context; // Example: mSyncthingBinary="/data/app/com.github.catfriend1.syncthingandroid.debug-8HsN-IsVtZXc8GrE5-Hepw==/lib/x86/libsyncthing.so" mSyncthingBinary = Constants.getSyncthingBinary(mContext); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java index 5372afedf..9029ad1ec 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java @@ -48,7 +48,7 @@ public class SyncthingService extends Service { private static final String TAG = "SyncthingService"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; /** * Intent action to perform a Syncthing restart. @@ -213,10 +213,11 @@ public enum State { */ @Override public void onCreate() { - LogV("onCreate"); super.onCreate(); PRNGFixes.apply(); ((SyncthingApp) getApplication()).component().inject(this); + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(mPreferences); + LogV("onCreate"); mHandler = new Handler(); /** @@ -521,7 +522,6 @@ private void launchStartupTask(SyncthingRunnable.Command srCommand) { return; } - Log.v(TAG, "Starting syncthing"); onServiceStateChange(State.STARTING); if (mRestApi == null) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index 21bea3bfd..4b19a9361 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -13,6 +13,7 @@ import com.nutomic.syncthingandroid.model.Gui; import com.nutomic.syncthingandroid.model.Options; import com.nutomic.syncthingandroid.R; +import com.nutomic.syncthingandroid.service.AppPrefs; import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.SyncthingRunnable; @@ -61,7 +62,7 @@ public class ConfigXml { private static final String TAG = "ConfigXml"; - private static final Boolean ENABLE_VERBOSE_LOG = false; + private Boolean ENABLE_VERBOSE_LOG = false; public class OpenConfigException extends RuntimeException { } @@ -98,6 +99,7 @@ public interface OnResultListener1 { public ConfigXml(Context context) { mContext = context; + ENABLE_VERBOSE_LOG = AppPrefs.getPrefVerboseLog(context); mConfigFile = Constants.getConfigFile(mContext); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b221693cf..297256ace 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -569,6 +569,10 @@ Please report any problems you encounter via Github. Config was imported Config import failed, make sure files are in %1$s + Restart required + + Changing this option requires an immediate restart of the app. All other changes will be discarded. Continue? + STTRACE Options @@ -601,6 +605,10 @@ Please report any problems you encounter via Github. About + Verbose log + + Enabling this option will help to generate debug logs at a very detailed level. + Open Log diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index dd90d2627..772554709 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -78,12 +78,14 @@ android:key="category_behaviour" android:title="@string/category_behaviour"> + + + + + + + @@ -230,21 +241,25 @@ android:action=".activities.LogActivity" /> + + + +