diff options
author | Glen Kuhne <kuh@google.com> | 2017-05-02 12:43:08 -0700 |
---|---|---|
committer | Glen Kuhne <kuh@google.com> | 2017-05-02 13:19:39 -0700 |
commit | 031cdffdaf223772d4ea52569ec7a08d00013208 (patch) | |
tree | 41abca3f40e3f0b133e43f97d6564fd33a52fc45 /tests | |
parent | 8472ba80953fbbb0227eff5faac497e1bca067b0 (diff) |
Fix potential NPE in WifiService dump
Added nullchecks to WifiServiceImpl & WifiMetrics dump methods usage of
args.
This is a precaution to similar null pointer exceptions that were occuring in
statemachine dump methods.
Bug: 37907061
Test: Added some unit tests
Change-Id: I0ab74421cddc31f7270cdd314fb86678194be0f0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java | 11 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 8 |
2 files changed, 19 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 22744b63b..4d9c906ea 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -41,7 +41,9 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.ByteArrayOutputStream; +import java.io.FileDescriptor; import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.BitSet; import java.util.List; @@ -1006,6 +1008,15 @@ public class WifiMetricsTest { dumpProtoAndDeserialize(); assertEquals(WifiMetrics.MAX_STA_EVENTS, mDeserializedWifiMetrics.staEventList.length); } + + /** + * Ensure WifiMetrics doesn't cause a null pointer exception when called with null args + */ + @Test + public void testDumpNullArg() { + mWifiMetrics.dump(new FileDescriptor(), new PrintWriter(new StringWriter()), null); + } + /** * Generate an RSSI delta event by creating a connection event and an RSSI poll within * 'interArrivalTime' milliseconds of each other. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index b1f035450..c81970d54 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -276,6 +276,14 @@ public class WifiServiceImplTest { /** + * Ensure WifiServiceImpl.dump() doesn't throw an NPE when executed with null args + */ + @Test + public void testDumpNullArgs() { + mWifiServiceImpl.dump(new FileDescriptor(), new PrintWriter(new StringWriter()), null); + } + + /** * Verify that wifi can be enabled by a caller with WIFI_STATE_CHANGE permission when wifi is * off (no hotspot, no airplane mode). */ |