From f5749a73fe63a3e01db62a9752be365fb40ec633 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 24 Apr 2018 15:55:38 -0700 Subject: WifiVendorHal: Add callbacks for radio mode change detection Plumb the radio change callbacks to WifiNative. We're interested in collecting metrics for each of these radio mode changes. Note: Plumbing to WifiNative and WifiMetrics will be taken up in follow up CL's. Bug: 69117051 Test: Unit tests Test: Manually verified logs using STA + AP in DBS & SCC mode. Change-Id: I6e49e9522b75d1661f1a8be2805f21d16a5b3bbe --- .../java/com/android/server/wifi/WifiNative.java | 39 +++ .../com/android/server/wifi/WifiVendorHal.java | 101 +++++++- .../com/android/server/wifi/WifiVendorHalTest.java | 280 +++++++++++++++++++++ 3 files changed, 416 insertions(+), 4 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 8a76c4d3b..0be2b199d 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1880,6 +1880,45 @@ public class WifiNative { void onDeath(); } + /** + * Callback to notify when vendor HAL detects that a change in radio mode. + */ + public interface VendorHalRadioModeChangeEventHandler { + /** + * Invoked when the vendor HAL detects a change to MCC mode. + * MCC (Multi channel concurrency) = Multiple interfaces are active on the same band, + * different channels, same radios. + * + * @param band Band on which MCC is detected (specified by one of the + * WifiScanner.WIFI_BAND_* constants) + */ + void onMcc(int band); + /** + * Invoked when the vendor HAL detects a change to SCC mode. + * SCC (Single channel concurrency) = Multiple interfaces are active on the same band, same + * channels, same radios. + * + * @param band Band on which SCC is detected (specified by one of the + * WifiScanner.WIFI_BAND_* constants) + */ + void onScc(int band); + /** + * Invoked when the vendor HAL detects a change to SBS mode. + * SBS (Single Band Simultaneous) = Multiple interfaces are active on the same band, + * different channels, different radios. + * + * @param band Band on which SBS is detected (specified by one of the + * WifiScanner.WIFI_BAND_* constants) + */ + void onSbs(int band); + /** + * Invoked when the vendor HAL detects a change to DBS mode. + * DBS (Dual Band Simultaneous) = Multiple interfaces are active on the different bands, + * different channels, different radios. + */ + void onDbs(); + } + /** * Tests whether the HAL is running or not */ diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java index 16a279833..8dd4509f6 100644 --- a/service/java/com/android/server/wifi/WifiVendorHal.java +++ b/service/java/com/android/server/wifi/WifiVendorHal.java @@ -85,7 +85,9 @@ import libcore.util.NonNull; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * Vendor HAL via HIDL @@ -302,6 +304,20 @@ public class WifiVendorHal { } } + private WifiNative.VendorHalRadioModeChangeEventHandler mRadioModeChangeEventHandler; + + /** + * Register to listen for radio mode change events from the HAL. + * + * @param handler Handler to notify when the vendor HAL detects a radio mode change. + */ + public void registerRadioModeChangeHandler( + WifiNative.VendorHalRadioModeChangeEventHandler handler) { + synchronized (sLock) { + mRadioModeChangeEventHandler = handler; + } + } + /** * Returns whether the vendor HAL is supported on this device or not. */ @@ -2920,12 +2936,89 @@ public class WifiVendorHal { mIWifiChipEventCallback.onDebugErrorAlert(errorCode, debugData); } + private boolean areSameIfaceNames(List ifaceList1, List ifaceList2) { + List ifaceNamesList1 = ifaceList1 + .stream() + .map(i -> i.name) + .collect(Collectors.toList()); + List ifaceNamesList2 = ifaceList2 + .stream() + .map(i -> i.name) + .collect(Collectors.toList()); + return ifaceNamesList1.containsAll(ifaceNamesList2); + } + + private boolean areSameIfaces(List ifaceList1, List ifaceList2) { + return ifaceList1.containsAll(ifaceList2); + } + @Override - public void onRadioModeChange( - ArrayList - radioModeInfoList) { - // Need to handle this callback. + public void onRadioModeChange(ArrayList radioModeInfoList) { mVerboseLog.d("onRadioModeChange " + radioModeInfoList); + WifiNative.VendorHalRadioModeChangeEventHandler handler; + synchronized (sLock) { + if (mRadioModeChangeEventHandler == null || radioModeInfoList == null) return; + handler = mRadioModeChangeEventHandler; + } + // Should only contain 1 or 2 radio infos. + if (radioModeInfoList.size() == 0 || radioModeInfoList.size() > 2) { + mLog.e("Unexpected number of radio info in list " + radioModeInfoList.size()); + return; + } + // Not concurrency scenario, uninteresting... + if (radioModeInfoList.size() == 1) return; + + RadioModeInfo radioModeInfo0 = radioModeInfoList.get(0); + RadioModeInfo radioModeInfo1 = radioModeInfoList.get(1); + // Number of ifaces on each radio should be equal. + if (radioModeInfo0.ifaceInfos.size() != radioModeInfo1.ifaceInfos.size()) { + mLog.e("Unexpected number of iface info in list " + + radioModeInfo0.ifaceInfos.size() + ", " + + radioModeInfo1.ifaceInfos.size()); + return; + } + int numIfacesOnEachRadio = radioModeInfo0.ifaceInfos.size(); + // Only 1 or 2 ifaces should be present on each radio. + if (numIfacesOnEachRadio == 0 || numIfacesOnEachRadio > 2) { + mLog.e("Unexpected number of iface info in list " + numIfacesOnEachRadio); + return; + } + // 2 ifaces simultaneous on 2 radios. + if (numIfacesOnEachRadio == 1) { + // Iface on radio0 should be different from the iface on radio1 for DBS & SBS. + if (areSameIfaceNames(radioModeInfo0.ifaceInfos, radioModeInfo1.ifaceInfos)) { + mLog.e("Unexpected for both radio infos to have same iface"); + return; + } + if (radioModeInfo0.bandInfo != radioModeInfo1.bandInfo) { + mLog.i("Device is in DBS mode now"); + handler.onDbs(); + } else { + mLog.i("Device is in SBS mode now"); + handler.onSbs(radioModeInfo0.bandInfo); + } + // 2 ifaces time sharing on 2 radios. + } else { + // Ifaces on radio0 & radio1 should be the same for MCC & SCC. + if (!areSameIfaces(radioModeInfo0.ifaceInfos, radioModeInfo1.ifaceInfos)) { + mLog.e("Unexpected for both radio infos to have different ifaces"); + return; + } + // Both radio0 & radio1 should now be in the same band (could be 5G or 2G). + if (radioModeInfo0.bandInfo != radioModeInfo1.bandInfo) { + mLog.e("Unexpected for both radio infos to have different band"); + return; + } + IfaceInfo ifaceInfo0 = radioModeInfo0.ifaceInfos.get(0); + IfaceInfo ifaceInfo1 = radioModeInfo0.ifaceInfos.get(1); + if (ifaceInfo0.channel != ifaceInfo1.channel) { + mLog.i("Device is in MCC mode now"); + handler.onMcc(radioModeInfo0.bandInfo); + } else { + mLog.i("Device is in SCC mode now"); + handler.onScc(radioModeInfo0.bandInfo); + } + } } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 9d20235ad..dcef6e9d4 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.test.MockAnswerUtil.AnswerWithArguments; @@ -75,6 +76,8 @@ import android.hardware.wifi.V1_0.WifiDebugTxPacketFateReport; import android.hardware.wifi.V1_0.WifiInformationElement; import android.hardware.wifi.V1_0.WifiStatus; import android.hardware.wifi.V1_0.WifiStatusCode; +import android.hardware.wifi.V1_2.IWifiChipEventCallback.IfaceInfo; +import android.hardware.wifi.V1_2.IWifiChipEventCallback.RadioModeInfo; import android.net.KeepalivePacketData; import android.net.MacAddress; import android.net.apf.ApfCapabilities; @@ -115,6 +118,7 @@ import java.util.Set; public class WifiVendorHalTest { private static final String TEST_IFACE_NAME = "wlan0"; + private static final String TEST_IFACE_NAME_1 = "wlan1"; private static final MacAddress TEST_MAC_ADDRESS = MacAddress.fromString("ee:33:a2:94:10:92"); WifiVendorHal mWifiVendorHal; @@ -146,6 +150,8 @@ public class WifiVendorHalTest { private android.hardware.wifi.V1_2.IWifiChipEventCallback mIWifiChipEventCallbackV12; @Mock private WifiNative.VendorHalDeathEventHandler mVendorHalDeathHandler; + @Mock + private WifiNative.VendorHalRadioModeChangeEventHandler mVendorHalRadioModeChangeHandler; /** * Spy used to return the V1_1 IWifiChip mock object to simulate the 1.1 HAL running on the @@ -2182,6 +2188,280 @@ public class WifiVendorHalTest { assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); } + /** + * Verifies radio mode change callback to indicate DBS mode. + */ + @Test + public void testRadioModeChangeCallbackToDbsMode() throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_24_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 1; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + verify(mVendorHalRadioModeChangeHandler).onDbs(); + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback to indicate SBS mode. + */ + @Test + public void testRadioModeChangeCallbackToSbsMode() throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 36; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + verify(mVendorHalRadioModeChangeHandler).onSbs(WifiScanner.WIFI_BAND_5_GHZ); + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback to indicate SCC mode. + */ + @Test + public void testRadioModeChangeCallbackToSccMode() throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 34; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo0.ifaceInfos.add(ifaceInfo1); + radioModeInfo1.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + verify(mVendorHalRadioModeChangeHandler).onScc(WifiScanner.WIFI_BAND_5_GHZ); + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback to indicate MCC mode. + */ + @Test + public void testRadioModeChangeCallbackToMccMode() throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 36; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo0.ifaceInfos.add(ifaceInfo1); + radioModeInfo1.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + verify(mVendorHalRadioModeChangeHandler).onMcc(WifiScanner.WIFI_BAND_5_GHZ); + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback error cases. + */ + @Test + public void testRadioModeChangeCallbackErrorTimeSharingWithDifferentIfacesOnBothRadios() + throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 34; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + // Ignored.... + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback error cases. + */ + @Test + public void testRadioModeChangeCallbackErrorTimeSharingWithDifferentNumberOfIfacesOnBothRadios() + throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 34; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + // Ignored.... + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback error cases. + */ + @Test + public void testRadioModeChangeCallbackErrorSimultaneousWithSameIfaceOnBothRadios() + throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_24_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo0); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + // Ignored.... + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + /** + * Verifies radio mode change callback error cases. + */ + @Test + public void testRadioModeChangeCallbackErrorTimeSharingWithDifferentBandsOnBothRadios() + throws Exception { + startHalInStaModeAndRegisterRadioModeChangeCallback(); + + RadioModeInfo radioModeInfo0 = new RadioModeInfo(); + radioModeInfo0.bandInfo = WifiScanner.WIFI_BAND_24_GHZ; + RadioModeInfo radioModeInfo1 = new RadioModeInfo(); + radioModeInfo1.bandInfo = WifiScanner.WIFI_BAND_5_GHZ; + + IfaceInfo ifaceInfo0 = new IfaceInfo(); + ifaceInfo0.name = TEST_IFACE_NAME; + ifaceInfo0.channel = 34; + IfaceInfo ifaceInfo1 = new IfaceInfo(); + ifaceInfo1.name = TEST_IFACE_NAME_1; + ifaceInfo1.channel = 36; + + radioModeInfo0.ifaceInfos.add(ifaceInfo0); + radioModeInfo0.ifaceInfos.add(ifaceInfo1); + radioModeInfo1.ifaceInfos.add(ifaceInfo0); + radioModeInfo1.ifaceInfos.add(ifaceInfo1); + + ArrayList radioModeInfos = new ArrayList<>(); + radioModeInfos.add(radioModeInfo0); + radioModeInfos.add(radioModeInfo1); + + mIWifiChipEventCallbackV12.onRadioModeChange(radioModeInfos); + // Ignored.... + + verifyNoMoreInteractions(mVendorHalRadioModeChangeHandler); + } + + private void startHalInStaModeAndRegisterRadioModeChangeCallback() { + // Expose the 1.2 IWifiChip. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + mWifiVendorHal.registerRadioModeChangeHandler(mVendorHalRadioModeChangeHandler); + assertTrue(mWifiVendorHal.startVendorHalSta()); + assertNotNull(mIWifiChipEventCallbackV12); + } + private void testAlertCallbackUsingProvidedCallback(IWifiChipEventCallback chipCallback) throws Exception { when(mIWifiChip.enableDebugErrorAlerts(anyBoolean())).thenReturn(mWifiStatusSuccess); -- cgit v1.2.3 From 80512c6070e4c2c84a2d7c58ad56d4f1ca3258ed Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 24 Apr 2018 16:08:33 -0700 Subject: WifiNative: Handle radio mode change callbacks These currently invokes the corresponding metrics stub calls. Note: The metrics stubs will be replaced in the next CL. Bug: 69117051 Test: Unit tests Change-Id: Ideb63bc8fc519898578f158894513a8f8d56e929 --- .../java/com/android/server/wifi/WifiMetrics.java | 32 +++++++++++++++++++ .../java/com/android/server/wifi/WifiNative.java | 37 ++++++++++++++++++++++ .../com/android/server/wifi/WifiVendorHal.java | 4 --- .../wifi/WifiNativeInterfaceManagementTest.java | 29 +++++++++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 584e51043..04505cc30 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -1510,6 +1510,38 @@ public class WifiMetrics { } } + /** + * Increment number of times we detected a radio mode change to MCC. + */ + public void incrementNumRadioModeChangeToMcc() { + synchronized (mLock) { + } + } + + /** + * Increment number of times we detected a radio mode change to SCC. + */ + public void incrementNumRadioModeChangeToScc() { + synchronized (mLock) { + } + } + + /** + * Increment number of times we detected a radio mode change to SBS. + */ + public void incrementNumRadioModeChangeToSbs() { + synchronized (mLock) { + } + } + + /** + * Increment number of times we detected a radio mode change to DBS. + */ + public void incrementNumRadioModeChangeToDbs() { + synchronized (mLock) { + } + } + /** * Increment N-Way network selection decision histograms: * Counts the size of various sets of scanDetails within a scan, and increment the occurrence diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 0be2b199d..0f785873b 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -614,6 +614,41 @@ public class WifiNative { } } + /** + * Radio mode change handler for the Vendor HAL daemon. + */ + private class VendorHalRadioModeChangeHandlerInternal + implements VendorHalRadioModeChangeEventHandler { + @Override + public void onMcc(int band) { + synchronized (mLock) { + Log.i(TAG, "Device is in MCC mode now"); + mWifiMetrics.incrementNumRadioModeChangeToMcc(); + } + } + @Override + public void onScc(int band) { + synchronized (mLock) { + Log.i(TAG, "Device is in SCC mode now"); + mWifiMetrics.incrementNumRadioModeChangeToScc(); + } + } + @Override + public void onSbs(int band) { + synchronized (mLock) { + Log.i(TAG, "Device is in SBS mode now"); + mWifiMetrics.incrementNumRadioModeChangeToSbs(); + } + } + @Override + public void onDbs() { + synchronized (mLock) { + Log.i(TAG, "Device is in DBS mode now"); + mWifiMetrics.incrementNumRadioModeChangeToDbs(); + } + } + } + // For devices that don't support the vendor HAL, we will not support any concurrency. // So simulate the HalDeviceManager behavior by triggering the destroy listener for // any active interface. @@ -720,6 +755,8 @@ public class WifiNative { Log.e(TAG, "Failed to initialize wificond"); return false; } + mWifiVendorHal.registerRadioModeChangeHandler( + new VendorHalRadioModeChangeHandlerInternal()); return true; } } diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java index 8dd4509f6..08d03d7de 100644 --- a/service/java/com/android/server/wifi/WifiVendorHal.java +++ b/service/java/com/android/server/wifi/WifiVendorHal.java @@ -2991,10 +2991,8 @@ public class WifiVendorHal { return; } if (radioModeInfo0.bandInfo != radioModeInfo1.bandInfo) { - mLog.i("Device is in DBS mode now"); handler.onDbs(); } else { - mLog.i("Device is in SBS mode now"); handler.onSbs(radioModeInfo0.bandInfo); } // 2 ifaces time sharing on 2 radios. @@ -3012,10 +3010,8 @@ public class WifiVendorHal { IfaceInfo ifaceInfo0 = radioModeInfo0.ifaceInfos.get(0); IfaceInfo ifaceInfo1 = radioModeInfo0.ifaceInfos.get(1); if (ifaceInfo0.channel != ifaceInfo1.channel) { - mLog.i("Device is in MCC mode now"); handler.onMcc(radioModeInfo0.bandInfo); } else { - mLog.i("Device is in SCC mode now"); handler.onScc(radioModeInfo0.bandInfo); } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java index 13147ea4d..12ef6eccc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java @@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.inOrder; @@ -39,6 +40,7 @@ import android.net.InterfaceConfiguration; import android.net.wifi.IApInterface; import android.net.wifi.IClientInterface; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiScanner; import android.os.INetworkManagementService; import android.os.RemoteException; import android.support.test.filters.SmallTest; @@ -84,6 +86,9 @@ public class WifiNativeInterfaceManagementTest { ArgumentCaptor.forClass(VendorHalDeathEventHandler.class); private ArgumentCaptor mWificondDeathHandlerCaptor = ArgumentCaptor.forClass(WificondDeathEventHandler.class); + private ArgumentCaptor + mWifiVendorHalRadioModeChangeHandlerCaptor = + ArgumentCaptor.forClass(WifiNative.VendorHalRadioModeChangeEventHandler.class); private ArgumentCaptor mSupplicantDeathHandlerCaptor = ArgumentCaptor.forClass(SupplicantDeathEventHandler.class); private ArgumentCaptor mHostapdDeathHandlerCaptor = @@ -107,6 +112,8 @@ public class WifiNativeInterfaceManagementTest { // mocks for negative or multi-interface tests. when(mWifiVendorHal.initialize(mWifiVendorHalDeathHandlerCaptor.capture())) .thenReturn(true); + doNothing().when(mWifiVendorHal).registerRadioModeChangeHandler( + mWifiVendorHalRadioModeChangeHandlerCaptor.capture()); when(mWifiVendorHal.isVendorHalSupported()).thenReturn(true); when(mWifiVendorHal.startVendorHal()).thenReturn(true); when(mWifiVendorHal.createStaIface(anyBoolean(), any())).thenReturn(IFACE_NAME_0); @@ -160,6 +167,7 @@ public class WifiNativeInterfaceManagementTest { mInOrder.verify(mWifiVendorHal).initialize(any()); mInOrder.verify(mWificondControl).initialize(any()); + mInOrder.verify(mWifiVendorHal).registerRadioModeChangeHandler(any()); } @After @@ -1140,6 +1148,27 @@ public class WifiNativeInterfaceManagementTest { mInOrder.verify(mNwManagementService).disableIpv6(IFACE_NAME_0); } + /** + * Verifies the handling of radio mode change callbacks. + */ + @Test + public void testRadioModeChangeCallback() { + WifiNative.VendorHalRadioModeChangeEventHandler handler = + mWifiVendorHalRadioModeChangeHandlerCaptor.getValue(); + + handler.onMcc(WifiScanner.WIFI_BAND_5_GHZ); + mInOrder.verify(mWifiMetrics).incrementNumRadioModeChangeToMcc(); + + handler.onScc(WifiScanner.WIFI_BAND_24_GHZ); + mInOrder.verify(mWifiMetrics).incrementNumRadioModeChangeToScc(); + + handler.onSbs(WifiScanner.WIFI_BAND_24_GHZ); + mInOrder.verify(mWifiMetrics).incrementNumRadioModeChangeToSbs(); + + handler.onDbs(); + mInOrder.verify(mWifiMetrics).incrementNumRadioModeChangeToDbs(); + } + private void executeAndValidateSetupClientInterface( boolean existingStaIface, boolean existingApIface, String ifaceName, @Mock WifiNative.InterfaceCallback callback, -- cgit v1.2.3 From 5d540c3dbe22ebd666e5f712a28327d3c7f34a49 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 24 Apr 2018 16:28:53 -0700 Subject: WifiMetrics: Add metrics for radio mode change Bug: 69117051 Test: Unit tests Change-Id: Id097255cb9e2620a4074986e1ee8d3ce7b5b143f --- .../java/com/android/server/wifi/WifiMetrics.java | 12 ++++++++++++ .../src/com/android/server/wifi/WifiMetricsTest.java | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 04505cc30..6b2b50169 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -1515,6 +1515,7 @@ public class WifiMetrics { */ public void incrementNumRadioModeChangeToMcc() { synchronized (mLock) { + mWifiLogProto.numRadioModeChangeToMcc++; } } @@ -1523,6 +1524,7 @@ public class WifiMetrics { */ public void incrementNumRadioModeChangeToScc() { synchronized (mLock) { + mWifiLogProto.numRadioModeChangeToScc++; } } @@ -1531,6 +1533,7 @@ public class WifiMetrics { */ public void incrementNumRadioModeChangeToSbs() { synchronized (mLock) { + mWifiLogProto.numRadioModeChangeToSbs++; } } @@ -1539,6 +1542,7 @@ public class WifiMetrics { */ public void incrementNumRadioModeChangeToDbs() { synchronized (mLock) { + mWifiLogProto.numRadioModeChangeToDbs++; } } @@ -1973,6 +1977,14 @@ public class WifiMetrics { + mWifiLogProto.numPasspointProviderUninstallSuccess); pw.println("mWifiLogProto.numPasspointProvidersSuccessfullyConnected=" + mWifiLogProto.numPasspointProvidersSuccessfullyConnected); + pw.println("mWifiLogProto.numRadioModeChangeToMcc=" + + mWifiLogProto.numRadioModeChangeToMcc); + pw.println("mWifiLogProto.numRadioModeChangeToScc=" + + mWifiLogProto.numRadioModeChangeToScc); + pw.println("mWifiLogProto.numRadioModeChangeToSbs=" + + mWifiLogProto.numRadioModeChangeToSbs); + pw.println("mWifiLogProto.numRadioModeChangeToDbs=" + + mWifiLogProto.numRadioModeChangeToDbs); pw.println("mTotalSsidsInScanHistogram:" + mTotalSsidsInScanHistogram.toString()); pw.println("mTotalBssidsInScanHistogram:" diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 8212169dc..8630e9ee8 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -286,6 +286,10 @@ public class WifiMetricsTest { private static final int NUM_WPS_OTHER_CONNECTION_FAILURE = 16; private static final int NUM_WPS_SUPPLICANT_FAILURE = 12; private static final int NUM_WPS_CANCELLATION = 11; + private static final int NUM_RADIO_MODE_CHANGE_TO_MCC = 4; + 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 long NUM_WATCHDOG_SUCCESS_DURATION_MS = 65; /** Number of notifications per "Connect to Network" notification type. */ @@ -587,6 +591,18 @@ public class WifiMetricsTest { for (int i = 0; i < NUM_PASSPOINT_PROVIDER_UNINSTALL_SUCCESS; i++) { mWifiMetrics.incrementNumPasspointProviderUninstallSuccess(); } + for (int i = 0; i < NUM_RADIO_MODE_CHANGE_TO_MCC; i++) { + mWifiMetrics.incrementNumRadioModeChangeToMcc(); + } + for (int i = 0; i < NUM_RADIO_MODE_CHANGE_TO_SCC; i++) { + mWifiMetrics.incrementNumRadioModeChangeToScc(); + } + for (int i = 0; i < NUM_RADIO_MODE_CHANGE_TO_SBS; i++) { + mWifiMetrics.incrementNumRadioModeChangeToSbs(); + } + for (int i = 0; i < NUM_RADIO_MODE_CHANGE_TO_DBS; i++) { + mWifiMetrics.incrementNumRadioModeChangeToDbs(); + } // increment pno scan metrics for (int i = 0; i < NUM_PNO_SCAN_ATTEMPTS; i++) { @@ -880,6 +896,10 @@ public class WifiMetricsTest { mDecodedProto.numPasspointProviderUninstallSuccess); assertEquals(NUM_PASSPOINT_PROVIDERS_SUCCESSFULLY_CONNECTED, mDecodedProto.numPasspointProvidersSuccessfullyConnected); + assertEquals(NUM_RADIO_MODE_CHANGE_TO_MCC, mDecodedProto.numRadioModeChangeToMcc); + 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); PnoScanMetrics pno_metrics = mDecodedProto.pnoScanMetrics; assertNotNull(pno_metrics); -- cgit v1.2.3