WifiDiagnostics: require verbose mode for ringbuffers
Only enable ringbuffers if the user has enabled verbose
mode via developer options. This is due to the CPU load
required to push the ringbuffers up to the framework,
with the current ringbuffer HAL.
Along the way:
1) Update some test comments to reflect new behavior
2) Remove unnecessary local variable in existing test
Bug: 68283533
Test: runtests.sh -e class com.android.server.wifi.WifiDiagnosticsTest (on walleye)
Manual Test:
- (enable verbose mode)
$ adb shell reboot
$ adb shell bugreport >/tmp/foo.bug 2>/dev/null; </tmp/foo.bug grep --text -A1 ring-buffer | egrep -v '^ring-buffer|^--$|^$' | wc -l
4
Manual Test:
- (disable verbose mode)
$ adb shell reboot
$ adb shell bugreport >/tmp/foo.bug 2>/dev/null; </tmp/foo.bug grep --text -A1 ring-buffer | egrep -v '^ring-buffer|^--$|^$' | wc -l
0
Change-Id: I3d68a80cb298ffee1b00cbc9b8c7756d08a7a943
diff --git a/service/java/com/android/server/wifi/WifiDiagnostics.java b/service/java/com/android/server/wifi/WifiDiagnostics.java
index 921faa3..30294bd 100644
--- a/service/java/com/android/server/wifi/WifiDiagnostics.java
+++ b/service/java/com/android/server/wifi/WifiDiagnostics.java
@@ -454,6 +454,10 @@
return false;
}
+ if (!isVerboseLoggingEnabled()) {
+ return false;
+ }
+
for (WifiNative.RingBufferStatus buffer : mRingBuffers){
if ((buffer.flag & RING_BUFFER_FLAG_HAS_PER_PACKET_ENTRIES) != 0) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
index 6b93e05..f607b33 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.AdditionalMatchers.gt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.contains;
import static org.mockito.Mockito.anyInt;
@@ -119,7 +120,7 @@
/** Verifies that startLogging() registers a logging event handler. */
@Test
public void startLoggingRegistersLogEventHandler() throws Exception {
- final boolean verbosityToggle = false; // even default mode wants log events from HAL
+ final boolean verbosityToggle = false; // even default mode registers handler
mWifiDiagnostics.startLogging(verbosityToggle);
verify(mWifiNative).setLoggingEventHandler(anyObject());
}
@@ -131,7 +132,7 @@
@Test
public void startLoggingRegistersLogEventHandlerIfPriorAttemptFailed()
throws Exception {
- final boolean verbosityToggle = false; // even default mode wants log events from HAL
+ final boolean verbosityToggle = false; // even default mode registers handler
when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(false);
mWifiDiagnostics.startLogging(verbosityToggle);
@@ -147,7 +148,7 @@
@Test
public void startLoggingDoesNotRegisterLogEventHandlerIfPriorAttemptSucceeded()
throws Exception {
- final boolean verbosityToggle = false; // even default mode wants log events from HAL
+ final boolean verbosityToggle = false; // even default mode registers handler
when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true);
mWifiDiagnostics.startLogging(verbosityToggle);
@@ -166,19 +167,32 @@
* b) instructs WifiNative to enable ring buffers of the appropriate log level.
*/
@Test
- public void startLoggingStopsAndRestartsRingBufferLogging() throws Exception {
- final boolean verbosityToggle = false;
+ public void startLoggingStopsAndRestartsRingBufferLoggingInVerboseMode() throws Exception {
+ final boolean verbosityToggle = true;
setBuildPropertiesToEnableRingBuffers();
mWifiDiagnostics.startLogging(verbosityToggle);
verify(mWifiNative).startLoggingRingBuffer(
eq(WifiDiagnostics.VERBOSE_NO_LOG), anyInt(), anyInt(), anyInt(),
eq(FAKE_RING_BUFFER_NAME));
verify(mWifiNative).startLoggingRingBuffer(
- eq(WifiDiagnostics.VERBOSE_NORMAL_LOG), anyInt(), anyInt(), anyInt(),
+ eq(WifiDiagnostics.VERBOSE_LOG_WITH_WAKEUP), anyInt(), anyInt(), anyInt(),
eq(FAKE_RING_BUFFER_NAME));
}
@Test
+ public void startLoggingStopsButDoesNotStartRingBufferLoggingInNormalMode() throws Exception {
+ final boolean verbosityToggle = false;
+ setBuildPropertiesToEnableRingBuffers();
+ mWifiDiagnostics.startLogging(verbosityToggle);
+ verify(mWifiNative).startLoggingRingBuffer(
+ eq(WifiDiagnostics.VERBOSE_NO_LOG), anyInt(), anyInt(), anyInt(),
+ eq(FAKE_RING_BUFFER_NAME));
+ verify(mWifiNative, never()).startLoggingRingBuffer(
+ gt(WifiDiagnostics.VERBOSE_NO_LOG), anyInt(), anyInt(), anyInt(),
+ anyString());
+ }
+
+ @Test
public void startLoggingDoesNotStartRingBuffersOnUserBuilds() throws Exception {
final boolean verbosityToggle = true;
mWifiDiagnostics.startLogging(verbosityToggle);
@@ -189,7 +203,7 @@
/** Verifies that, if a log handler was registered, then stopLogging() resets it. */
@Test
public void stopLoggingResetsLogHandlerIfHandlerWasRegistered() throws Exception {
- final boolean verbosityToggle = false; // even default mode wants log events from HAL
+ final boolean verbosityToggle = false; // even default mode registers handler
when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true);
mWifiDiagnostics.startLogging(verbosityToggle);
@@ -202,7 +216,6 @@
/** Verifies that, if a log handler is not registered, stopLogging() skips resetLogHandler(). */
@Test
public void stopLoggingOnlyResetsLogHandlerIfHandlerWasRegistered() throws Exception {
- final boolean verbosityToggle = false; // even default mode wants log events from HAL
mWifiDiagnostics.stopLogging();
verify(mWifiNative, never()).resetLogHandler();
}
@@ -210,7 +223,7 @@
/** Verifies that stopLogging() remembers that we've reset the log handler. */
@Test
public void multipleStopLoggingCallsOnlyResetLogHandlerOnce() throws Exception {
- final boolean verbosityToggle = false; // even default mode wants log events from HAL
+ final boolean verbosityToggle = false; // even default mode registers handler
when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true);
mWifiDiagnostics.startLogging(verbosityToggle);