From aa7ad9b5ee419172f6e0c2037e20c3b525713103 Mon Sep 17 00:00:00 2001 From: vorlon77 <42155352+vorlon77@users.noreply.github.com> Date: Mon, 26 Jun 2023 12:34:09 -0600 Subject: [PATCH] Only log debug messages when DEBUG is True (#453) According to the internal comments and other usage, this message should only be logged when DEBUG is True. The log entry can potentially contain sensitive data in the case where authentication tokens are part of a GET request and so it should be possible for the user of Volley to disable logging by setting DEBUG to False even in the case where the network request is "slow." Fixes #452 --- .../com/android/volley/toolbox/BasicAsyncNetwork.java | 6 +++--- .../java/com/android/volley/toolbox/BasicNetwork.java | 4 ++-- .../java/com/android/volley/toolbox/NetworkUtility.java | 8 +++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/android/volley/toolbox/BasicAsyncNetwork.java b/core/src/main/java/com/android/volley/toolbox/BasicAsyncNetwork.java index cdedaff5..4d6924d3 100644 --- a/core/src/main/java/com/android/volley/toolbox/BasicAsyncNetwork.java +++ b/core/src/main/java/com/android/volley/toolbox/BasicAsyncNetwork.java @@ -16,7 +16,7 @@ package com.android.volley.toolbox; -import static com.android.volley.toolbox.NetworkUtility.logSlowRequests; +import static com.android.volley.toolbox.NetworkUtility.logRequestSummary; import android.os.SystemClock; import androidx.annotation.NonNull; @@ -213,9 +213,9 @@ private void onResponseRead( OnRequestComplete callback, List
responseHeaders, byte[] responseContents) { - // if the request is slow, log it. + // log request when debugging is enabled. long requestLifetime = SystemClock.elapsedRealtime() - requestStartMs; - logSlowRequests(requestLifetime, request, responseContents, statusCode); + logRequestSummary(requestLifetime, request, responseContents, statusCode); if (statusCode < 200 || statusCode > 299) { onRequestFailed( diff --git a/core/src/main/java/com/android/volley/toolbox/BasicNetwork.java b/core/src/main/java/com/android/volley/toolbox/BasicNetwork.java index 552e6286..8cd817ec 100644 --- a/core/src/main/java/com/android/volley/toolbox/BasicNetwork.java +++ b/core/src/main/java/com/android/volley/toolbox/BasicNetwork.java @@ -124,9 +124,9 @@ public NetworkResponse performRequest(Request request) throws VolleyError { responseContents = new byte[0]; } - // if the request is slow, log it. + // log request when debugging is enabled. long requestLifetime = SystemClock.elapsedRealtime() - requestStart; - NetworkUtility.logSlowRequests( + NetworkUtility.logRequestSummary( requestLifetime, request, responseContents, statusCode); if (statusCode < 200 || statusCode > 299) { diff --git a/core/src/main/java/com/android/volley/toolbox/NetworkUtility.java b/core/src/main/java/com/android/volley/toolbox/NetworkUtility.java index 58a3bb3a..5683f160 100644 --- a/core/src/main/java/com/android/volley/toolbox/NetworkUtility.java +++ b/core/src/main/java/com/android/volley/toolbox/NetworkUtility.java @@ -43,14 +43,12 @@ * BasicAsyncNetwork} */ final class NetworkUtility { - private static final int SLOW_REQUEST_THRESHOLD_MS = 3000; - private NetworkUtility() {} - /** Logs requests that took over SLOW_REQUEST_THRESHOLD_MS to complete. */ - static void logSlowRequests( + /** Logs a summary about the request when debug logging is enabled. */ + static void logRequestSummary( long requestLifetime, Request request, byte[] responseContents, int statusCode) { - if (VolleyLog.DEBUG || requestLifetime > SLOW_REQUEST_THRESHOLD_MS) { + if (VolleyLog.DEBUG) { VolleyLog.d( "HTTP response for request=<%s> [lifetime=%d], [size=%s], " + "[rc=%d], [retryCount=%s]",