diff options
author | Etan Cohen <etancohen@google.com> | 2019-12-01 21:10:20 -0800 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2019-12-09 20:56:33 -0800 |
commit | 324c2515179766a346f6f19160d2daf17d0d9153 (patch) | |
tree | 8b4c4b2cb03b836b06314593333fc2f532cb899d | |
parent | 395983b1f1e42f7956b77f909340bd510996bc44 (diff) |
[WIFI][MAINLINE] Transition WificondControl interfaces: PNO metrics
Transition WificondControl public interfaces to that class itself.
Preparation for the class being extracted to an official API.
Classes shifted: PNO metrics
Bug: 140062898
Test: atest android.net.wifi
Test: atest com.android.server.wifi
Change-Id: I10fccbd960db5c18aa1338236aabb2dd676ea5d6
6 files changed, 67 insertions, 19 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index e8d62a56d..f313cdaa9 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -883,7 +883,7 @@ public class WifiMetrics { /** * Increment total number of attempts to start a pno scan */ - public void incrementPnoScanStartAttempCount() { + public void incrementPnoScanStartAttemptCount() { synchronized (mLock) { mPnoScanMetrics.numPnoScanAttempts++; } diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index e0b1fd642..3dde35ed9 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1544,7 +1544,19 @@ public class WifiNative { * @return true on success. */ public boolean startPnoScan(@NonNull String ifaceName, PnoSettings pnoSettings) { - return mWificondControl.startPnoScan(ifaceName, pnoSettings.toNativePnoSettings()); + return mWificondControl.startPnoScan(ifaceName, pnoSettings.toNativePnoSettings(), + new WificondControl.PnoScanRequestCallback() { + @Override + public void onPnoRequestSucceeded() { + mWifiMetrics.incrementPnoScanStartAttemptCount(); + } + + @Override + public void onPnoRequestFailed() { + mWifiMetrics.incrementPnoScanStartAttemptCount(); + mWifiMetrics.incrementPnoScanFailedCount(); + } + }); } /** diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index a717f624b..ec813b356 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -117,6 +117,21 @@ public class WificondControl implements IBinder.DeathRecipient { void onScanFailed(); } + /** + * Interface for a callback to provide information about PNO scan request. + */ + public interface PnoScanRequestCallback { + /** + * Called when the PNO scan is requested. + */ + void onPnoRequestSucceeded(); + + /** + * Called when a PNO scan request fails. + */ + void onPnoRequestFailed(); + } + private class ScanEventHandler extends IScanEvent.Stub { private ScanEventCallback mCallback; @@ -792,7 +807,8 @@ public class WificondControl implements IBinder.DeathRecipient { * @param pnoSettings Pno scan configuration. * @return true on success. */ - public boolean startPnoScan(@NonNull String ifaceName, PnoSettings pnoSettings) { + public boolean startPnoScan(@NonNull String ifaceName, PnoSettings pnoSettings, + PnoScanRequestCallback callback) { IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName); if (scannerImpl == null) { Log.e(TAG, "No valid wificond scanner interface handler"); @@ -801,9 +817,10 @@ public class WificondControl implements IBinder.DeathRecipient { try { boolean success = scannerImpl.startPnoScan(pnoSettings); - mWifiInjector.getWifiMetrics().incrementPnoScanStartAttempCount(); - if (!success) { - mWifiInjector.getWifiMetrics().incrementPnoScanFailedCount(); + if (success) { + callback.onPnoRequestSucceeded(); + } else { + callback.onPnoRequestFailed(); } return success; } catch (RemoteException e1) { diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 0eb8f84df..c63cf487e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -793,7 +793,7 @@ public class WifiMetricsTest extends WifiBaseTest { // increment pno scan metrics for (int i = 0; i < NUM_PNO_SCAN_ATTEMPTS; i++) { - mWifiMetrics.incrementPnoScanStartAttempCount(); + mWifiMetrics.incrementPnoScanStartAttemptCount(); } for (int i = 0; i < NUM_PNO_SCAN_FAILED; i++) { mWifiMetrics.incrementPnoScanFailedCount(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java index cfa555f22..1e4e86d40 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java @@ -754,10 +754,31 @@ public class WifiNativeTest extends WifiBaseTest { * Verifies that startPnoscan() calls underlying WificondControl. */ @Test - public void testStartPnoScan() throws Exception { + public void testStartPnoScanOnRequestProcessed() throws Exception { mWifiNative.startPnoScan(WIFI_IFACE_NAME, TEST_PNO_SETTINGS); - verify(mWificondControl).startPnoScan( - WIFI_IFACE_NAME, TEST_PNO_SETTINGS.toNativePnoSettings()); + + ArgumentCaptor<WificondControl.PnoScanRequestCallback> captor = ArgumentCaptor.forClass( + WificondControl.PnoScanRequestCallback.class); + verify(mWificondControl).startPnoScan(eq(WIFI_IFACE_NAME), + eq(TEST_PNO_SETTINGS.toNativePnoSettings()), captor.capture()); + captor.getValue().onPnoRequestSucceeded(); + verify(mWifiMetrics).incrementPnoScanStartAttemptCount(); + } + + /** + * Verifies that startPnoscan() calls underlying WificondControl. + */ + @Test + public void testStartPnoScanOnRequestFailed() throws Exception { + mWifiNative.startPnoScan(WIFI_IFACE_NAME, TEST_PNO_SETTINGS); + + ArgumentCaptor<WificondControl.PnoScanRequestCallback> captor = ArgumentCaptor.forClass( + WificondControl.PnoScanRequestCallback.class); + verify(mWificondControl).startPnoScan(eq(WIFI_IFACE_NAME), + eq(TEST_PNO_SETTINGS.toNativePnoSettings()), captor.capture()); + captor.getValue().onPnoRequestFailed(); + verify(mWifiMetrics).incrementPnoScanStartAttemptCount(); + verify(mWifiMetrics).incrementPnoScanFailedCount(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java index 93afc4eb1..869cf0e04 100644 --- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java @@ -84,10 +84,6 @@ public class WificondControlTest extends WifiBaseTest { @Mock private WifiInjector mWifiInjector; @Mock - private WifiMonitor mWifiMonitor; - @Mock - private WifiMetrics mWifiMetrics; - @Mock private IWificond mWificond; @Mock private IBinder mWifiCondBinder; @@ -109,6 +105,8 @@ public class WificondControlTest extends WifiBaseTest { private WificondControl.ScanEventCallback mNormalScanCallback; @Mock private WificondControl.ScanEventCallback mPnoScanCallback; + @Mock + private WificondControl.PnoScanRequestCallback mPnoScanRequestCallback; private TestLooper mLooper; private WificondControl mWificondControl; private static final String TEST_INTERFACE_NAME = "test_wlan_if"; @@ -176,7 +174,6 @@ public class WificondControlTest extends WifiBaseTest { when(mWificond.tearDownApInterface(any())).thenReturn(true); when(mClientInterface.getWifiScannerImpl()).thenReturn(mWifiScannerImpl); when(mClientInterface.getInterfaceName()).thenReturn(TEST_INTERFACE_NAME); - when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics); mLooper = new TestLooper(); mWificondControl = new WificondControl(mWifiInjector, mAlarmManager, new Handler(mLooper.getLooper()), mClock); @@ -618,8 +615,9 @@ public class WificondControlTest extends WifiBaseTest { public void testStartPnoScan() throws Exception { when(mWifiScannerImpl.startPnoScan(any(PnoSettings.class))).thenReturn(true); assertTrue(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, - TEST_PNO_SETTINGS.toNativePnoSettings())); + TEST_PNO_SETTINGS.toNativePnoSettings(), mPnoScanRequestCallback)); verify(mWifiScannerImpl).startPnoScan(argThat(new PnoScanMatcher(TEST_PNO_SETTINGS))); + verify(mPnoScanRequestCallback).onPnoRequestSucceeded(); } /** @@ -710,10 +708,10 @@ public class WificondControlTest extends WifiBaseTest { @Test public void testStartPnoScanForMetrics() throws Exception { when(mWifiScannerImpl.startPnoScan(any(PnoSettings.class))).thenReturn(false); + assertFalse(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, - TEST_PNO_SETTINGS.toNativePnoSettings())); - verify(mWifiMetrics).incrementPnoScanStartAttempCount(); - verify(mWifiMetrics).incrementPnoScanFailedCount(); + TEST_PNO_SETTINGS.toNativePnoSettings(), mPnoScanRequestCallback)); + verify(mPnoScanRequestCallback).onPnoRequestFailed(); } /** |