diff options
4 files changed, 146 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 99bdb5b98..2faf11577 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.database.ContentObserver; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; +import android.net.wifi.WifiScanner; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -37,6 +38,7 @@ import android.util.Log; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.util.ArrayUtils; import com.android.internal.util.IState; import com.android.internal.util.State; import com.android.internal.util.StateMachine; @@ -47,7 +49,9 @@ import com.android.server.wifi.util.ApConfigUtil; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Arrays; import java.util.Locale; +import java.util.stream.Stream; /** * Manage WiFi in AP mode. @@ -530,6 +534,29 @@ public class SoftApManager implements ActiveModeManager { + " Bandwidth: " + mReportedBandwidth); mWifiMetrics.addSoftApChannelSwitchedEvent(mReportedFrequency, mReportedBandwidth, mMode); + int[] allowedChannels = new int[0]; + if (mApConfig.apBand == WifiConfiguration.AP_BAND_2GHZ) { + allowedChannels = + mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); + } else if (mApConfig.apBand == WifiConfiguration.AP_BAND_5GHZ) { + allowedChannels = + mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); + } else if (mApConfig.apBand == WifiConfiguration.AP_BAND_ANY) { + int[] allowed2GChannels = + mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); + int[] allowed5GChannels = + mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); + allowedChannels = Stream.concat( + Arrays.stream(allowed2GChannels).boxed(), + Arrays.stream(allowed5GChannels).boxed()) + .mapToInt(Integer::valueOf) + .toArray(); + } + if (!ArrayUtils.contains(allowedChannels, mReportedFrequency)) { + Log.e(TAG, "Channel does not satisfy user band preference: " + + mReportedFrequency); + mWifiMetrics.incrementNumSoftApUserBandPreferenceUnsatisfied(); + } break; case CMD_TIMEOUT_TOGGLE_CHANGED: boolean isEnabled = (message.arg1 == 1); diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 93dec11eb..3097658d3 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -1549,6 +1549,15 @@ public class WifiMetrics { } /** + * Increment number of times we detected a channel did not satisfy user band preference. + */ + public void incrementNumSoftApUserBandPreferenceUnsatisfied() { + synchronized (mLock) { + mWifiLogProto.numSoftApUserBandPreferenceUnsatisfied++; + } + } + + /** * Increment N-Way network selection decision histograms: * Counts the size of various sets of scanDetails within a scan, and increment the occurrence * of that size for the associated histogram. There are ten histograms generated for each @@ -1994,6 +2003,8 @@ public class WifiMetrics { + mWifiLogProto.numRadioModeChangeToSbs); pw.println("mWifiLogProto.numRadioModeChangeToDbs=" + mWifiLogProto.numRadioModeChangeToDbs); + pw.println("mWifiLogProto.numSoftApUserBandPreferenceUnsatisfied=" + + mWifiLogProto.numSoftApUserBandPreferenceUnsatisfied); pw.println("mTotalSsidsInScanHistogram:" + mTotalSsidsInScanHistogram.toString()); pw.println("mTotalBssidsInScanHistogram:" diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index 7534f78ce..0b937849d 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -42,6 +42,7 @@ import android.net.Uri; import android.net.wifi.IApInterfaceEventCallback; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; +import android.net.wifi.WifiScanner; import android.os.UserHandle; import android.os.test.TestLooper; import android.provider.Settings; @@ -57,8 +58,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -72,13 +71,11 @@ public class SoftApManagerTest { private static final String TEST_SSID = "TestSSID"; private static final String TEST_PASSWORD = "TestPassword"; private static final String TEST_COUNTRY_CODE = "TestCountry"; - private static final Integer[] ALLOWED_2G_CHANNELS = {1, 2, 3, 4}; private static final String TEST_INTERFACE_NAME = "testif0"; private static final String OTHER_INTERFACE_NAME = "otherif"; private static final int TEST_NUM_CONNECTED_CLIENTS = 4; - - private final ArrayList<Integer> mAllowed2GChannels = - new ArrayList<>(Arrays.asList(ALLOWED_2G_CHANNELS)); + private static final int[] ALLOWED_2G_CHANNELS = {2412, 2417, 2437}; + private static final int[] ALLOWED_5G_CHANNELS = {5180, 5190, 5240}; private final WifiConfiguration mDefaultApConfig = createDefaultApConfig(); @@ -600,6 +597,105 @@ public class SoftApManagerTest { } @Test + public void updatesMetricsOnChannelSwitchedEventDetectsBandUnsatisfiedOnBand2Ghz() + throws Exception { + WifiConfiguration config = createDefaultApConfig(); + config.apBand = WifiConfiguration.AP_BAND_2GHZ; + + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config); + startSoftApAndVerifyEnabled(apConfig); + + final int channelFrequency = 2437; + final int channelBandwidth = IApInterfaceEventCallback.BANDWIDTH_20; + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ)) + .thenReturn(ALLOWED_5G_CHANNELS); + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched(channelFrequency, + channelBandwidth); + mLooper.dispatchAll(); + + verify(mWifiNative).getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); + verify(mWifiMetrics).addSoftApChannelSwitchedEvent(channelFrequency, channelBandwidth, + apConfig.getTargetMode()); + verify(mWifiMetrics).incrementNumSoftApUserBandPreferenceUnsatisfied(); + } + + @Test + public void updatesMetricsOnChannelSwitchedEventDetectsBandUnsatisfiedOnBand5Ghz() + throws Exception { + WifiConfiguration config = createDefaultApConfig(); + config.apBand = WifiConfiguration.AP_BAND_5GHZ; + + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config); + startSoftApAndVerifyEnabled(apConfig); + + final int channelFrequency = 5180; + final int channelBandwidth = IApInterfaceEventCallback.BANDWIDTH_20; + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)) + .thenReturn(ALLOWED_2G_CHANNELS); + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched(channelFrequency, + channelBandwidth); + mLooper.dispatchAll(); + + verify(mWifiNative).getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); + verify(mWifiMetrics).addSoftApChannelSwitchedEvent(channelFrequency, channelBandwidth, + apConfig.getTargetMode()); + verify(mWifiMetrics).incrementNumSoftApUserBandPreferenceUnsatisfied(); + } + + @Test + public void updatesMetricsOnChannelSwitchedEventDetectsBandUnsatisfiedOnBandAny() + throws Exception { + WifiConfiguration config = createDefaultApConfig(); + config.apBand = WifiConfiguration.AP_BAND_ANY; + + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config); + startSoftApAndVerifyEnabled(apConfig); + + final int channelFrequency = 2437; + final int channelBandwidth = IApInterfaceEventCallback.BANDWIDTH_20; + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ)) + .thenReturn(new int[0]); + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)) + .thenReturn(new int[0]); + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched(channelFrequency, + channelBandwidth); + mLooper.dispatchAll(); + + verify(mWifiNative).getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); + verify(mWifiNative).getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); + verify(mWifiMetrics).addSoftApChannelSwitchedEvent(channelFrequency, channelBandwidth, + apConfig.getTargetMode()); + verify(mWifiMetrics).incrementNumSoftApUserBandPreferenceUnsatisfied(); + } + + @Test + public void updatesMetricsOnChannelSwitchedEventDetectsBandUnsatisfiedOnlyWhenRequired() + throws Exception { + WifiConfiguration config = createDefaultApConfig(); + config.apBand = WifiConfiguration.AP_BAND_2GHZ; + + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config); + startSoftApAndVerifyEnabled(apConfig); + + final int channelFrequency = 2437; + final int channelBandwidth = IApInterfaceEventCallback.BANDWIDTH_20; + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ)) + .thenReturn(ALLOWED_2G_CHANNELS); + mSoftApListenerCaptor.getValue().onSoftApChannelSwitched(channelFrequency, + channelBandwidth); + mLooper.dispatchAll(); + + verify(mWifiNative).getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); + verify(mWifiMetrics).addSoftApChannelSwitchedEvent(channelFrequency, channelBandwidth, + apConfig.getTargetMode()); + verify(mWifiMetrics, never()).incrementNumSoftApUserBandPreferenceUnsatisfied(); + } + + @Test public void updatesNumAssociatedStations() throws Exception { SoftApModeConfiguration apConfig = new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 9b9bce33d..3e267196e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -290,6 +290,7 @@ public class WifiMetricsTest { private static final int NUM_RADIO_MODE_CHANGE_TO_SCC = 13; private static final int NUM_RADIO_MODE_CHANGE_TO_SBS = 19; private static final int NUM_RADIO_MODE_CHANGE_TO_DBS = 34; + private static final int NUM_SOFTAP_USER_BAND_PREFERENCE_UNSATISFIED = 14; private static final long NUM_WATCHDOG_SUCCESS_DURATION_MS = 65; /** Number of notifications per "Connect to Network" notification type. */ @@ -604,6 +605,9 @@ public class WifiMetricsTest { for (int i = 0; i < NUM_RADIO_MODE_CHANGE_TO_DBS; i++) { mWifiMetrics.incrementNumRadioModeChangeToDbs(); } + for (int i = 0; i < NUM_SOFTAP_USER_BAND_PREFERENCE_UNSATISFIED; i++) { + mWifiMetrics.incrementNumSoftApUserBandPreferenceUnsatisfied(); + } // increment pno scan metrics for (int i = 0; i < NUM_PNO_SCAN_ATTEMPTS; i++) { @@ -902,6 +906,8 @@ public class WifiMetricsTest { assertEquals(NUM_RADIO_MODE_CHANGE_TO_SCC, mDecodedProto.numRadioModeChangeToScc); assertEquals(NUM_RADIO_MODE_CHANGE_TO_SBS, mDecodedProto.numRadioModeChangeToSbs); assertEquals(NUM_RADIO_MODE_CHANGE_TO_DBS, mDecodedProto.numRadioModeChangeToDbs); + assertEquals(NUM_SOFTAP_USER_BAND_PREFERENCE_UNSATISFIED, + mDecodedProto.numSoftApUserBandPreferenceUnsatisfied); PnoScanMetrics pno_metrics = mDecodedProto.pnoScanMetrics; assertNotNull(pno_metrics); |