diff options
-rw-r--r-- | service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java | 18 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java | 25 |
2 files changed, 35 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index c4474890d..e84455834 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -76,20 +76,20 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { private static final int MIN_PERIOD_PER_CHANNEL_MS = 200; // DFS needs 120 ms private static final int UNKNOWN_PID = -1; - private static final LocalLog mLocalLog = new LocalLog(1024); + private final LocalLog mLocalLog = new LocalLog(1024); private final WifiMetrics mWifiMetrics; - private static void localLog(String message) { + private void localLog(String message) { mLocalLog.log(message); } - private static void logw(String message) { + private void logw(String message) { Log.w(TAG, message); mLocalLog.log(message); } - private static void loge(String message) { + private void loge(String message) { Log.e(TAG, message); mLocalLog.log(message); } @@ -307,7 +307,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { return workSource != null && workSource.size() > 0 && workSource.get(0) >= 0; } - private static WorkSource computeWorkSource(ClientInfo ci, WorkSource requestedWorkSource) { + private WorkSource computeWorkSource(ClientInfo ci, WorkSource requestedWorkSource) { if (requestedWorkSource != null) { if (isWorkSourceValid(requestedWorkSource)) { // Wifi currently doesn't use names, so need to clear names out of the @@ -328,7 +328,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } } - private static class RequestInfo<T> { + private class RequestInfo<T> { final ClientInfo clientInfo; final int handlerId; final WorkSource workSource; @@ -347,7 +347,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } } - private static class RequestList<T> extends ArrayList<RequestInfo<T>> { + private class RequestList<T> extends ArrayList<RequestInfo<T>> { void addRequest(ClientInfo ci, int handler, WorkSource reqworkSource, T settings) { add(new RequestInfo<T>(ci, handler, reqworkSource, settings)); } @@ -2489,7 +2489,9 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } } } - mPnoScanStateMachine.dump(fd, pw, args); + if (mPnoScanStateMachine != null) { + mPnoScanStateMachine.dump(fd, pw, args); + } } void logScanRequest(String request, ClientInfo ci, int id, WorkSource workSource, diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index 4fe7d53da..30580ab7e 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -57,9 +57,13 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.internal.matchers.CapturingMatcher; +import java.io.FileDescriptor; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.regex.Pattern; /** * Unit tests for {@link com.android.server.wifi.scanner.WifiScanningServiceImpl}. @@ -276,10 +280,27 @@ public class WifiScanningServiceTest { mLooper.dispatchAll(); } + private String dumpService() { + StringWriter stringWriter = new StringWriter(); + mWifiScanningServiceImpl.dump(new FileDescriptor(), new PrintWriter(stringWriter), + new String[0]); + return stringWriter.toString(); + } + + private void assertDumpContainsRequestLog(String type, int id) { + String serviceDump = dumpService(); + Pattern logLineRegex = Pattern.compile("^.+" + type + ": ClientInfo\\[uid=\\d+\\],Id=" + + id + ".*$", Pattern.MULTILINE); + assertTrue("dump did not contain log with type=" + type + ", id=" + id + + " for scan request: " + serviceDump + "\n", + logLineRegex.matcher(serviceDump).find()); + } + @Test public void construct() throws Exception { verifyNoMoreInteractions(mWifiScannerImpl, mWifiScannerImpl, mWifiScannerImplFactory, mBatteryStats); + dumpService(); // make sure this succeeds } @Test @@ -308,6 +329,7 @@ public class WifiScanningServiceTest { sendBackgroundScanRequest(controlChannel, 192, generateValidScanSettings(), null); mLooper.dispatchAll(); verifySuccessfulResponse(order, handler, 192); + assertDumpContainsRequestLog("addBackgroundScanRequest", 192); } @Test @@ -349,6 +371,8 @@ public class WifiScanningServiceTest { verifyScanResultsRecieved(order, handler, requestId, results.getScanData()); verifySingleScanCompletedRecieved(order, handler, requestId); verifyNoMoreInteractions(handler); + assertDumpContainsRequestLog("addSingleScanRequest", requestId); + assertDumpContainsRequestLog("singleScanResults", requestId); } /** @@ -405,6 +429,7 @@ public class WifiScanningServiceTest { assertEquals(mWifiMetrics.getOneshotScanCount(), 1); assertEquals(mWifiMetrics.getScanReturnEntry(WifiMetricsProto.WifiLog.SCAN_UNKNOWN), 1); + assertDumpContainsRequestLog("addSingleScanRequest", requestId); } /** |