summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-03-07 17:33:02 -0800
committerDavid Su <dysu@google.com>2019-03-15 15:27:34 -0700
commitf76cf1112e78a03ec60b999a5d7d931588c89c48 (patch)
tree3e5a78eb6b9196699bfbf6dff2a4382431d9f9db
parentdca46d9f86d7a78ca84903137e73e5f9f9ba6929 (diff)
Dump RSSI and Link Layer Stats in Bug Report when screen off
Always poll RSSI and link layer stats during a bug report, even when the screen is off. The RSSI and link layer stats will be shown in the "WifiScoreReport" section of the bug report. Bug: 119727583 Test: ran `adb bugreport` when screen is on, verify that it does not crash Test: ran `adb bugreport` when screen is off, verify link layer stats show in BR Test: ran `adb bugreport` when the device is disconnected from Wifi, verify that it does not crash Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I9aa47225f109751fbae68fd28c68b358fe67fef6
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java35
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java32
3 files changed, 64 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 444219d2b..987f463be 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -466,6 +466,8 @@ public class ClientModeImpl extends StateMachine {
static final int CMD_ENABLE_RSSI_POLL = BASE + 82;
/* RSSI poll */
static final int CMD_RSSI_POLL = BASE + 83;
+ /** Runs RSSI poll once */
+ static final int CMD_ONESHOT_RSSI_POLL = BASE + 84;
/* Enable suspend mode optimizations in the driver */
static final int CMD_SET_SUSPEND_OPT_ENABLED = BASE + 86;
@@ -2246,6 +2248,7 @@ public class ClientModeImpl extends StateMachine {
}
break;
case CMD_RSSI_POLL:
+ case CMD_ONESHOT_RSSI_POLL:
case CMD_UNWANTED_NETWORK:
case WifiManager.RSSI_PKTCNT_FETCH:
sb.append(" ");
@@ -3558,6 +3561,7 @@ public class ClientModeImpl extends StateMachine {
case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
case WifiMonitor.ASSOCIATION_REJECTION_EVENT:
case CMD_RSSI_POLL:
+ case CMD_ONESHOT_RSSI_POLL:
case CMD_PRE_DHCP_ACTION:
case CMD_PRE_DHCP_ACTION_COMPLETE:
case CMD_POST_DHCP_ACTION:
@@ -5087,14 +5091,14 @@ public class ClientModeImpl extends StateMachine {
sendNetworkStateChangeBroadcast(mLastBssid);
}
break;
+ case CMD_ONESHOT_RSSI_POLL:
+ if (!mEnableRssiPolling) {
+ updateLinkLayerStatsRssiAndScoreReportInternal();
+ }
+ break;
case CMD_RSSI_POLL:
if (message.arg1 == mRssiPollToken) {
- WifiLinkLayerStats stats = getWifiLinkLayerStats();
- // Get Info and continue polling
- fetchRssiLinkSpeedAndFrequencyNative();
- // Send the update score to network agent.
- mWifiScoreReport.calculateAndReportScore(
- mWifiInfo, mNetworkAgent, mWifiMetrics);
+ WifiLinkLayerStats stats = updateLinkLayerStatsRssiAndScoreReportInternal();
mWifiMetrics.updateWifiUsabilityStatsEntries(mWifiInfo, stats);
if (mWifiScoreReport.shouldCheckIpLayer()) {
if (mIpClient != null) {
@@ -5240,6 +5244,25 @@ public class ClientModeImpl extends StateMachine {
return HANDLED;
}
+
+ /**
+ * Fetches link stats and updates Wifi Score Report.
+ */
+ private WifiLinkLayerStats updateLinkLayerStatsRssiAndScoreReportInternal() {
+ WifiLinkLayerStats stats = getWifiLinkLayerStats();
+ // Get Info and continue polling
+ fetchRssiLinkSpeedAndFrequencyNative();
+ // Send the update score to network agent.
+ mWifiScoreReport.calculateAndReportScore(mWifiInfo, mNetworkAgent, mWifiMetrics);
+ return stats;
+ }
+ }
+
+ /**
+ * Fetches link stats and updates Wifi Score Report.
+ */
+ public void updateLinkLayerStatsRssiAndScoreReport() {
+ sendMessage(CMD_ONESHOT_RSSI_POLL);
}
private static int convertToUsabilityStatsTriggerType(int unusableEventTriggerType) {
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 728a4b4ec..abf226873 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2722,6 +2722,9 @@ public class WifiServiceImpl extends BaseWifiService {
}
}, RUN_WITH_SCISSORS_TIMEOUT_MILLIS);
} else {
+ // Polls link layer stats and RSSI. This allows the stats to show up in
+ // WifiScoreReport's dump() output when taking a bug report even if the screen is off.
+ mClientModeImpl.updateLinkLayerStatsRssiAndScoreReport();
pw.println("Wi-Fi is " + mClientModeImpl.syncGetWifiStateByName());
pw.println("Verbose logging is " + (mVerboseLoggingEnabled ? "on" : "off"));
pw.println("Stay-awake conditions: " +
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 48efb51a6..a69679482 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -115,6 +115,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
+import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
@@ -233,6 +234,7 @@ public class WifiServiceImplTest {
@Mock TelephonyManager mTelephonyManager;
@Mock IOnWifiUsabilityStatsListener mOnWifiUsabilityStatsListener;
@Mock WifiConfigManager mWifiConfigManager;
+ @Mock WifiScoreReport mWifiScoreReport;
@Spy FakeWifiLog mLog;
@@ -357,6 +359,7 @@ public class WifiServiceImplTest {
.thenReturn(mWifiNetworkSuggestionsManager);
when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager);
when(mWifiInjector.getWifiConfigManager()).thenReturn(mWifiConfigManager);
+ when(mClientModeImpl.getWifiScoreReport()).thenReturn(mWifiScoreReport);
when(mClientModeImpl.syncStartSubscriptionProvisioning(anyInt(),
any(OsuProvider.class), any(IProvisioningCallback.class), any())).thenReturn(true);
when(mPackageManager.hasSystemFeature(
@@ -439,6 +442,35 @@ public class WifiServiceImplTest {
}
/**
+ * Ensure that WifiServiceImpl.dump() calls
+ * {@link ClientModeImpl#updateLinkLayerStatsRssiAndScoreReport()}, then calls
+ * mWifiInjector.getClientModeImplHandler().runWithScissors() at least once before calling
+ * {@link WifiScoreReport#dump(FileDescriptor, PrintWriter, String[])}.
+ *
+ * runWithScissors() needs to be called at least once so that we know that the async call
+ * {@link ClientModeImpl#updateLinkLayerStatsRssiAndScoreReport()} has completed, since
+ * runWithScissors() blocks the current thread until the call completes, which includes all
+ * previous calls posted to that thread.
+ *
+ * This ensures that WifiScoreReport will always get updated RSSI and link layer stats before
+ * dumping during a bug report, no matter if the screen is on or not.
+ */
+ @Test
+ public void testWifiScoreReportDump() {
+ setupClientModeImplHandlerForRunWithScissors();
+
+ mWifiServiceImpl.dump(new FileDescriptor(), new PrintWriter(new StringWriter()), null);
+
+ InOrder inOrder = inOrder(mClientModeImpl, mHandlerSpyForCmiRunWithScissors,
+ mWifiScoreReport);
+
+ inOrder.verify(mClientModeImpl).updateLinkLayerStatsRssiAndScoreReport();
+ inOrder.verify(mHandlerSpyForCmiRunWithScissors, atLeastOnce())
+ .runWithScissors(any(), anyLong());
+ inOrder.verify(mWifiScoreReport).dump(any(), any(), any());
+ }
+
+ /**
* Verify that wifi can be enabled by a caller with NETWORK_SETTINGS permission.
*/
@Test