diff options
author | David Su <dysu@google.com> | 2019-03-18 16:55:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-03-18 16:55:22 +0000 |
commit | aaa99081b930076d4992e65842e3b27481018ef2 (patch) | |
tree | 82b5683508283ccabd2200969cf59daae78d6852 | |
parent | 49699036a7956b28c9183a12132942b965927f1f (diff) | |
parent | f76cf1112e78a03ec60b999a5d7d931588c89c48 (diff) |
Merge "Dump RSSI and Link Layer Stats in Bug Report when screen off"
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 08406dc38..7497aaf0c 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -467,6 +467,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: @@ -5099,14 +5103,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) { @@ -5252,6 +5256,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 83e8cb0f0..7a69eaa24 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 191acc6a7..ffc23a5ef 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 |