diff options
author | Roshan Pius <rpius@google.com> | 2019-08-14 19:33:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-08-14 19:33:10 +0000 |
commit | 89d0799578d787a883702242adf511463d3b7756 (patch) | |
tree | e0ed478cae2c5c113a814682367e2e42df4a9e2f /tests | |
parent | 2d0f9652cf0a4997da39bd144acf9c4e0510e7d4 (diff) | |
parent | 1ca5e145a383d00e05b8ef1240abeaf08ddea70c (diff) |
Merge changes from topic "wifi_mainline_apk_separation"
* changes:
Revert "WifiService: Ignore wifi state change API in crypt debounce state"
WifiScanningService: Use Context.checkPermission
WifiStackService: Register wifi API services from system_server
Create Mainline wifi stack module
Create Mainline wifi stack permission module
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.bp | 19 | ||||
-rw-r--r-- | tests/Android.mk | 21 | ||||
-rw-r--r-- | tests/wifitests/Android.bp | 96 | ||||
-rw-r--r-- | tests/wifitests/Android.mk | 123 | ||||
-rwxr-xr-x | tests/wifitests/runtests.sh | 2 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java | 29 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 107 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java | 62 |
8 files changed, 179 insertions, 280 deletions
diff --git a/tests/Android.bp b/tests/Android.bp new file mode 100644 index 000000000..087691d89 --- /dev/null +++ b/tests/Android.bp @@ -0,0 +1,19 @@ +// Copyright (C) 2019 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. + +// Include subdirectory makefiles +// ============================================================ +subdirs = [ + "wifitests", +] diff --git a/tests/Android.mk b/tests/Android.mk deleted file mode 100644 index 2027fefeb..000000000 --- a/tests/Android.mk +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2015 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. - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -# Include subdirectory makefiles -# ============================================================ -include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/tests/wifitests/Android.bp b/tests/wifitests/Android.bp new file mode 100644 index 000000000..b0ff2cf90 --- /dev/null +++ b/tests/wifitests/Android.bp @@ -0,0 +1,96 @@ +// Copyright (C) 2015 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. + +// Make test APK +// ============================================================ +android_test { + // TODO(rpius): Rename once all google3 config files are changed + // name: "WifiStackTests", + name: "FrameworksWifiTests", + + srcs: ["**/*.java"], + + dxflags: ["--multi-dex"], + + // wifi-service and services must be included here so that the latest changes + // will be used when tests. Otherwise the tests would run against the installed + // system. + // TODO figure out if this is the correct thing to do, this seems to not be right + // since neither is declared a static java library. + static_libs: [ + "androidx.test.rules", + "hamcrest-library", + "mockito-target-extended-minus-junit4", + "frameworks-base-testutils", + "services", + "WifiStackBase", + "truth-prebuilt", + ], + + libs: [ + "android.test.runner", + "android.hidl.manager-V1.2-java", + "android.test.base", + "android.test.mock", + ], + + // These must be explicitly included because they are not normally accessible + // from apps. + jni_libs: [ + "libcrypto", + "libwifi-jni", + "libEGL", + "libGLESv2", + "libaudioutils", + "libbacktrace", + "libbase", + "libbinder", + "libbinderthreadstate", + "libc++", + "ld-android", + "libdl_android", + "libcamera_client", + "libcamera_metadata", + "libcgrouprc", + "libcutils", + "libexpat", + "libgui", + "libhardware", + "libandroidicu", + "libjsoncpp", + "liblzma", + "libmedia", + "libnativehelper", + "libnbaio", + "libnetutils", + "libnl", + "libpowermanager", + "libprocessgroup", + "libsonivox", + "libstagefright_foundation", + "libstdc++", + "libsync", + "libwifi-system", + "libui", + "libunwindstack", + "libutils", + "libvndksupport", + "libdexmakerjvmtiagent", + "libstaticjvmtiagent", + ], + min_sdk_version: "29", + platform_apis: true, + privileged: true, + test_suites: ["device-tests"], +} diff --git a/tests/wifitests/Android.mk b/tests/wifitests/Android.mk deleted file mode 100644 index 8e48f0c7f..000000000 --- a/tests/wifitests/Android.mk +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (C) 2015 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. - -LOCAL_PATH:= $(call my-dir) - -# Make test APK -# ============================================================ -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_SRC_FILES := $(call all-subdir-java-files) - -# Provide jack a list of classes to exclude form code coverage -# This list is generated from the java source files in this module -# The list is a comma separated list of class names with * matching zero or more characters. -# Example: -# Input files: src/com/android/server/wifi/Test.java src/com/android/server/wifi/AnotherTest.java -# Generated exclude list: com.android.server.wifi.Test*,com.android.server.wifi.AnotherTest* - -# Filter all src files to just java files -local_java_files := $(filter %.java,$(LOCAL_SRC_FILES)) -# Transform java file names into full class names. -# This only works if the class name matches the file name and the directory structure -# matches the package. -local_classes := $(subst /,.,$(patsubst src/%.java,%,$(local_java_files))) -# Convert class name list to jacoco exclude list -# This appends a * to all classes and replace the space separators with commas. -# These patterns will match all classes in this module and their inner classes. -jacoco_exclude := $(subst $(space),$(comma),$(patsubst %,%*,$(local_classes))) - -jacoco_include := com.android.server.wifi.* - -LOCAL_JACK_COVERAGE_INCLUDE_FILTER := $(jacoco_include) -LOCAL_JACK_COVERAGE_EXCLUDE_FILTER := $(jacoco_exclude) - -LOCAL_DX_FLAGS := --multi-dex -LOCAL_JACK_FLAGS := --multi-dex native - -# wifi-service and services must be included here so that the latest changes -# will be used when tests. Otherwise the tests would run against the installed -# system. -# TODO figure out if this is the correct thing to do, this seems to not be right -# since neither is declared a static java library. -LOCAL_STATIC_JAVA_LIBRARIES := \ - androidx.test.rules hamcrest-library \ - mockito-target-extended-minus-junit4 \ - frameworks-base-testutils \ - services \ - wifi-service \ - truth-prebuilt \ - -LOCAL_JAVA_LIBRARIES := \ - android.test.runner \ - android.hidl.manager-V1.2-java \ - android.test.base \ - android.test.mock - -# These must be explicitly included because they are not normally accessible -# from apps. -LOCAL_JNI_SHARED_LIBRARIES := \ - libcrypto \ - libwifi-service \ - libEGL \ - libGLESv2 \ - libaudioutils \ - libbacktrace \ - libbase \ - libbinder \ - libbinderthreadstate \ - libc++ \ - ld-android \ - libdl_android \ - libcamera_client \ - libcamera_metadata \ - libcgrouprc \ - libcutils \ - libexpat \ - libgui \ - libhardware \ - libandroidicu \ - libjsoncpp \ - liblzma \ - libmedia \ - libnativehelper \ - libnbaio \ - libnetutils \ - libnl \ - libpowermanager \ - libprocessgroup \ - libsonivox \ - libstagefright_foundation \ - libstdc++ \ - libsync \ - libwifi-system \ - libui \ - libunwindstack \ - libutils \ - libvndksupport \ - libdexmakerjvmtiagent \ - libstaticjvmtiagent - -ifdef WPA_SUPPLICANT_VERSION -LOCAL_JNI_SHARED_LIBRARIES += libwpa_client -endif - -LOCAL_PACKAGE_NAME := FrameworksWifiTests -LOCAL_PRIVATE_PLATFORM_APIS := true - -LOCAL_COMPATIBILITY_SUITE := device-tests - -include $(BUILD_PACKAGE) diff --git a/tests/wifitests/runtests.sh b/tests/wifitests/runtests.sh index 6e831994a..085098a94 100755 --- a/tests/wifitests/runtests.sh +++ b/tests/wifitests/runtests.sh @@ -31,7 +31,7 @@ set -e # fail early echo "+ mmma -j32 $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/tests" # NOTE Don't actually run the command above since this shell doesn't inherit functions from the # caller. -$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode MODULES-IN-frameworks-opt-net-wifi-tests +$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode MODULES-IN-frameworks-opt-net-wifi-tests-wifitests APK_NAME="$(ls -t $(find $OUT -name FrameworksWifiTests.apk) | head -n 1)" set -x # print commands diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java index c18278893..978a0a5d9 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java @@ -81,6 +81,7 @@ public class WifiApConfigStoreTest { private static final String TEST_STRING_UTF8_WITH_34_BYTES = "Ευπροσηγοροςγινου"; @Mock private Context mContext; + @Mock private WifiInjector mWifiInjector; private TestLooper mLooper; @Mock private BackupManagerProxy mBackupManagerProxy; @Mock private FrameworkFacade mFrameworkFacade; @@ -139,7 +140,7 @@ public class WifiApConfigStoreTest { */ private WifiApConfigStore createWifiApConfigStore() { WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor = @@ -212,7 +213,7 @@ public class WifiApConfigStoreTest { @Test public void initWithDefaultConfiguration() throws Exception { WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); } @@ -232,7 +233,7 @@ public class WifiApConfigStoreTest { true /* Hidden SSID */); writeApConfigFile(expectedConfig); WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyApConfig(expectedConfig, store.getApConfiguration()); } @@ -254,7 +255,7 @@ public class WifiApConfigStoreTest { true /* Hidden SSID */); writeApConfigFile(expectedConfig); WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -270,7 +271,7 @@ public class WifiApConfigStoreTest { public void updateApConfiguration() throws Exception { /* Initialize WifiApConfigStore with default configuration. */ WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); @@ -296,7 +297,7 @@ public class WifiApConfigStoreTest { public void convertSingleModeDeviceAnyTo5Ghz() throws Exception { /* Initialize WifiApConfigStore with default configuration. */ WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); @@ -330,7 +331,7 @@ public class WifiApConfigStoreTest { public void singleModeDevice5GhzNotConverted() throws Exception { /* Initialize WifiApConfigStore with default configuration. */ WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); @@ -357,7 +358,7 @@ public class WifiApConfigStoreTest { /* Initialize WifiApConfigStore with default configuration. */ WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); @@ -393,7 +394,7 @@ public class WifiApConfigStoreTest { /* Initialize WifiApConfigStore with default configuration. */ WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); @@ -434,7 +435,7 @@ public class WifiApConfigStoreTest { false /* Hidden SSID */); writeApConfigFile(persistedConfig); WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyApConfig(expectedConfig, store.getApConfiguration()); verify(mBackupManagerProxy).notifyDataChanged(); @@ -457,7 +458,7 @@ public class WifiApConfigStoreTest { writeApConfigFile(persistedConfig); WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyApConfig(persistedConfig, store.getApConfiguration()); verify(mBackupManagerProxy, never()).notifyDataChanged(); @@ -489,7 +490,7 @@ public class WifiApConfigStoreTest { writeApConfigFile(persistedConfig); WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyApConfig(expectedConfig, store.getApConfiguration()); verify(mBackupManagerProxy).notifyDataChanged(); @@ -514,7 +515,7 @@ public class WifiApConfigStoreTest { writeApConfigFile(persistedConfig); WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); verifyApConfig(persistedConfig, store.getApConfiguration()); verify(mBackupManagerProxy, never()).notifyDataChanged(); @@ -526,7 +527,7 @@ public class WifiApConfigStoreTest { @Test public void getDefaultApConfigurationIsValid() { WifiApConfigStore store = new WifiApConfigStore( - mContext, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, + mContext, mWifiInjector, mLooper.getLooper(), mBackupManagerProxy, mFrameworkFacade, mApConfigFile.getPath()); WifiConfiguration config = store.getApConfiguration(); assertTrue(WifiApConfigStore.validateApWifiConfiguration(config)); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index d74f364e1..5bb420630 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -101,6 +101,7 @@ import android.net.wifi.WifiManager.LocalOnlyHotspotCallback; import android.net.wifi.WifiManager.SoftApCallback; import android.net.wifi.WifiNetworkSuggestion; import android.net.wifi.WifiSsid; +import android.net.wifi.WifiStackClient; import android.net.wifi.hotspot2.IProvisioningCallback; import android.net.wifi.hotspot2.OsuProvider; import android.net.wifi.hotspot2.PasspointConfiguration; @@ -397,6 +398,8 @@ public class WifiServiceImplTest { anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_MANAGED_PROVISIONING), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mScanRequestProxy.startScan(anyInt(), anyString())).thenReturn(true); ArgumentCaptor<SoftApCallback> softApCallbackCaptor = @@ -654,20 +657,6 @@ public class WifiServiceImplTest { } /** - * Verify that wifi is not enabled when wificontroller is not started. - */ - @Test - public void testSetWifiEnabledFailureWhenInCryptDebounce() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true); - when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), - anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); - when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); - when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); - assertFalse(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true)); - verifyZeroInteractions(mWifiController); - } - - /** * Verify that wifi cannot be enabled by the apps targeting Q SDK. */ @Test @@ -919,20 +908,6 @@ public class WifiServiceImplTest { } /** - * Verify that wifi is not disabled when wificontroller is not started. - */ - @Test - public void testSetWifiDisabledFailureWhenInCryptDebounce() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true); - when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), - anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); - when(mSettingsStore.handleWifiToggled(eq(false))).thenReturn(false); - when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); - assertFalse(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, false)); - verifyZeroInteractions(mWifiController); - } - - /** * Verify that wifi cannot be disabled by the apps targeting Q SDK. */ @Test @@ -1051,7 +1026,6 @@ public class WifiServiceImplTest { mWifiServiceImpl = new WifiServiceImpl(mContext, mWifiInjector, mAsyncChannel); mWifiServiceImpl.setWifiHandlerLogForTest(mLog); - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true); @@ -1077,7 +1051,6 @@ public class WifiServiceImplTest { // ap should be disabled when wifi hasn't been started assertEquals(WifiManager.WIFI_AP_STATE_DISABLED, mWifiServiceImpl.getWifiApEnabledState()); - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); mLooper.dispatchAll(); @@ -1114,22 +1087,10 @@ public class WifiServiceImplTest { } /** - * Make sure we do not start wifi if System services have to be restarted to decrypt the device. - */ - @Test - public void testWifiControllerDoesNotStartWhenDeviceTriggerResetMainAtBoot() { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true); - when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); - mWifiServiceImpl.checkAndStartWifi(); - verify(mWifiController, never()).start(); - } - - /** * Make sure we do start WifiController (wifi disabled) if the device is already decrypted. */ @Test - public void testWifiControllerStartsWhenDeviceIsDecryptedAtBootWithWifiDisabled() { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); + public void testWifiControllerStartsWhenDeviceBootsWithWifiDisabled() { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); verify(mWifiController).start(); @@ -1140,8 +1101,7 @@ public class WifiServiceImplTest { * Make sure we do start WifiController (wifi enabled) if the device is already decrypted. */ @Test - public void testWifiFullyStartsWhenDeviceIsDecryptedAtBootWithWifiEnabled() { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); + public void testWifiFullyStartsWhenDeviceBootsWithWifiEnabled() { when(mSettingsStore.handleWifiToggled(true)).thenReturn(true); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(true); when(mClientModeImpl.syncGetWifiState()).thenReturn(WIFI_STATE_DISABLED); @@ -1189,19 +1149,6 @@ public class WifiServiceImplTest { } /** - * Verify does not start softap when wificontroller is not started. - */ - @Test - public void testStartSoftApWhenInCryptDebounce() { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true); - - WifiConfiguration config = createValidSoftApConfiguration(); - boolean result = mWifiServiceImpl.startSoftAp(config); - assertFalse(result); - verifyZeroInteractions(mWifiController); - } - - /** * Verify a SecurityException is thrown when a caller without the correct permission attempts to * start softap. */ @@ -1225,18 +1172,6 @@ public class WifiServiceImplTest { } /** - * Verify does not stop softap when wificontroller is not started. - */ - @Test - public void testStopSoftApWhenInCryptDebounce() { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true); - - boolean result = mWifiServiceImpl.stopSoftAp(); - assertFalse(result); - verifyZeroInteractions(mWifiController); - } - - /** * Verify SecurityException is thrown when a caller without the correct permission attempts to * stop softap. */ @@ -1591,19 +1526,6 @@ public class WifiServiceImplTest { } /** - * Only start LocalOnlyHotspot if device is in crypt debounce mode. - */ - @Test - public void testStartLocalOnlyHotspotFailsIfInCryptDebounce() throws Exception { - when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true); - when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true); - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true); - int result = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder, - TEST_PACKAGE_NAME); - assertEquals(LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE, result); - } - - /** * Only start LocalOnlyHotspot if we are not tethering. */ @Test @@ -1621,6 +1543,7 @@ public class WifiServiceImplTest { // Start another session without a stop, that should fail. assertFalse(mWifiServiceImpl.startSoftAp(createValidSoftApConfiguration())); + verifyNoMoreInteractions(mWifiController); } @@ -2085,7 +2008,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksTriggeredOnSoftApFailureGeneric() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2110,7 +2032,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksTriggeredOnSoftApFailureNoChannel() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2137,8 +2058,6 @@ public class WifiServiceImplTest { @Test public void testRegisteredCallbacksTriggeredOnSoftApDisabling() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2172,8 +2091,6 @@ public class WifiServiceImplTest { @Test public void testRegisteredCallbacksTriggeredOnSoftApDisabled() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2205,7 +2122,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksNotTriggeredOnSoftApStart() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2230,8 +2146,6 @@ public class WifiServiceImplTest { @Test public void testRegisteredCallbacksTriggeredOnlyOnceWhenSoftApDisabling() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2266,7 +2180,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksTriggeredOnlyOnceWhenSoftApFailsTwice() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2295,7 +2208,6 @@ public class WifiServiceImplTest { */ @Test public void testAllRegisteredCallbacksTriggeredWhenSoftApFails() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2330,8 +2242,6 @@ public class WifiServiceImplTest { @Test public void testAllRegisteredCallbacksTriggeredWhenSoftApStops() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2372,8 +2282,6 @@ public class WifiServiceImplTest { @Test public void testAllRegisteredCallbacksTriggeredWhenSoftApStopsLOHSNotActive() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2554,8 +2462,6 @@ public class WifiServiceImplTest { public void testRegisterLocalOnlyHotspotRequestAfterStoppedNoOnStartedCallback() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), @@ -3145,7 +3051,6 @@ public class WifiServiceImplTest { @Test public void testHandleDelayedScanAfterIdleMode() throws Exception { setupClientModeImplHandlerForRunWithScissors(); - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index c2c974499..9faa7a890 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -17,6 +17,7 @@ package com.android.server.wifi.scanner; import static android.content.pm.PackageManager.PERMISSION_DENIED; +import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static com.android.server.wifi.ScanTestUtil.NativeScanSettingsBuilder; import static com.android.server.wifi.ScanTestUtil.assertNativePnoSettingsEquals; @@ -51,13 +52,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import android.Manifest; import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.app.test.TestAlarmManager; import android.content.BroadcastReceiver; import android.content.Context; import android.net.wifi.ScanResult; import android.net.wifi.WifiScanner; +import android.net.wifi.WifiStackClient; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -165,6 +166,9 @@ public class WifiScanningServiceTest { when(mFrameworkFacade.makeWifiAsyncChannel(anyString())).thenReturn(mWifiAsyncChannel); when(mWifiInjector.getFrameworkFacade()).thenReturn(mFrameworkFacade); when(mWifiInjector.getClock()).thenReturn(mClock); + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) + .thenReturn(PERMISSION_GRANTED); mWifiScanningServiceImpl = new WifiScanningServiceImpl(mContext, mLooper.getLooper(), mWifiScannerImplFactory, mBatteryStats, mWifiInjector); } @@ -700,8 +704,8 @@ public class WifiScanningServiceTest { requestSettings.type = WifiScanner.TYPE_HIGH_ACCURACY; WorkSource workSource = new WorkSource(Binder.getCallingUid()); // don't explicitly set - when(mContext.checkPermission( - Manifest.permission.NETWORK_STACK, -1, Binder.getCallingUid())) + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) .thenReturn(PERMISSION_DENIED); startServiceAndLoadDriver(); @@ -752,8 +756,8 @@ public class WifiScanningServiceTest { }; WorkSource workSource = new WorkSource(Binder.getCallingUid()); // don't explicitly set - when(mContext.checkPermission( - Manifest.permission.NETWORK_STACK, -1, Binder.getCallingUid())) + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) .thenReturn(PERMISSION_DENIED); startServiceAndLoadDriver(); @@ -839,8 +843,8 @@ public class WifiScanningServiceTest { @Test public void sendSingleScanRequestWithNoPrivilegedParamsSetFromNonPrivilegedApp() throws Exception { - when(mContext.checkPermission( - Manifest.permission.NETWORK_STACK, -1, Binder.getCallingUid())) + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) .thenReturn(PERMISSION_DENIED); WifiScanner.ScanSettings requestSettings = createRequest(channelsToSpec(2400, 5150, 5175), 0, 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); @@ -2484,7 +2488,7 @@ public class WifiScanningServiceTest { } /** - * Verifies that only clients with NETWORK_STACK permission can issues restricted messages + * Verifies that only clients with PERMISSION_MAINLINE_WIFI_STACK permission can issues restricted messages * (from API's). */ @Test @@ -2494,9 +2498,10 @@ public class WifiScanningServiceTest { Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); - // Client doesn't have NETWORK_STACK permission. + // Client doesn't have PERMISSION_MAINLINE_WIFI_STACK permission. doThrow(new SecurityException()).when(mContext).enforcePermission( - eq(Manifest.permission.NETWORK_STACK), anyInt(), eq(Binder.getCallingUid()), any()); + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); controlChannel.sendMessage(Message.obtain(null, WifiScanner.CMD_ENABLE)); mLooper.dispatchAll(); @@ -2534,13 +2539,20 @@ public class WifiScanningServiceTest { } /** - * Verifies that clients without NETWORK_STACK permission cannot issue any messages when they + * Verifies that clients without PERMISSION_MAINLINE_WIFI_STACK permission cannot issue any messages when they * don't have the necessary location permissions & location is enabled. */ @Test public void rejectAllMessagesFromNonPrivilegedAppsWithoutLocationPermission() throws Exception { // Start service & initialize it. startServiceAndLoadDriver(); + doThrow(new SecurityException()).when(mContext).enforcePermission( + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) + .thenReturn(PERMISSION_DENIED); + // Location permission or mode check fail. doThrow(new SecurityException()).when(mWifiPermissionsUtil) .enforceCanAccessScanResultsForWifiScanner(any(), eq(Binder.getCallingUid()), @@ -2549,9 +2561,10 @@ public class WifiScanningServiceTest { Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); - // Client doesn't have NETWORK_STACK permission. - doThrow(new SecurityException()).when(mContext).enforcePermission( - eq(Manifest.permission.NETWORK_STACK), anyInt(), eq(Binder.getCallingUid()), any()); + // Client doesn't have PERMISSION_MAINLINE_WIFI_STACK permission. + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) + .thenReturn(PERMISSION_DENIED); controlChannel.sendMessage(Message.obtain(null, WifiScanner.CMD_START_SINGLE_SCAN)); mLooper.dispatchAll(); @@ -2593,9 +2606,13 @@ public class WifiScanningServiceTest { Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); - // Client doesn't have NETWORK_STACK permission. + // Client doesn't have PERMISSION_MAINLINE_WIFI_STACK permission. doThrow(new SecurityException()).when(mContext).enforcePermission( - eq(Manifest.permission.NETWORK_STACK), anyInt(), eq(Binder.getCallingUid()), any()); + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) + .thenReturn(PERMISSION_DENIED); Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); @@ -2653,9 +2670,13 @@ public class WifiScanningServiceTest { Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); - // Client doesn't have NETWORK_STACK permission. + // Client doesn't have PERMISSION_MAINLINE_WIFI_STACK permission. doThrow(new SecurityException()).when(mContext).enforcePermission( - eq(Manifest.permission.NETWORK_STACK), anyInt(), eq(Binder.getCallingUid()), any()); + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); + when(mContext.checkPermission(eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), + anyInt(), eq(Binder.getCallingUid()))) + .thenReturn(PERMISSION_DENIED); Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); @@ -2715,9 +2736,10 @@ public class WifiScanningServiceTest { Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); - // Client does have NETWORK_STACK permission. + // Client does have WIFI_STACK permission. doNothing().when(mContext).enforcePermission( - eq(Manifest.permission.NETWORK_STACK), anyInt(), eq(Binder.getCallingUid()), any()); + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); |