forked from organicmaps/organicmaps
[android] Made logging of network request safe
This commit is contained in:
parent
8d64c7a011
commit
9b343ad088
3 changed files with 14 additions and 9 deletions
|
@ -88,7 +88,7 @@ public class MiscPrefsFragment extends BaseXmlSettingsFragment
|
|||
boolean newVal = (Boolean) newValue;
|
||||
if (oldVal != newVal)
|
||||
{
|
||||
LoggerFactory.INSTANCE.setFileLoggingEnabled((Boolean) newValue);
|
||||
LoggerFactory.INSTANCE.setFileLoggingEnabled(newVal);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,8 @@ public final class HttpClient
|
|||
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
LOGGER.d("Connecting to ", p.url);
|
||||
logUrlSafely(p.url);
|
||||
|
||||
try
|
||||
{
|
||||
connection = (HttpURLConnection) new URL(p.url).openConnection(); // NullPointerException, MalformedUrlException, IOException
|
||||
|
@ -211,6 +212,12 @@ public final class HttpClient
|
|||
return in;
|
||||
}
|
||||
|
||||
private static void logUrlSafely(@NonNull final String url)
|
||||
{
|
||||
String safeUrl = url.replaceAll("(token|password|key)=([^&]+)", "***");
|
||||
LOGGER.d("Connecting to ", safeUrl);
|
||||
}
|
||||
|
||||
private static class HttpHeader
|
||||
{
|
||||
public HttpHeader(@NonNull String key, @NonNull String value)
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.text.TextUtils;
|
|||
|
||||
import com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.StorageUtils;
|
||||
import net.jcip.annotations.GuardedBy;
|
||||
import net.jcip.annotations.ThreadSafe;
|
||||
|
@ -37,7 +38,6 @@ public class LoggerFactory
|
|||
}
|
||||
|
||||
public final static LoggerFactory INSTANCE = new LoggerFactory();
|
||||
private final static String PREF_FILE_LOGGING_ENABLED = "FileLoggingEnabled";
|
||||
|
||||
@NonNull
|
||||
@GuardedBy("this")
|
||||
|
@ -53,17 +53,14 @@ public class LoggerFactory
|
|||
public boolean isFileLoggingEnabled()
|
||||
{
|
||||
SharedPreferences prefs = MwmApplication.prefs();
|
||||
return prefs.getBoolean(PREF_FILE_LOGGING_ENABLED, false);
|
||||
return prefs.getBoolean(MwmApplication.get().getString(R.string.pref_enable_logging), false);
|
||||
}
|
||||
|
||||
public void setFileLoggingEnabled(boolean enabled)
|
||||
{
|
||||
if (isFileLoggingEnabled() == enabled)
|
||||
return;
|
||||
|
||||
SharedPreferences prefs = MwmApplication.prefs();
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(PREF_FILE_LOGGING_ENABLED, enabled).apply();
|
||||
editor.putBoolean(MwmApplication.get().getString(R.string.pref_enable_logging), enabled).apply();
|
||||
updateLoggers();
|
||||
}
|
||||
|
||||
|
@ -114,7 +111,8 @@ public class LoggerFactory
|
|||
private LoggerStrategy createLoggerStrategy(@NonNull Type type)
|
||||
{
|
||||
SharedPreferences prefs = MwmApplication.prefs();
|
||||
if (prefs.getBoolean(PREF_FILE_LOGGING_ENABLED, BuildConfig.BUILD_TYPE.equals("beta")))
|
||||
String enableLoggingKey = MwmApplication.get().getString(R.string.pref_enable_logging);
|
||||
if (prefs.getBoolean(enableLoggingKey, BuildConfig.BUILD_TYPE.equals("beta")))
|
||||
{
|
||||
String logsFolder = StorageUtils.getLogsFolder();
|
||||
if (!TextUtils.isEmpty(logsFolder))
|
||||
|
|
Loading…
Add table
Reference in a new issue