summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server
diff options
context:
space:
mode:
authorxshu <xshu@google.com>2019-05-21 17:34:56 -0700
committerxshu <xshu@google.com>2019-06-27 17:25:16 -0700
commit8945c2a640c3227e4e5efe5dbffbaacd579eeec5 (patch)
tree729e3db76a7ac845b083e5615e52f66220278eb3 /tests/wifitests/src/com/android/server
parentc23fd06553163353e75ed9b45d2556b5969ed6f0 (diff)
downloadandroid_frameworks_opt_net_wifi-8945c2a640c3227e4e5efe5dbffbaacd579eeec5.tar.gz
android_frameworks_opt_net_wifi-8945c2a640c3227e4e5efe5dbffbaacd579eeec5.tar.bz2
android_frameworks_opt_net_wifi-8945c2a640c3227e4e5efe5dbffbaacd579eeec5.zip
Detect+trigger bugreport for abnormal connections
This is an effort investigate why certain connections take really long to finish. Users running user-debug builds will be shown an notification, which they may tap on to file a bugreport. Added DeviceConfig flags (that is disabled by default) which may be configured on the server side to enable this feature for a select group of users. Also added a flag to fine tune the threshold at which bugreports get triggered. Bug: 132648941 Test: Unit tests Test: Tested turning on the bugreport trigger with "adb shell device_config put wifi abnormal_connection_bugreport_enabled true" Test: Ran "adb shell device_config put wifi abnormal_connection_duration_ms 30" and verified that bugreport is taken Change-Id: Ic4ea7c1850677781838a645b989f81db858546f4
Diffstat (limited to 'tests/wifitests/src/com/android/server')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java106
1 files changed, 104 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
index 9ae382640..7c55228ca 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
@@ -21,16 +21,20 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.*;
+import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiSsid;
+import android.os.Handler;
import android.os.test.TestLooper;
+import android.provider.DeviceConfig.OnPropertiesChangedListener;
import android.util.Pair;
import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import java.util.ArrayList;
@@ -42,6 +46,8 @@ import java.util.List;
*/
@SmallTest
public class WifiLastResortWatchdogTest {
+ final ArgumentCaptor<OnPropertiesChangedListener> mOnPropertiesChangedListenerCaptor =
+ ArgumentCaptor.forClass(OnPropertiesChangedListener.class);
WifiLastResortWatchdog mLastResortWatchdog;
@Mock WifiInjector mWifiInjector;
@Mock WifiMetrics mWifiMetrics;
@@ -49,6 +55,8 @@ public class WifiLastResortWatchdogTest {
@Mock ClientModeImpl mClientModeImpl;
@Mock Clock mClock;
@Mock WifiInfo mWifiInfo;
+ @Mock Context mContext;
+ @Mock DeviceConfigFacade mDeviceConfigFacade;
private String[] mSsids = {"\"test1\"", "\"test2\"", "\"test3\"", "\"test4\""};
private String[] mBssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "de:ad:ba:b1:e5:55",
@@ -61,17 +69,24 @@ public class WifiLastResortWatchdogTest {
private boolean[] mHasEverConnected = {false, false, false, false};
private TestLooper mLooper;
private static final String TEST_NETWORK_SSID = "\"test_ssid\"";
+ private static final int DEFAULT_ABNORMAL_CONNECTION_DURATION_MS = 30000;
@Before
public void setUp() throws Exception {
initMocks(this);
mLooper = new TestLooper();
when(mWifiInjector.getSelfRecovery()).thenReturn(mSelfRecovery);
- mLastResortWatchdog = new WifiLastResortWatchdog(mWifiInjector, mClock, mWifiMetrics,
- mClientModeImpl, mLooper.getLooper());
+ when(mDeviceConfigFacade.isAbnormalConnectionBugreportEnabled()).thenReturn(true);
+ when(mDeviceConfigFacade.getAbnormalConnectionDurationMs()).thenReturn(
+ DEFAULT_ABNORMAL_CONNECTION_DURATION_MS);
+ mLastResortWatchdog = new WifiLastResortWatchdog(mWifiInjector, mContext, mClock,
+ mWifiMetrics, mClientModeImpl, mLooper.getLooper(), mDeviceConfigFacade);
mLastResortWatchdog.setBugReportProbability(1);
when(mClientModeImpl.getWifiInfo()).thenReturn(mWifiInfo);
when(mWifiInfo.getSSID()).thenReturn(TEST_NETWORK_SSID);
+ when(mWifiInjector.getClientModeImplHandler()).thenReturn(mLastResortWatchdog.getHandler());
+ verify(mDeviceConfigFacade).addOnPropertiesChangedListener(any(),
+ mOnPropertiesChangedListenerCaptor.capture());
}
private List<Pair<ScanDetail, WifiConfiguration>> createFilteredQnsCandidates(String[] ssids,
@@ -2152,4 +2167,91 @@ public class WifiLastResortWatchdogTest {
verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses();
}
+ /**
+ * Verifies that when a connection takes too long (time difference between
+ * StaEvent.TYPE_CMD_START_CONNECT and StaEvent.TYPE_NETWORK_CONNECTION_EVENT) a bugreport is
+ * taken.
+ */
+ @Test
+ public void testAbnormalConnectionTimeTriggersBugreport() throws Exception {
+ // first verifies that bugreports are not taken when connection takes less than
+ // DEFAULT_ABNORMAL_CONNECTION_DURATION_MS
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(1L);
+ mLastResortWatchdog.noteStartConnectTime();
+ mLooper.dispatchAll();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ (long) DEFAULT_ABNORMAL_CONNECTION_DURATION_MS);
+ Handler handler = mLastResortWatchdog.getHandler();
+ handler.sendMessage(
+ handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null));
+ mLooper.dispatchAll();
+ verify(mClientModeImpl, never()).takeBugReport(anyString(), anyString());
+
+ // Now verify that bugreport is taken
+ mLastResortWatchdog.noteStartConnectTime();
+ mLooper.dispatchAll();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ 2L * DEFAULT_ABNORMAL_CONNECTION_DURATION_MS + 1);
+ handler.sendMessage(
+ handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null));
+ mLooper.dispatchAll();
+ verify(mClientModeImpl).takeBugReport(anyString(), anyString());
+
+ // Verify additional connections (without more TYPE_CMD_START_CONNECT) don't trigger more
+ // bugreports.
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ 4L * DEFAULT_ABNORMAL_CONNECTION_DURATION_MS);
+ handler.sendMessage(
+ handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null));
+ mLooper.dispatchAll();
+ verify(mClientModeImpl).takeBugReport(anyString(), anyString());
+ }
+
+ /**
+ * Changes |mAbnormalConnectionDurationMs| to a new value, and then verify that a bugreport is
+ * taken for a connection that takes longer than the new threshold.
+ * @throws Exception
+ */
+ @Test
+ public void testGServicesSetDuration() throws Exception {
+ final int testDurationMs = 10 * 1000; // 10 seconds
+ // changes the abnormal connection duration to |testDurationMs|.
+ when(mDeviceConfigFacade.getAbnormalConnectionDurationMs()).thenReturn(testDurationMs);
+ mOnPropertiesChangedListenerCaptor.getValue().onPropertiesChanged(null);
+
+ // verifies that bugreport is taken for connections that take longer than |testDurationMs|.
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(1L);
+ mLastResortWatchdog.noteStartConnectTime();
+ mLooper.dispatchAll();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn((long) testDurationMs + 2);
+ Handler handler = mLastResortWatchdog.getHandler();
+ handler.sendMessage(
+ handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null));
+ mLooper.dispatchAll();
+ verify(mClientModeImpl).takeBugReport(anyString(), anyString());
+ }
+
+ /**
+ * Verifies that bugreports are not triggered even when conditions are met after the
+ * |mAbnormalConnectionBugreportEnabled| flag is changed to false.
+ * @throws Exception
+ */
+ @Test
+ public void testGServicesFlagDisable() throws Exception {
+ // changes |mAbnormalConnectionBugreportEnabled| to false.
+ when(mDeviceConfigFacade.isAbnormalConnectionBugreportEnabled()).thenReturn(false);
+ mOnPropertiesChangedListenerCaptor.getValue().onPropertiesChanged(null);
+
+ // verifies that bugreports are not taken.
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(1L);
+ mLastResortWatchdog.noteStartConnectTime();
+ mLooper.dispatchAll();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ (long) DEFAULT_ABNORMAL_CONNECTION_DURATION_MS + 2);
+ Handler handler = mLastResortWatchdog.getHandler();
+ handler.sendMessage(
+ handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null));
+ mLooper.dispatchAll();
+ verify(mClientModeImpl, never()).takeBugReport(anyString(), anyString());
+ }
}