summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-02-21 12:57:04 -0800
committerRoshan Pius <rpius@google.com>2020-02-22 18:49:34 -0800
commit61282a6d2108c5d35fe699a049313525add5c8d2 (patch)
treea81c3cddb7b431b372d9de0bf651ed319c965cc4 /tests
parent7f06922f0540a679df06baf9cc70008fd1b1fe48 (diff)
wifi-service: Add a class for scan available settings compatibility
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE which is marked @hide is used extensively by external apps. Even though the wifi stack stopped using the setting, we need to provide compatibility support for set/get of that setting. Bug: 149954910 Test: Device boots up and connects to wifi networks. Test: Manually verification: Getter: - Change the scan available state from settings app (uses WifiManager. setScanAlwaysAvailable()) -'adb shell settings get global wifi_scan_always_enabled' Setter: -'adb shell settings put global wifi_scan_always_enabled 1' - Verified scan available state from settings app (uses WifiManager. isScanAlwaysAvailable). (cherry-picked from ag/10384217) Test: atest com.android.server.wifi Change-Id: I64b5d4d16eab1cda6c186153958601f41f7bcae7
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java135
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java6
3 files changed, 141 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java
new file mode 100644
index 000000000..2caa813c6
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static com.android.server.wifi.WifiScanAlwaysAvailableSettingsCompatibility.SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.validateMockitoUsage;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.os.Handler;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.WifiScanAlwaysAvailableSettingsCompatibility}.
+ */
+@SmallTest
+public class WifiScanAlwaysAvailableSettingsCompatibilityTest extends WifiBaseTest {
+ @Mock
+ private Context mContext;
+ @Mock
+ private Handler mHandler;
+ @Mock
+ private WifiSettingsStore mWifiSettingsStore;
+ @Mock
+ private ActiveModeWarden mActiveModeWarden;
+ @Mock
+ private FrameworkFacade mFrameworkFacade;
+ @Mock
+ private ContentResolver mContentResolver;
+
+ private ArgumentCaptor<ContentObserver> mContentObserverArgumentCaptor =
+ ArgumentCaptor.forClass(ContentObserver.class);
+
+ private WifiScanAlwaysAvailableSettingsCompatibility mScanAlwaysCompatibility;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ mScanAlwaysCompatibility =
+ new WifiScanAlwaysAvailableSettingsCompatibility(mContext, mHandler,
+ mWifiSettingsStore, mActiveModeWarden, mFrameworkFacade);
+ }
+
+ /**
+ * Called after each test
+ */
+ @After
+ public void cleanup() {
+ validateMockitoUsage();
+ }
+
+ @Test
+ public void reactToContentObserverChanges() {
+ mScanAlwaysCompatibility.initialize();
+ verify(mContentResolver).registerContentObserver(
+ any(), anyBoolean(), mContentObserverArgumentCaptor.capture());
+
+ ContentObserver contentObserver = mContentObserverArgumentCaptor.getValue();
+ assertNotNull(contentObserver);
+
+ when(mWifiSettingsStore.isScanAlwaysAvailable()).thenReturn(false);
+ when(mFrameworkFacade.getIntegerSetting(
+ any(ContentResolver.class),
+ eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE),
+ anyInt()))
+ .thenReturn(1);
+ contentObserver.onChange(false);
+
+ verify(mWifiSettingsStore).handleWifiScanAlwaysAvailableToggled(true);
+ verify(mActiveModeWarden).scanAlwaysModeChanged();
+
+ when(mWifiSettingsStore.isScanAlwaysAvailable()).thenReturn(true);
+ when(mFrameworkFacade.getIntegerSetting(
+ any(ContentResolver.class),
+ eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE),
+ anyInt()))
+ .thenReturn(0);
+ contentObserver.onChange(false);
+
+ verify(mWifiSettingsStore).handleWifiScanAlwaysAvailableToggled(false);
+ verify(mActiveModeWarden, times(2)).scanAlwaysModeChanged();
+ }
+
+
+ @Test
+ public void changeSetting() {
+ mScanAlwaysCompatibility.initialize();
+
+ mScanAlwaysCompatibility.handleWifiScanAlwaysAvailableToggled(true);
+ verify(mFrameworkFacade).setIntegerSetting(
+ any(ContentResolver.class),
+ eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE),
+ eq(1));
+
+ mScanAlwaysCompatibility.handleWifiScanAlwaysAvailableToggled(false);
+ verify(mFrameworkFacade).setIntegerSetting(
+ any(ContentResolver.class),
+ eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE),
+ eq(0));
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 08380614d..f1e515b9c 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -307,6 +307,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
@Mock IOnWifiActivityEnergyInfoListener mOnWifiActivityEnergyInfoListener;
@Mock IWifiConnectedNetworkScorer mWifiConnectedNetworkScorer;
@Mock WifiSettingsConfigStore mWifiSettingsConfigStore;
+ @Mock WifiScanAlwaysAvailableSettingsCompatibility mScanAlwaysAvailableSettingsCompatibility;
WifiLog mLog = new LogcatLog(TAG);
@@ -380,6 +381,8 @@ public class WifiServiceImplTest extends WifiBaseTest {
when(mWifiInjector.getWifiThreadRunner())
.thenReturn(new WifiThreadRunner(new Handler(mLooper.getLooper())));
when(mWifiInjector.getSettingsConfigStore()).thenReturn(mWifiSettingsConfigStore);
+ when(mWifiInjector.getWifiScanAlwaysAvailableSettingsCompatibility())
+ .thenReturn(mScanAlwaysAvailableSettingsCompatibility);
when(mClientModeImpl.syncStartSubscriptionProvisioning(anyInt(),
any(OsuProvider.class), any(IProvisioningCallback.class), any())).thenReturn(true);
// Create an OSU provider that can be provisioned via an open OSU AP
diff --git a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java
index 7f6e1e1cd..799df547b 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java
@@ -1224,17 +1224,17 @@ public class WifiPermissionsUtilTest extends WifiBaseTest {
doThrow(new RuntimeException()).when(mLocationManager).isLocationEnabledForUser(any());
when(mMockFrameworkFacade.getIntegerSetting(
- any(), eq(Settings.Secure.LOCATION_MODE), anyInt()))
+ any(Context.class), eq(Settings.Secure.LOCATION_MODE), anyInt()))
.thenReturn(Settings.Secure.LOCATION_MODE_OFF);
assertFalse(codeUnderTest.isLocationModeEnabled());
when(mMockFrameworkFacade.getIntegerSetting(
- any(), eq(Settings.Secure.LOCATION_MODE), anyInt()))
+ any(Context.class), eq(Settings.Secure.LOCATION_MODE), anyInt()))
.thenReturn(Settings.Secure.LOCATION_MODE_ON);
assertTrue(codeUnderTest.isLocationModeEnabled());
verify(mMockFrameworkFacade, times(2)).getIntegerSetting(
- any(), eq(Settings.Secure.LOCATION_MODE), anyInt());
+ any(Context.class), eq(Settings.Secure.LOCATION_MODE), anyInt());
}
private Answer<Integer> createPermissionAnswer() {