summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-03-02 14:15:44 -0800
committerRoshan Pius <rpius@google.com>2018-03-19 13:16:14 -0700
commitc7a347b9f084606cb1cf78eda4a1eb42539dc1d9 (patch)
tree9e4363e2254e05bd916a7c60542bdaae9dc19d52 /tests
parent4f11976612567e57eefb0b58c7aef1059f52b45c (diff)
ScanRequestProxy: Add a separate bg scan throttle mechanism
The current scan throttling mechanism is too lenient for background apps. So, split the throttling logic into two: a) For foreground apps, continue to throttle to a max of 1 scan per app every 30 seconds. b) For background apps, throttle to a max of 1 scan from any background app every 30 minutes. Bug: 68987915 Test: Unit tests Change-Id: I57915226e3be332ad6934e81ad69c218fe17ad30 Merged-In: I7c392429f8abaa00ea29b0a4479d010415d7b0ef
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java71
1 files changed, 64 insertions, 7 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
index aa7a821eb..7f684bc20 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
@@ -16,9 +16,13 @@
package com.android.server.wifi;
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
+
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import android.app.ActivityManager;
+import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
@@ -57,6 +61,8 @@ public class ScanRequestProxyTest {
}};
@Mock private Context mContext;
+ @Mock private AppOpsManager mAppOps;
+ @Mock private ActivityManager mActivityManager;
@Mock private WifiInjector mWifiInjector;
@Mock private WifiConfigManager mWifiConfigManager;
@Mock private WifiScanner mWifiScanner;
@@ -90,8 +96,8 @@ public class ScanRequestProxyTest {
mTestScanDatas2 = ScanTestUtil.createScanDatas(new int[][]{ { 2412, 2422, 5200, 5210 } });
mScanRequestProxy =
- new ScanRequestProxy(mContext, mWifiInjector, mWifiConfigManager,
- mWifiPermissionsUtil, mClock);
+ new ScanRequestProxy(mContext, mAppOps, mActivityManager, mWifiInjector,
+ mWifiConfigManager, mWifiPermissionsUtil, mClock);
}
@After
@@ -454,7 +460,7 @@ public class ScanRequestProxyTest {
/**
* Ensure new scan requests from the same app are rejected if it's before
- * {@link ScanRequestProxy#SCAN_REQUEST_THROTTLE_INTERVAL_MS}
+ * {@link ScanRequestProxy#SCAN_REQUEST_THROTTLE_INTERVAL_FG_APPS_MS}
*/
@Test
public void testSuccessiveScanRequestFromSameAppThrottled() {
@@ -465,7 +471,7 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
long secondRequestMs =
- firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_MS - 1;
+ firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_FG_APPS_MS - 1;
when(mClock.getElapsedSinceBootMillis()).thenReturn(secondRequestMs);
// Make scan request 2 from the same package name & ensure that it is throttled.
assertFalse(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
@@ -476,7 +482,7 @@ public class ScanRequestProxyTest {
/**
* Ensure new scan requests from the same app are not rejected if it's after
- * {@link ScanRequestProxy#SCAN_REQUEST_THROTTLE_INTERVAL_MS}
+ * {@link ScanRequestProxy#SCAN_REQUEST_THROTTLE_INTERVAL_FG_APPS_MS}
*/
@Test
public void testSuccessiveScanRequestFromSameAppNotThrottled() {
@@ -487,7 +493,7 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
long secondRequestMs =
- firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_MS + 1;
+ firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_FG_APPS_MS + 1;
when(mClock.getElapsedSinceBootMillis()).thenReturn(secondRequestMs);
// Make scan request 2 from the same package name & ensure that it is not throttled.
assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
@@ -511,7 +517,7 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
long secondRequestMs =
- firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_MS - 1;
+ firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_FG_APPS_MS - 1;
when(mClock.getElapsedSinceBootMillis()).thenReturn(secondRequestMs);
// Make scan request 2 from the same package name & ensure that it is not throttled.
assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
@@ -542,6 +548,57 @@ public class ScanRequestProxyTest {
verifyNoMoreInteractions(mWifiScanner, mWifiConfigManager, mContext);
}
+ /**
+ * Ensure scan requests from different background apps are throttled if it's before
+ * {@link ScanRequestProxy#SCAN_REQUEST_THROTTLE_INTERVAL_BG_APPS_MS}.
+ */
+ @Test
+ public void testSuccessiveScanRequestFromBgAppsThrottled() {
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1))
+ .thenReturn(IMPORTANCE_FOREGROUND_SERVICE + 1);
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_2))
+ .thenReturn(IMPORTANCE_FOREGROUND_SERVICE + 1);
+
+ long firstRequestMs = 782;
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(firstRequestMs);
+ // Make scan request 1.
+ assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
+ mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
+
+ // Make scan request 2 from the different package name & ensure that it is throttled.
+ assertFalse(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_2));
+ validateScanResultsFailureBroadcastSent(TEST_PACKAGE_NAME_2);
+
+ verifyNoMoreInteractions(mWifiScanner, mWifiConfigManager, mContext);
+ }
+
+ /**
+ * Ensure scan requests from different background apps are not throttled if it's after
+ * {@link ScanRequestProxy#SCAN_REQUEST_THROTTLE_INTERVAL_BG_APPS_MS}.
+ */
+ @Test
+ public void testSuccessiveScanRequestFromBgAppsNotThrottled() {
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1))
+ .thenReturn(ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND + 1);
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_2))
+ .thenReturn(ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND + 1);
+
+ long firstRequestMs = 782;
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(firstRequestMs);
+ // Make scan request 1.
+ assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
+ mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
+
+ long secondRequestMs =
+ firstRequestMs + ScanRequestProxy.SCAN_REQUEST_THROTTLE_INTERVAL_BG_APPS_MS + 1;
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(secondRequestMs);
+ // Make scan request 2 from the different package name & ensure that it is throttled.
+ assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_2));
+ mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
+
+ verifyNoMoreInteractions(mWifiScanner, mWifiConfigManager, mContext);
+ }
+
private void validateScanSettings(WifiScanner.ScanSettings scanSettings,
boolean expectHiddenNetworks) {
validateScanSettings(scanSettings, expectHiddenNetworks, false);