summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-04-29 13:22:44 -0700
committerRoshan Pius <rpius@google.com>2019-05-02 16:05:17 +0000
commit7eeafbaa082eff6aa6958fc241df61511172a31d (patch)
treeda042af7e84b703581b5bc414c28f3febaafd90e
parentc0f020cfc1486880c7a80290ded61a9c3b13fad2 (diff)
SoftApManager: Simplify band preference violation metrics update
Changes in the CL: a) Refactor the metrics update for user band preference violation into a separate method. b) Use a simple frequency check to verify if band preference is violated (don't fetch the channel list from wificond). c) Don't do anything for ANY band preference. Bug: 131557372 Test: atest FrameworksWifiTests Test: Toggle softap on/off Change-Id: Ifbee921acd45539b6c92e08b7482ffdd8a58b119 Merged-In: Ifbee921acd45539b6c92e08b7482ffdd8a58b119
-rw-r--r--service/java/com/android/server/wifi/SoftApManager.java45
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java47
2 files changed, 22 insertions, 70 deletions
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
index 740a9d40e..b92dab78d 100644
--- a/service/java/com/android/server/wifi/SoftApManager.java
+++ b/service/java/com/android/server/wifi/SoftApManager.java
@@ -24,9 +24,9 @@ import android.annotation.NonNull;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
+import android.net.wifi.ScanResult;
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;
@@ -38,7 +38,6 @@ 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;
@@ -49,9 +48,7 @@ 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.
@@ -558,6 +555,22 @@ public class SoftApManager implements ActiveModeManager {
mStateMachine.quitNow();
}
+ private void updateUserBandPreferenceViolationMetricsIfNeeded() {
+ boolean bandPreferenceViolated = false;
+ if (mApConfig.apBand == WifiConfiguration.AP_BAND_2GHZ
+ && ScanResult.is5GHz(mReportedFrequency)) {
+ bandPreferenceViolated = true;
+ } else if (mApConfig.apBand == WifiConfiguration.AP_BAND_5GHZ
+ && ScanResult.is24GHz(mReportedFrequency)) {
+ bandPreferenceViolated = true;
+ }
+ if (bandPreferenceViolated) {
+ Log.e(TAG, "Channel does not satisfy user band preference: "
+ + mReportedFrequency);
+ mWifiMetrics.incrementNumSoftApUserBandPreferenceUnsatisfied();
+ }
+ }
+
@Override
public boolean processMessage(Message message) {
switch (message.what) {
@@ -576,29 +589,7 @@ 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();
- }
+ updateUserBandPreferenceViolationMetricsIfNeeded();
break;
case CMD_TIMEOUT_TOGGLE_CHANGED:
boolean isEnabled = (message.arg1 == 1);
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
index e50d5b1a6..ed70ef5a2 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
@@ -42,7 +42,6 @@ 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;
@@ -75,8 +74,6 @@ public class SoftApManagerTest {
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 static final int[] ALLOWED_2G_CHANNELS = {2412, 2417, 2437};
- private static final int[] ALLOWED_5G_CHANNELS = {5180, 5190, 5240};
private final WifiConfiguration mDefaultApConfig = createDefaultApConfig();
@@ -774,15 +771,12 @@ public class SoftApManagerTest {
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
startSoftApAndVerifyEnabled(apConfig);
- final int channelFrequency = 2437;
+ final int channelFrequency = 5180;
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();
@@ -798,66 +792,33 @@ public class SoftApManagerTest {
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()
+ public void updatesMetricsOnChannelSwitchedEventDoesNotDetectBandUnsatisfiedOnBandAny()
throws Exception {
WifiConfiguration config = createDefaultApConfig();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ config.apBand = WifiConfiguration.AP_BAND_ANY;
SoftApModeConfiguration apConfig =
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
startSoftApAndVerifyEnabled(apConfig);
- final int channelFrequency = 2437;
+ final int channelFrequency = 5220;
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();