diff options
author | Roshan Pius <rpius@google.com> | 2019-06-11 06:52:01 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-08-08 12:26:18 -0700 |
commit | fa4865828574f11464b5f0c06b27e2829b3672e6 (patch) | |
tree | 8560230553dc3d3821d2f20136ea39647dc8a685 | |
parent | dc597b0771b1366fa8fc4d6a94b50e385e20191a (diff) |
Create Mainline wifi stack module
a) Moved wifi service to a separate APK (WifiStack)
b) Converted all the .mk to .bp
c) Changed all the wifi services to inherit from a new WifiServiceBase
class (away from SystemService because we're no longer in system_server).
d) WifiStackService is the entry point into the APK entry. This will be
invoked from WifiStackClient running in system_server after
PHASE_SYSTEM_SERVICES_READY in android framework boot sequence.
e) Added a bunch of new .rc rules to help change ownership of all the
config store files.
f) Changed the |setPackage| on a bunch of private broadcasts triggered
for notification actions (from "android" to the new retrieved package
name).
g) Changed WifiScanner permission checks to use MAINLINE_WIFI_STACK
permission instead of NETWORK_STACK.
Bug: 113174748
Test: atest com.android.server.wifi
Test: Device boots up & connects to wifi networks, hotspot toggle, etc.
Test: Will send for regression tests
Change-Id: I87b83704c33694fcc99d2d9bde4e5cad9ddd06da
37 files changed, 947 insertions, 464 deletions
diff --git a/Android.bp b/Android.bp index 9735cc727..7c74fcb3e 100644 --- a/Android.bp +++ b/Android.bp @@ -15,5 +15,6 @@ subdirs = [ "libwifi_system", "libwifi_system_iface", - "service/proto", + "service", + "tests", ] diff --git a/service/Android.bp b/service/Android.bp index 091023e6f..f587c9c76 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -1,4 +1,5 @@ -// Copyright (C) 2011 The Android Open Source Project +// +// Copyright (C) 2018 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. @@ -11,11 +12,32 @@ // 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. +// +java_defaults { + name: "WifiStackCommon", + min_sdk_version: "29", + platform_apis: true, + privileged: true, + dex_preopt: { + enabled: false, + }, + errorprone: { + javacflags: ["-Xep:CheckReturnValue:ERROR"], + }, + product_variables: { + pdk: { + enabled: false, + }, + }, + resource_dirs: [ + "res", + ], +} // Make the JNI part // ============================================================ cc_library_shared { - name: "libwifi-service", + name: "libwifi-jni", cflags: [ "-Wall", @@ -48,3 +70,98 @@ cc_library_shared { }, }, } + +// Build the wifi-service static library +// ============================================================ +java_library { + name: "WifiStackBase", + installable: true, + defaults: ["WifiStackCommon"], + aidl: { + include_dirs: ["system/connectivity/wificond/aidl"], + local_include_dirs: ["java"], + }, + srcs: [ + ":libwificond_ipc_aidl", + "java/**/*.java", + "java/**/I*.aidl", + "java/**/*.logtags", + ], + + libs: [ + "error_prone_annotations", + "libprotobuf-java-lite", + "jsr305", + "services", + ], + + static_libs: [ + "android.hardware.wifi-V1.0-java", + "android.hardware.wifi-V1.1-java", + "android.hardware.wifi-V1.2-java", + "android.hardware.wifi-V1.3-java", + "android.hardware.wifi.hostapd-V1.0-java", + "android.hardware.wifi.hostapd-V1.1-java", + "android.hardware.wifi.supplicant-V1.0-java", + "android.hardware.wifi.supplicant-V1.1-java", + "android.hardware.wifi.supplicant-V1.2-java", + "android.hidl.manager-V1.2-java", + "androidx.annotation_annotation", + "wifi_service_proto", + "ksoap2", + "libnanohttpd", + "services.core", + "services.net", + "services.wifi" + ], + + required: [ + "libwifi-jni", + "services", + "cacerts_wfa", + ], +} + +java_defaults { + name: "WifiStackAppCommon", + defaults: ["WifiStackCommon"], + static_libs: [ + "WifiStackBase", + ], + jni_libs: [ + "libwifi-jni", + ], + // Resources already included in WifiStackBase + resource_dirs: [], + jarjar_rules: "jarjar-rules-shared.txt", + optimize: { + proguard_flags_files: ["proguard.flags"], + }, +} + +// Updatable stack packaged as an application +android_app { + name: "WifiStack", + defaults: ["WifiStackAppCommon"], + certificate: "networkstack", + manifest: "AndroidManifest.xml", + use_embedded_native_libs: true, + // The permission configuration *must* be included to ensure security of the device + required: ["WifiStackPermissionConfig"], + init_rc: ["wifi.rc"], +} + +// Non-updatable wifi stack running in the system server process for devices not using the module +// TODO (b/135753701): Test this path. +android_app { + name: "InProcessWifiStack", + defaults: ["WifiStackAppCommon"], + certificate: "platform", + manifest: "AndroidManifest_InProcess.xml", + // InProcessWifiStack is a replacement for WifiStack + overrides: ["WifiStack"], + // The permission configuration *must* be included to ensure security of the device + required: ["PlatformWifiStackPermissionConfig"], + init_rc: ["wifi_inprocess.rc"], +} + diff --git a/service/Android.mk b/service/Android.mk deleted file mode 100644 index b396214c7..000000000 --- a/service/Android.mk +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (C) 2011 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) - -ifneq ($(TARGET_BUILD_PDK), true) - -# Build the java code -# ============================================================ - -wificond_aidl_path := system/connectivity/wificond/aidl -wificond_aidl_rel_path := ../../../../../$(wificond_aidl_path) - -include $(CLEAR_VARS) - -LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/java $(wificond_aidl_path) -LOCAL_SRC_FILES := $(call all-java-files-under, java) \ - $(call all-Iaidl-files-under, java) \ - $(call all-Iaidl-files-under, $(wificond_aidl_rel_path)) \ - $(call all-logtags-files-under, java) - -LOCAL_JAVA_LIBRARIES := \ - android.hidl.manager-V1.2-java \ - error_prone_annotations \ - libprotobuf-java-lite \ - jsr305 \ - services -LOCAL_STATIC_JAVA_LIBRARIES := \ - android.hardware.wifi-V1.0-java \ - android.hardware.wifi-V1.1-java \ - android.hardware.wifi-V1.2-java \ - android.hardware.wifi-V1.3-java \ - android.hardware.wifi.hostapd-V1.0-java \ - android.hardware.wifi.hostapd-V1.1-java \ - android.hardware.wifi.supplicant-V1.0-java \ - android.hardware.wifi.supplicant-V1.1-java \ - android.hardware.wifi.supplicant-V1.2-java \ - wifi_service_proto \ - ksoap2 \ - libnanohttpd - -LOCAL_REQUIRED_MODULES := \ - services \ - libwifi-service \ - cacerts_wfa -LOCAL_MODULE_TAGS := -LOCAL_MODULE := wifi-service -LOCAL_INIT_RC := wifi-events.rc - -LOCAL_DEX_PREOPT_APP_IMAGE := false -LOCAL_DEX_PREOPT_GENERATE_PROFILE := true -LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := frameworks/base/services/art-profile -LOCAL_ERROR_PRONE_FLAGS := -Xep:CheckReturnValue:ERROR - -include $(BUILD_JAVA_LIBRARY) - -endif # !TARGET_BUILD_PDK diff --git a/service/AndroidManifest.xml b/service/AndroidManifest.xml new file mode 100644 index 000000000..4cd6585bf --- /dev/null +++ b/service/AndroidManifest.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * 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. + */ +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.server.wifistack" + coreApp="true" + android:sharedUserId="android.uid.networkstack" + android:versionCode="220000000" + android:versionName="30 system image"> + + <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29" /> + + <!-- Permissions must be defined here, and not in the base manifest, as the wifi stack + running in the system server process does not need any permission, and having privileged + permissions added would cause crashes on startup unless they are also added to the + privileged permissions whitelist for that package. --> + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> + <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" /> + <uses-permission android:name="android.permission.BROADCAST_STICKY" /> + <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> + <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> + <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> + <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" /> + <uses-permission android:name="android.permission.DEVICE_POWER" /> + <uses-permission android:name="android.permission.DUMP" /> + <uses-permission android:name="android.permission.GET_ACCOUNTS" /> + <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> + <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" /> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS" /> + <uses-permission android:name="android.permission.LOCATION_HARDWARE" /> + <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> + <uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" /> + <uses-permission android:name="android.permission.MANAGE_USERS" /> + <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" /> + <uses-permission android:name="android.permission.READ_PHONE_STATE" /> + <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" /> + <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + <uses-permission android:name="android.permission.REORDER_TASKS" /> + <uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" /> + <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> + <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" /> + <uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" /> + <uses-permission android:name="android.permission.WAKE_LOCK" /> + <uses-permission android:name="android.permission.WRITE_SETTINGS" /> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> + <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> + <!-- Signature permission defined for wifi module--> + <uses-permission android:name="android.permission.MAINLINE_WIFI_STACK" /> + + <!-- TODO(b/135691051): Need to move to network stack process. + "android:process="com.google.android.networkstack" + This is not possible currently because hidden API access is denied when run on network + stack process --> + <application + android:extractNativeLibs="false" + android:persistent="true" + android:directBootAware="true" + android:label="@string/wifiAppLabel"> + <service + android:name="com.android.server.wifi.WifiStackService" + android:directBootAware="true"> + <intent-filter> + <action android:name="android.net.wifi.IWifiStackConnector"/> + </intent-filter> + </service> + </application> +</manifest> diff --git a/service/AndroidManifestBase.xml b/service/AndroidManifestBase.xml new file mode 100644 index 000000000..0d05bf44d --- /dev/null +++ b/service/AndroidManifestBase.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * 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. + */ +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.server.wifistack" + android:versionCode="11" + android:versionName="R-initial"> + + <application + android:label="WifiStack" + android:defaultToDeviceProtectedStorage="true" + android:directBootAware="true" + android:usesCleartextTraffic="true"> + </application> +</manifest> diff --git a/service/AndroidManifest_InProcess.xml b/service/AndroidManifest_InProcess.xml new file mode 100644 index 000000000..785393c93 --- /dev/null +++ b/service/AndroidManifest_InProcess.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * 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. + */ +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.server.wifistack.inprocess" + android:sharedUserId="android.uid.system"> + <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29" /> + <application> + <service + android:name="com.android.server.wifi.WifiStackService" + android:directBootAware="true" + android:process="system"> + <intent-filter> + <action android:name="android.net.wifi.IWifiStackConnector.InProcess"/> + </intent-filter> + </service> + </application> +</manifest> diff --git a/service/CleanSpec.mk b/service/CleanSpec.mk deleted file mode 100644 index 70e8e55e1..000000000 --- a/service/CleanSpec.mk +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2011 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. -# - -# If you don't need to do a full clean build but would like to touch -# a file or delete some intermediate files, add a clean step to the end -# of the list. These steps will only be run once, if they haven't been -# run before. -# -# E.g.: -# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) -# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) -# -# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with -# files that are missing or have been moved. -# -# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. -# Use $(OUT_DIR) to refer to the "out" directory. -# -# If you need to re-do something that's already mentioned, just copy -# the command and add it to the bottom of the list. E.g., if a change -# that you made last week required touching a file and a change you -# made today requires touching the same file, just copy the old -# touch step and add it to the end of the list. -# -# ************************************************ -# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST -# ************************************************ - -$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/wifi-service_intermediates) - -# ************************************************ -# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST -# ************************************************ diff --git a/service/jarjar-rules-shared.txt b/service/jarjar-rules-shared.txt new file mode 100644 index 000000000..706449103 --- /dev/null +++ b/service/jarjar-rules-shared.txt @@ -0,0 +1 @@ +# TBD diff --git a/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java b/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java index f500c4e56..6800ebc60 100644 --- a/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java +++ b/service/java/com/android/server/wifi/ConnectToNetworkNotificationBuilder.java @@ -53,13 +53,16 @@ public class ConnectToNetworkNotificationBuilder { "com.android.server.wifi.ConnectToNetworkNotification.AVAILABLE_NETWORK_NOTIFIER_TAG"; private Context mContext; + private WifiInjector mWifiInjector; private Resources mResources; private FrameworkFacade mFrameworkFacade; public ConnectToNetworkNotificationBuilder( Context context, + WifiInjector wifiInjector, FrameworkFacade framework) { mContext = context; + mWifiInjector = wifiInjector; mResources = context.getResources(); mFrameworkFacade = framework; } @@ -175,7 +178,8 @@ public class ConnectToNetworkNotificationBuilder { } private PendingIntent getPrivateBroadcast(String action, String extraData) { - Intent intent = new Intent(action).setPackage("android"); + Intent intent = new Intent(action) + .setPackage(mWifiInjector.getWifiStackPackageName()); int requestCode = 0; // Makes the different kinds of notifications distinguishable if (extraData != null) { intent.putExtra(AVAILABLE_NETWORK_NOTIFIER_TAG, extraData); diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java index f3c5d4b3d..204d080f8 100644 --- a/service/java/com/android/server/wifi/FrameworkFacade.java +++ b/service/java/com/android/server/wifi/FrameworkFacade.java @@ -186,15 +186,6 @@ public class FrameworkFacade { } /** - * Check if the device will be restarting after decrypting during boot by calling {@link - * StorageManager.inCryptKeeperBounce}. - * @return true if the device will restart, false otherwise - */ - public boolean inStorageManagerCryptKeeperBounce() { - return StorageManager.inCryptKeeperBounce(); - } - - /** * Check if the provided uid is the app in the foreground. * @param uid the uid to check * @return true if the app is in the foreground, false otherwise diff --git a/service/java/com/android/server/wifi/WakeupNotificationFactory.java b/service/java/com/android/server/wifi/WakeupNotificationFactory.java index 23f31a7db..748a74d6c 100644 --- a/service/java/com/android/server/wifi/WakeupNotificationFactory.java +++ b/service/java/com/android/server/wifi/WakeupNotificationFactory.java @@ -42,10 +42,13 @@ public class WakeupNotificationFactory { public static final int ONBOARD_ID = SystemMessage.NOTE_WIFI_WAKE_ONBOARD; private final Context mContext; + private final WifiInjector mWifiInjector; private final FrameworkFacade mFrameworkFacade; - WakeupNotificationFactory(Context context, FrameworkFacade frameworkFacade) { + WakeupNotificationFactory(Context context, WifiInjector wifiInjector, + FrameworkFacade frameworkFacade) { mContext = context; + mWifiInjector = wifiInjector; mFrameworkFacade = frameworkFacade; } @@ -80,7 +83,8 @@ public class WakeupNotificationFactory { private PendingIntent getPrivateBroadcast(String action) { - Intent intent = new Intent(action).setPackage("android"); + Intent intent = new Intent(action) + .setPackage(mWifiInjector.getWifiStackPackageName()); return mFrameworkFacade.getBroadcast( mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index 7970ab72f..7aa5a6acc 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -85,23 +85,27 @@ public class WifiApConfigStore { private ArrayList<Integer> mAllowed2GChannel = null; private final Context mContext; + private final WifiInjector mWifiInjector; private final Handler mHandler; private final String mApConfigFile; private final BackupManagerProxy mBackupManagerProxy; private final FrameworkFacade mFrameworkFacade; private boolean mRequiresApBandConversion = false; - WifiApConfigStore(Context context, Looper looper, + WifiApConfigStore(Context context, WifiInjector wifiInjector, Looper looper, BackupManagerProxy backupManagerProxy, FrameworkFacade frameworkFacade) { - this(context, looper, backupManagerProxy, frameworkFacade, DEFAULT_AP_CONFIG_FILE); + this(context, wifiInjector, looper, backupManagerProxy, frameworkFacade, + DEFAULT_AP_CONFIG_FILE); } WifiApConfigStore(Context context, + WifiInjector wifiInjector, Looper looper, BackupManagerProxy backupManagerProxy, FrameworkFacade frameworkFacade, String apConfigFile) { mContext = context; + mWifiInjector = wifiInjector; mHandler = new Handler(looper); mBackupManagerProxy = backupManagerProxy; mFrameworkFacade = frameworkFacade; @@ -496,7 +500,8 @@ public class WifiApConfigStore { } private PendingIntent getPrivateBroadcast(String action) { - Intent intent = new Intent(action).setPackage("android"); + Intent intent = new Intent(action) + .setPackage(mWifiInjector.getWifiStackPackageName()); return mFrameworkFacade.getBroadcast( mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 3e01046dc..092d77694 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -154,6 +154,7 @@ public class WifiInjector { private IpMemoryStore mIpMemoryStore; private final CellularLinkLayerStatsCollector mCellularLinkLayerStatsCollector; + public WifiInjector(Context context) { if (context == null) { throw new IllegalStateException( @@ -232,7 +233,7 @@ public class WifiInjector { mContext.getResources() .getBoolean(R.bool.config_wifi_revert_country_code_on_cellular_loss)); mWifiApConfigStore = new WifiApConfigStore( - mContext, mWifiCoreHandlerThread.getLooper(), mBackupManagerProxy, + mContext, this, mWifiCoreHandlerThread.getLooper(), mBackupManagerProxy, mFrameworkFacade); // WifiConfigManager/Store objects and their dependencies. @@ -314,7 +315,7 @@ public class WifiInjector { mBatteryStats); WakeupNotificationFactory wakeupNotificationFactory = - new WakeupNotificationFactory(mContext, mFrameworkFacade); + new WakeupNotificationFactory(mContext, this, mFrameworkFacade); WakeupOnboarding wakeupOnboarding = new WakeupOnboarding(mContext, mWifiConfigManager, mWifiCoreHandlerThread.getLooper(), mFrameworkFacade, wakeupNotificationFactory); @@ -598,11 +599,11 @@ public class WifiInjector { mOpenNetworkNotifier = new OpenNetworkNotifier(mContext, mWifiCoreHandlerThread.getLooper(), mFrameworkFacade, mClock, mWifiMetrics, mWifiConfigManager, mWifiConfigStore, clientModeImpl, - new ConnectToNetworkNotificationBuilder(mContext, mFrameworkFacade)); + new ConnectToNetworkNotificationBuilder(mContext, this, mFrameworkFacade)); mCarrierNetworkNotifier = new CarrierNetworkNotifier(mContext, mWifiCoreHandlerThread.getLooper(), mFrameworkFacade, mClock, mWifiMetrics, mWifiConfigManager, mWifiConfigStore, clientModeImpl, - new ConnectToNetworkNotificationBuilder(mContext, mFrameworkFacade)); + new ConnectToNetworkNotificationBuilder(mContext, this, mFrameworkFacade)); mWifiLastResortWatchdog = new WifiLastResortWatchdog(this, mContext, mClock, mWifiMetrics, clientModeImpl, clientModeImpl.getHandler().getLooper(), mDeviceConfigFacade); @@ -751,4 +752,8 @@ public class WifiInjector { public HostapdHal getHostapdHal() { return mHostapdHal; } + + public String getWifiStackPackageName() { + return mContext.getPackageName(); + } } diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 3e5dc3c79..3078d0b05 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -3261,8 +3261,8 @@ public class WifiNative { ********************************************************/ /* Register native functions */ static { - /* Native functions are defined in libwifi-service.so */ - System.loadLibrary("wifi-service"); + /* Native functions are defined in libwifi-jni.so */ + System.loadLibrary("wifi-jni"); registerNatives(); } diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 35316f7c3..c05b2f832 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -757,7 +757,7 @@ public class WifiNetworkSuggestionsManager { private PendingIntent getPrivateBroadcast(@NonNull String action, @NonNull String packageName, int uid) { Intent intent = new Intent(action) - .setPackage("android") + .setPackage(mWifiInjector.getWifiStackPackageName()) .putExtra(EXTRA_PACKAGE_NAME, packageName) .putExtra(EXTRA_UID, uid); return mFrameworkFacade.getBroadcast(mContext, 0, intent, diff --git a/service/java/com/android/server/wifi/WifiService.java b/service/java/com/android/server/wifi/WifiService.java index b934ea108..46cd1116d 100644 --- a/service/java/com/android/server/wifi/WifiService.java +++ b/service/java/com/android/server/wifi/WifiService.java @@ -17,34 +17,33 @@ package com.android.server.wifi; import android.content.Context; +import android.os.ServiceManager; import android.util.Log; -import com.android.server.SystemService; import com.android.server.wifi.util.WifiAsyncChannel; -public final class WifiService extends SystemService { +/** + * Manages the wifi service instance. + */ +public final class WifiService implements WifiServiceBase { private static final String TAG = "WifiService"; final WifiServiceImpl mImpl; public WifiService(Context context) { - super(context); mImpl = new WifiServiceImpl(context, new WifiInjector(context), new WifiAsyncChannel(TAG)); } @Override public void onStart() { Log.i(TAG, "Registering " + Context.WIFI_SERVICE); - publishBinderService(Context.WIFI_SERVICE, mImpl); - } + ServiceManager.addService(Context.WIFI_SERVICE, mImpl); - @Override - public void onBootPhase(int phase) { - if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { - mImpl.checkAndStartWifi(); - } else if (phase == SystemService.PHASE_BOOT_COMPLETED) { - mImpl.handleBootCompleted(); - } + Log.i(TAG, "Starting " + Context.WIFI_SERVICE); + mImpl.checkAndStartWifi(); + + // Trigger all the necessary boot completed actions, since we are starting late now. + mImpl.handleBootCompleted(); } @Override diff --git a/service/java/com/android/server/wifi/WifiServiceBase.java b/service/java/com/android/server/wifi/WifiServiceBase.java new file mode 100644 index 000000000..0a443542a --- /dev/null +++ b/service/java/com/android/server/wifi/WifiServiceBase.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 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; + +/** + * Base class for all the wifi services. This is used to manage the lifetime of the services. + * Each service should override the methods corresponding to the lifetime events they care about. + * + * Note: Services can listen to these system broadcasts on their own, but they're explicitly listed + * here to better manage inter-service dependencies. (For ex: wifi aware service needs wifi service + * to initialize the HAL first). + */ +public interface WifiServiceBase { + /** + * Invoked when the APK service is bound. Should bed used to publish + * it's binder service & perform necessary initialization. This should happen very close to + * bootup phase {@link SystemService#PHASE_BOOT_COMPLETED} in system_server. + */ + default void onStart() {} + + /** + * Invoked when the user switches. + * + * @param userId Id for the new user. + */ + default void onSwitchUser(int userId) {} + + /** + * Invoked when the user unlocks. + * + * @param userId Id for the user. + */ + default void onUnlockUser(int userId) {} + + /** + * Invoked when the user stops. + * + * @param userId Id for the user. + */ + default void onStopUser(int userId) {} +} diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index e8c7d8301..f90655c04 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -75,6 +75,7 @@ import android.net.wifi.WifiManager.DeviceMobilityState; import android.net.wifi.WifiManager.LocalOnlyHotspotCallback; 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; @@ -509,12 +510,6 @@ public class WifiServiceImpl extends BaseWifiService { * This function is used only at boot time. */ public void checkAndStartWifi() { - // First check if we will end up restarting WifiService - if (mFrameworkFacade.inStorageManagerCryptKeeperBounce()) { - Log.d(TAG, "Device still encrypted. Need to restart SystemServer. Do not start wifi."); - return; - } - // Check if wi-fi needs to be enabled boolean wifiEnabled = mSettingsStore.isWifiToggleEnabled(); Slog.i(TAG, "WifiService starting up with Wi-Fi " + @@ -733,6 +728,11 @@ public class WifiServiceImpl extends BaseWifiService { == PackageManager.PERMISSION_GRANTED; } + private boolean checkMainlineWifiStackPermission(int pid, int uid) { + return mContext.checkPermission(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK, pid, uid) + == PackageManager.PERMISSION_GRANTED; + } + private boolean checkNetworkManagedProvisioningPermission(int pid, int uid) { return mContext.checkPermission(android.Manifest.permission.NETWORK_MANAGED_PROVISIONING, pid, uid) == PackageManager.PERMISSION_GRANTED; @@ -744,7 +744,8 @@ public class WifiServiceImpl extends BaseWifiService { return checkNetworkSettingsPermission(pid, uid) || checkNetworkSetupWizardPermission(pid, uid) || checkNetworkStackPermission(pid, uid) - || checkNetworkManagedProvisioningPermission(pid, uid); + || checkNetworkManagedProvisioningPermission(pid, uid) + || checkMainlineWifiStackPermission(pid, uid); } // Helper method to check if the entity initiating the binder call has setup wizard or settings diff --git a/service/java/com/android/server/wifi/WifiStackService.java b/service/java/com/android/server/wifi/WifiStackService.java new file mode 100644 index 000000000..28eef264e --- /dev/null +++ b/service/java/com/android/server/wifi/WifiStackService.java @@ -0,0 +1,205 @@ +/* + * 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. + */ + +package com.android.server.wifi; + +import static com.android.internal.notification.SystemNotificationChannels.NETWORK_ALERTS; +import static com.android.internal.notification.SystemNotificationChannels.NETWORK_AVAILABLE; +import static com.android.internal.notification.SystemNotificationChannels.NETWORK_STATUS; + +import android.annotation.NonNull; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.PackageManager; +import android.net.wifi.IWifiStackConnector; +import android.os.IBinder; +import android.os.UserHandle; +import android.os.storage.StorageManager; +import android.util.Log; + +import com.android.internal.R; +import com.android.server.wifi.aware.WifiAwareService; +import com.android.server.wifi.p2p.WifiP2pService; +import com.android.server.wifi.rtt.RttService; +import com.android.server.wifi.scanner.WifiScanningService; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; + +/** + * Android service used to start the wifi stack when bound to via an intent. + */ +public class WifiStackService extends Service { + private static final String TAG = WifiStackService.class.getSimpleName(); + // Ordered list of wifi services. The ordering determines the order in which the events + // are delivered to the services. + private final LinkedHashSet<WifiServiceBase> mServices = new LinkedHashSet<>(); + private static WifiStackConnector sConnector; + + private static class WifiStackConnector extends IWifiStackConnector.Stub { + private final Context mContext; + + WifiStackConnector(Context context) { + mContext = context; + } + } + + private class WifiBroadcastReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "Received " + intent + " broadcast"); + final String action = intent.getAction(); + if (action == null) { + Log.w(TAG, "Received null action for broadcast."); + return; + } + int userId; + switch (action) { + case Intent.ACTION_USER_SWITCHED: + userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); + for (WifiServiceBase service : mServices) { + service.onSwitchUser(userId); + } + break; + case Intent.ACTION_USER_STOPPED: + userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); + for (WifiServiceBase service : mServices) { + service.onStopUser(userId); + } + break; + case Intent.ACTION_USER_UNLOCKED: + userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); + for (WifiServiceBase service : mServices) { + service.onUnlockUser(userId); + } + break; + default: + Log.e(TAG, "Received unexpected action for broadcast."); + break; + } + } + } + + // Create notification channels used by wifi. + private void createNotificationChannels() { + final NotificationManager nm = getSystemService(NotificationManager.class); + List<NotificationChannel> channelsList = new ArrayList<>(); + final NotificationChannel networkStatusChannel = new NotificationChannel( + NETWORK_STATUS, + getString(R.string.notification_channel_network_status), + NotificationManager.IMPORTANCE_LOW); + channelsList.add(networkStatusChannel); + + final NotificationChannel networkAlertsChannel = new NotificationChannel( + NETWORK_ALERTS, + getString(R.string.notification_channel_network_alerts), + NotificationManager.IMPORTANCE_HIGH); + networkAlertsChannel.setBlockableSystem(true); + channelsList.add(networkAlertsChannel); + + final NotificationChannel networkAvailable = new NotificationChannel( + NETWORK_AVAILABLE, + getString(R.string.notification_channel_network_available), + NotificationManager.IMPORTANCE_LOW); + networkAvailable.setBlockableSystem(true); + channelsList.add(networkAvailable); + + nm.createNotificationChannels(channelsList); + } + + + private synchronized boolean initializeServices(Context context) { + if (UserHandle.myUserId() != 0) { + Log.w(TAG, "Wifi stack can only be bound from primary user"); + return false; + } + // Don't start wifi services if we're in crypt bounce state. + if (StorageManager.inCryptKeeperBounce()) { + Log.d(TAG, "Device still encrypted. Need to restart SystemServer." + + " Do not start wifi."); + return false; + } + // Top level wifi feature flag. + if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { + Log.w(TAG, "Wifi not supported on the device"); + return false; + } + + // Ordering of wifi services. + // wifi service + mServices.add(new WifiService(this)); + // wifiscanner service + mServices.add(new WifiScanningService(this)); + // wifi-p2p service + if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) { + mServices.add(new WifiP2pService(this)); + } + // wifi-aware service + if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_AWARE)) { + mServices.add(new WifiAwareService(this)); + } + // wifirtt service + if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)) { + mServices.add(new RttService(this)); + } + // Start all the services. + for (WifiServiceBase service : mServices) { + service.onStart(); + } + + // Register broadcast receiver for system events. + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_USER_SWITCHED); + intentFilter.addAction(Intent.ACTION_USER_STOPPED); + intentFilter.addAction(Intent.ACTION_USER_UNLOCKED); + registerReceiver(new WifiBroadcastReceiver(), intentFilter); + + // Create notification channels. + createNotificationChannels(); + + return true; + } + + /** + * Create a binder connector for the system server to communicate with the network stack. + * + * <p>On platforms where the network stack runs in the system server process, this method may + * be called directly instead of obtaining the connector by binding to the service. + */ + private synchronized IBinder makeConnectorAndInitializeServices(Context context) { + if (sConnector == null) { + if (!initializeServices(context)) { + Log.w(TAG, "Failed to initialize services"); + return null; + } + sConnector = new WifiStackConnector(context); + } + return sConnector; + } + + @NonNull + @Override + public IBinder onBind(Intent intent) { + Log.i(TAG, "WifiStack Service onBind"); + return makeConnectorAndInitializeServices(this); + } +} diff --git a/service/java/com/android/server/wifi/aware/WifiAwareService.java b/service/java/com/android/server/wifi/aware/WifiAwareService.java index f38c37316..a41f8a7d5 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareService.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareService.java @@ -18,63 +18,60 @@ package com.android.server.wifi.aware; import android.content.Context; import android.os.HandlerThread; +import android.os.ServiceManager; import android.util.Log; -import com.android.server.SystemService; import com.android.server.wifi.HalDeviceManager; import com.android.server.wifi.WifiInjector; +import com.android.server.wifi.WifiServiceBase; /** * Service implementing Wi-Fi Aware functionality. Delegates actual interface * implementation to WifiAwareServiceImpl. */ -public final class WifiAwareService extends SystemService { +public final class WifiAwareService implements WifiServiceBase { private static final String TAG = "WifiAwareService"; final WifiAwareServiceImpl mImpl; public WifiAwareService(Context context) { - super(context); mImpl = new WifiAwareServiceImpl(context); } @Override public void onStart() { Log.i(TAG, "Registering " + Context.WIFI_AWARE_SERVICE); - publishBinderService(Context.WIFI_AWARE_SERVICE, mImpl); - } + ServiceManager.addService(Context.WIFI_AWARE_SERVICE, mImpl); - @Override - public void onBootPhase(int phase) { - if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { - WifiInjector wifiInjector = WifiInjector.getInstance(); - if (wifiInjector == null) { - Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!"); - return; - } + Log.i(TAG, "Starting " + Context.WIFI_AWARE_SERVICE); + WifiInjector wifiInjector = WifiInjector.getInstance(); + if (wifiInjector == null) { + Log.e(TAG, "NULL injector!"); + return; + } - HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager(); + HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager(); - WifiAwareStateManager wifiAwareStateManager = new WifiAwareStateManager(); - WifiAwareNativeCallback wifiAwareNativeCallback = new WifiAwareNativeCallback( - wifiAwareStateManager); - WifiAwareNativeManager wifiAwareNativeManager = new WifiAwareNativeManager( - wifiAwareStateManager, halDeviceManager, wifiAwareNativeCallback); - WifiAwareNativeApi wifiAwareNativeApi = new WifiAwareNativeApi(wifiAwareNativeManager); - wifiAwareStateManager.setNative(wifiAwareNativeManager, wifiAwareNativeApi); - WifiAwareShellCommand wifiAwareShellCommand = new WifiAwareShellCommand(); - wifiAwareShellCommand.register("native_api", wifiAwareNativeApi); - wifiAwareShellCommand.register("native_cb", wifiAwareNativeCallback); - wifiAwareShellCommand.register("state_mgr", wifiAwareStateManager); + WifiAwareStateManager wifiAwareStateManager = new WifiAwareStateManager(); + WifiAwareNativeCallback wifiAwareNativeCallback = new WifiAwareNativeCallback( + wifiAwareStateManager); + WifiAwareNativeManager wifiAwareNativeManager = new WifiAwareNativeManager( + wifiAwareStateManager, halDeviceManager, wifiAwareNativeCallback); + WifiAwareNativeApi wifiAwareNativeApi = new WifiAwareNativeApi(wifiAwareNativeManager); + wifiAwareStateManager.setNative(wifiAwareNativeManager, wifiAwareNativeApi); + WifiAwareShellCommand wifiAwareShellCommand = new WifiAwareShellCommand(); + wifiAwareShellCommand.register("native_api", wifiAwareNativeApi); + wifiAwareShellCommand.register("native_cb", wifiAwareNativeCallback); + wifiAwareShellCommand.register("state_mgr", wifiAwareStateManager); - HandlerThread awareHandlerThread = wifiInjector.getWifiAwareHandlerThread(); - mImpl.start(awareHandlerThread, wifiAwareStateManager, wifiAwareShellCommand, - wifiInjector.getWifiMetrics().getWifiAwareMetrics(), - wifiInjector.getWifiPermissionsUtil(), - wifiInjector.getWifiPermissionsWrapper(), wifiInjector.getFrameworkFacade(), - wifiAwareNativeManager, wifiAwareNativeApi, wifiAwareNativeCallback); - } else if (phase == SystemService.PHASE_BOOT_COMPLETED) { - mImpl.startLate(); - } + HandlerThread awareHandlerThread = wifiInjector.getWifiAwareHandlerThread(); + mImpl.start(awareHandlerThread, wifiAwareStateManager, wifiAwareShellCommand, + wifiInjector.getWifiMetrics().getWifiAwareMetrics(), + wifiInjector.getWifiPermissionsUtil(), + wifiInjector.getWifiPermissionsWrapper(), wifiInjector.getFrameworkFacade(), + wifiAwareNativeManager, wifiAwareNativeApi, wifiAwareNativeCallback); + + // TODO: This 2 step initialization is no longer necessary because of service ordering in + // WifiStackService. + mImpl.startLate(); } } - diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pService.java b/service/java/com/android/server/wifi/p2p/WifiP2pService.java index 6137c3cd9..877c1570d 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pService.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pService.java @@ -17,36 +17,32 @@ package com.android.server.wifi.p2p; import android.content.Context; +import android.os.ServiceManager; import android.util.Log; -import com.android.server.SystemService; import com.android.server.wifi.WifiInjector; +import com.android.server.wifi.WifiServiceBase; /** * Wifi P2p Service class, instantiates P2p service - * Overrides onStart() and onBootPhase() methods in + * Overrides onStart() and onBootCompleted() methods in * the super class. */ -public final class WifiP2pService extends SystemService { +public final class WifiP2pService implements WifiServiceBase { private static final String TAG = "WifiP2pService"; final WifiP2pServiceImpl mImpl; public WifiP2pService(Context context) { - super(context); mImpl = new WifiP2pServiceImpl(context, WifiInjector.getInstance()); } @Override public void onStart() { Log.i(TAG, "Registering " + Context.WIFI_P2P_SERVICE); - publishBinderService(Context.WIFI_P2P_SERVICE, mImpl); - } + ServiceManager.addService(Context.WIFI_P2P_SERVICE, mImpl); - @Override - public void onBootPhase(int phase) { - if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { - mImpl.connectivityServiceReady(); - } + Log.i(TAG, "Starting " + Context.WIFI_P2P_SERVICE); + mImpl.connectivityServiceReady(); } } diff --git a/service/java/com/android/server/wifi/rtt/RttService.java b/service/java/com/android/server/wifi/rtt/RttService.java index 74370516e..e5e13453b 100644 --- a/service/java/com/android/server/wifi/rtt/RttService.java +++ b/service/java/com/android/server/wifi/rtt/RttService.java @@ -22,21 +22,20 @@ import android.os.HandlerThread; import android.os.ServiceManager; import android.util.Log; -import com.android.server.SystemService; import com.android.server.wifi.HalDeviceManager; import com.android.server.wifi.WifiInjector; +import com.android.server.wifi.WifiServiceBase; import com.android.server.wifi.util.WifiPermissionsUtil; /** * TBD. */ -public class RttService extends SystemService { +public class RttService implements WifiServiceBase { private static final String TAG = "RttService"; private Context mContext; private RttServiceImpl mImpl; public RttService(Context context) { - super(context); mContext = context; mImpl = new RttServiceImpl(context); } @@ -44,31 +43,25 @@ public class RttService extends SystemService { @Override public void onStart() { Log.i(TAG, "Registering " + Context.WIFI_RTT_RANGING_SERVICE); - publishBinderService(Context.WIFI_RTT_RANGING_SERVICE, mImpl); - } - - @Override - public void onBootPhase(int phase) { - if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { - Log.i(TAG, "Starting " + Context.WIFI_RTT_RANGING_SERVICE); + ServiceManager.addService(Context.WIFI_RTT_RANGING_SERVICE, mImpl); - WifiInjector wifiInjector = WifiInjector.getInstance(); - if (wifiInjector == null) { - Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!"); - return; - } + Log.i(TAG, "Starting " + Context.WIFI_RTT_RANGING_SERVICE); + WifiInjector wifiInjector = WifiInjector.getInstance(); + if (wifiInjector == null) { + Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!"); + return; + } - HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager(); - HandlerThread handlerThread = wifiInjector.getRttHandlerThread(); - WifiPermissionsUtil wifiPermissionsUtil = wifiInjector.getWifiPermissionsUtil(); - RttMetrics rttMetrics = wifiInjector.getWifiMetrics().getRttMetrics(); + HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager(); + HandlerThread handlerThread = wifiInjector.getRttHandlerThread(); + WifiPermissionsUtil wifiPermissionsUtil = wifiInjector.getWifiPermissionsUtil(); + RttMetrics rttMetrics = wifiInjector.getWifiMetrics().getRttMetrics(); - IWifiAwareManager awareBinder = (IWifiAwareManager) ServiceManager.getService( - Context.WIFI_AWARE_SERVICE); + IWifiAwareManager awareBinder = (IWifiAwareManager) ServiceManager.getService( + Context.WIFI_AWARE_SERVICE); - RttNative rttNative = new RttNative(mImpl, halDeviceManager); - mImpl.start(handlerThread.getLooper(), wifiInjector.getClock(), awareBinder, rttNative, - rttMetrics, wifiPermissionsUtil, wifiInjector.getFrameworkFacade()); - } + RttNative rttNative = new RttNative(mImpl, halDeviceManager); + mImpl.start(handlerThread.getLooper(), wifiInjector.getClock(), awareBinder, rttNative, + rttMetrics, wifiPermissionsUtil, wifiInjector.getFrameworkFacade()); } } diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningService.java b/service/java/com/android/server/wifi/scanner/WifiScanningService.java index 93ac72252..f0616eb8a 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningService.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningService.java @@ -18,24 +18,27 @@ package com.android.server.wifi.scanner; import android.content.Context; import android.os.HandlerThread; +import android.os.ServiceManager; import android.util.Log; -import com.android.server.SystemService; import com.android.server.am.BatteryStatsService; import com.android.server.wifi.WifiInjector; +import com.android.server.wifi.WifiServiceBase; -public class WifiScanningService extends SystemService { +/** + * Manages the wifi scanner service instance. + */ +public class WifiScanningService implements WifiServiceBase { static final String TAG = "WifiScanningService"; private final WifiScanningServiceImpl mImpl; private final HandlerThread mHandlerThread; public WifiScanningService(Context context) { - super(context); Log.i(TAG, "Creating " + Context.WIFI_SCANNING_SERVICE); mHandlerThread = new HandlerThread("WifiScanningService"); mHandlerThread.start(); - mImpl = new WifiScanningServiceImpl(getContext(), mHandlerThread.getLooper(), + mImpl = new WifiScanningServiceImpl(context, mHandlerThread.getLooper(), WifiScannerImpl.DEFAULT_FACTORY, BatteryStatsService.getService(), WifiInjector.getInstance()); } @@ -43,14 +46,9 @@ public class WifiScanningService extends SystemService { @Override public void onStart() { Log.i(TAG, "Publishing " + Context.WIFI_SCANNING_SERVICE); - publishBinderService(Context.WIFI_SCANNING_SERVICE, mImpl); - } + ServiceManager.addService(Context.WIFI_SCANNING_SERVICE, mImpl); - @Override - public void onBootPhase(int phase) { - if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { - Log.i(TAG, "Starting " + Context.WIFI_SCANNING_SERVICE); - mImpl.startService(); - } + Log.i(TAG, "Starting " + Context.WIFI_SCANNING_SERVICE); + mImpl.startService(); } } diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index 442faa13e..534242b02 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -29,6 +29,7 @@ import android.net.wifi.WifiScanner.ChannelSpec; import android.net.wifi.WifiScanner.PnoSettings; import android.net.wifi.WifiScanner.ScanData; import android.net.wifi.WifiScanner.ScanSettings; +import android.net.wifi.WifiStackClient; import android.os.Binder; import android.os.Bundle; import android.os.Looper; @@ -121,11 +122,11 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { return b; } - private void enforceNetworkStack(int uid) { + private void enforceWifiStack(int uid) { mContext.enforcePermission( - Manifest.permission.NETWORK_STACK, + WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK, UNKNOWN_PID, uid, - "NetworkStack"); + "MainlineWifiStack"); } // Helper method to check if the incoming message is for a privileged request. @@ -179,7 +180,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { private void enforcePermission(int uid, Message msg) throws SecurityException { try { /** Wifi stack issued requests.*/ - enforceNetworkStack(uid); + enforceWifiStack(uid); } catch (SecurityException e) { /** System-app issued requests. */ if (isPrivilegedMessage(msg.what)) { @@ -804,9 +805,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { Log.e(TAG, "Invalid scan type " + settings.type); return false; } - if (mContext.checkPermission( - Manifest.permission.NETWORK_STACK, UNKNOWN_PID, ci.getUid()) - == PERMISSION_DENIED) { + if (!mWifiPermissionsUtil.checkMainlineWifiStackPermission(ci.getUid())) { if (!ArrayUtils.isEmpty(settings.hiddenNetworks)) { Log.e(TAG, "Failing single scan because app " + ci.getUid() + " does not have permission to set hidden networks"); diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java index 2834ad765..24fc2708f 100644 --- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java +++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java @@ -23,6 +23,7 @@ import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.location.LocationManager; import android.net.NetworkStack; +import android.net.wifi.WifiStackClient; import android.os.Binder; import android.os.Build; import android.os.RemoteException; @@ -486,6 +487,15 @@ public class WifiPermissionsUtil { } /** + * Returns true if the |uid| holds MAINLINE_WIFI_STACK permission. + */ + public boolean checkMainlineWifiStackPermission(int uid) { + return mWifiPermissionsWrapper.getUidPermission( + WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK, uid) + == PackageManager.PERMISSION_GRANTED; + } + + /** * Returns true if the |uid| holds NETWORK_MANAGED_PROVISIONING permission. */ public boolean checkNetworkManagedProvisioningPermission(int uid) { diff --git a/service/proguard.flags b/service/proguard.flags new file mode 100644 index 000000000..706449103 --- /dev/null +++ b/service/proguard.flags @@ -0,0 +1 @@ +# TBD diff --git a/service/res/values/strings.xml b/service/res/values/strings.xml new file mode 100644 index 000000000..83d6e5412 --- /dev/null +++ b/service/res/values/strings.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <!-- Official label of the wifi stack --> + <string name="wifiAppLabel" product="default">System Wi-Fi</string> +</resources> diff --git a/service/wifi.rc b/service/wifi.rc new file mode 100644 index 000000000..e32ec20ed --- /dev/null +++ b/service/wifi.rc @@ -0,0 +1,89 @@ +# +# Copyright (C) 2016 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. +# + +# These are needed for migration of data from "system" user to "network_stack" user +# since wifi is no longer running in "system_server". +on post-fs-data + chown network_stack network_stack /data/misc/wifi + chown network_stack network_stack /data/misc/wifi/WifiConfigStore.xml + chown network_stack network_stack /data/misc/wifi/WifiConfigStore.xml.encrypted-checksum + chown network_stack network_stack /data/misc/wifi/softap.conf + +on property:sys.user.0.ce_available=true + mkdir /data/misc_ce/0/wifi 0770 network_stack network_stack + # For devices upgrading, we need to change permission. + chown network_stack network_stack /data/misc_ce/0/wifi + chown network_stack network_stack /data/misc_ce/0/wifi/WifiConfigStore.xml + chown network_stack network_stack /data/misc_ce/0/wifi/WifiConfigStore.xml.encrypted-checksum + chown network_stack network_stack /data/misc_ce/0/wifi/WifiConfigStoreNetworkSuggestions.xml + chown network_stack network_stack /data/misc_ce/0/wifi/WifiConfigStoreNetworkSuggestions.xml.encrypted-checksum + + # Load the new sepolicy file context labels (these files were relabeled in R). + restorecon /data/misc_ce/0/wifi + restorecon /data/misc_ce/0/wifi/WifiConfigStore.xml + restorecon /data/misc_ce/0/wifi/WifiConfigStore.xml.encrypted-checksum + restorecon /data/misc_ce/0/wifi/WifiConfigStoreNetworkSuggestions.xml + restorecon /data/misc_ce/0/wifi/WifiConfigStoreNetworkSuggestions.xml.encrypted-checksum + +# Below are for kernel tracing related stuff. +on fs + setprop sys.wifitracing.started 0 + +on property:sys.boot_completed=1 && property:sys.wifitracing.started=0 + # Create trace buffer, and set basic configuration. + mkdir /sys/kernel/debug/tracing/instances/wifi 711 + restorecon_recursive /sys/kernel/debug/tracing/instances/wifi + write /sys/kernel/debug/tracing/instances/wifi/tracing_on 0 + write /sys/kernel/debug/tracing/instances/wifi/buffer_size_kb 1 + write /sys/kernel/debug/tracing/instances/wifi/trace_options disable_on_free + + # Enable cfg80211 events for connection and key management events. + # - Events are not actually logged until WifiService writes "1" to + # /sys/kernel/debug/tracing/instances/wifi/tracing_on. + # - WifiService is responsible for turning tracing off and on. + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/cfg80211_gtk_rekey_notify/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_add_key/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_assoc/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_auth/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_connect/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_set_default_key/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_set_default_mgmt_key/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/cfg80211/rdev_set_rekey_data/enable 1 + + # Enable datapath events for Wifi. + # - Events are not actually logged until WifiService writes "1" to + # /sys/kernel/debug/tracing/instances/wifi/tracing_on. + # - WifiService will ensure that tracing is turned back off, + # when a connection attempt ends (whether in success or failure) + write /sys/kernel/debug/tracing/instances/wifi/events/net/filter name==${wifi.interface:-wlan0} + write /sys/kernel/debug/tracing/instances/wifi/events/net/net_dev_queue/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/net/net_dev_xmit/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/net/netif_rx/enable 1 + write /sys/kernel/debug/tracing/instances/wifi/events/net/netif_receive_skb/enable 1 + + # Set DAC to allow network_stack to enable/disable, and read wifi trace + # events. + chown network_stack network_stack /sys/kernel/debug/tracing/instances/wifi/tracing_on + chown network_stack network_stack /sys/kernel/debug/tracing/instances/wifi/free_buffer + chown network_stack network_stack /sys/kernel/debug/tracing/instances/wifi/trace + chmod 200 /sys/kernel/debug/tracing/instances/wifi/tracing_on + chmod 400 /sys/kernel/debug/tracing/instances/wifi/free_buffer + chmod 600 /sys/kernel/debug/tracing/instances/wifi/trace + setprop sys.wifitracing.started 1 + +on property:sys.boot_completed=1 && property:wifi.interface=* && sys.wifitracing.started=1 + # Override default value. + write /sys/kernel/debug/tracing/instances/wifi/events/net/filter name==${wifi.interface} diff --git a/service/wifi-events.rc b/service/wifi_inprocess.rc index b4b093441..b849b74ee 100644 --- a/service/wifi-events.rc +++ b/service/wifi_inprocess.rc @@ -14,6 +14,7 @@ # limitations under the License. # +# Below are for kernel tracing related stuff. on fs setprop sys.wifitracing.started 0 @@ -49,7 +50,7 @@ on property:sys.boot_completed=1 && property:sys.wifitracing.started=0 write /sys/kernel/debug/tracing/instances/wifi/events/net/netif_rx/enable 1 write /sys/kernel/debug/tracing/instances/wifi/events/net/netif_receive_skb/enable 1 - # Set DAC to allow system_server to enable/disable, and read wifi trace + # Set DAC to allow system to enable/disable, and read wifi trace # events. chown system /sys/kernel/debug/tracing/instances/wifi/tracing_on chown system /sys/kernel/debug/tracing/instances/wifi/free_buffer 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 24d8de54b..6b80d6aaf 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 = @@ -1014,7 +1017,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); @@ -1040,7 +1042,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(); @@ -1077,22 +1078,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(); @@ -1103,8 +1092,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); @@ -2048,7 +2036,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksTriggeredOnSoftApFailureGeneric() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2073,7 +2060,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksTriggeredOnSoftApFailureNoChannel() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2100,8 +2086,6 @@ public class WifiServiceImplTest { @Test public void testRegisteredCallbacksTriggeredOnSoftApDisabling() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2135,8 +2119,6 @@ public class WifiServiceImplTest { @Test public void testRegisteredCallbacksTriggeredOnSoftApDisabled() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2168,7 +2150,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksNotTriggeredOnSoftApStart() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2193,8 +2174,6 @@ public class WifiServiceImplTest { @Test public void testRegisteredCallbacksTriggeredOnlyOnceWhenSoftApDisabling() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2229,7 +2208,6 @@ public class WifiServiceImplTest { */ @Test public void testRegisteredCallbacksTriggeredOnlyOnceWhenSoftApFailsTwice() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2258,7 +2236,6 @@ public class WifiServiceImplTest { */ @Test public void testAllRegisteredCallbacksTriggeredWhenSoftApFails() throws Exception { - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2293,8 +2270,6 @@ public class WifiServiceImplTest { @Test public void testAllRegisteredCallbacksTriggeredWhenSoftApStops() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2335,8 +2310,6 @@ public class WifiServiceImplTest { @Test public void testAllRegisteredCallbacksTriggeredWhenSoftApStopsLOHSNotActive() throws Exception { setupClientModeImplHandlerForPost(); - - when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -2517,8 +2490,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(), @@ -3108,7 +3079,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..cf56e5b67 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -58,6 +58,7 @@ 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,7 @@ public class WifiScanningServiceTest { when(mFrameworkFacade.makeWifiAsyncChannel(anyString())).thenReturn(mWifiAsyncChannel); when(mWifiInjector.getFrameworkFacade()).thenReturn(mFrameworkFacade); when(mWifiInjector.getClock()).thenReturn(mClock); + when(mWifiPermissionsUtil.checkMainlineWifiStackPermission(anyInt())).thenReturn(true); mWifiScanningServiceImpl = new WifiScanningServiceImpl(mContext, mLooper.getLooper(), mWifiScannerImplFactory, mBatteryStats, mWifiInjector); } @@ -700,9 +702,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())) - .thenReturn(PERMISSION_DENIED); + when(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); startServiceAndLoadDriver(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); @@ -752,9 +753,8 @@ public class WifiScanningServiceTest { }; WorkSource workSource = new WorkSource(Binder.getCallingUid()); // don't explicitly set - when(mContext.checkPermission( - Manifest.permission.NETWORK_STACK, -1, Binder.getCallingUid())) - .thenReturn(PERMISSION_DENIED); + when(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); startServiceAndLoadDriver(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); @@ -839,9 +839,8 @@ public class WifiScanningServiceTest { @Test public void sendSingleScanRequestWithNoPrivilegedParamsSetFromNonPrivilegedApp() throws Exception { - when(mContext.checkPermission( - Manifest.permission.NETWORK_STACK, -1, Binder.getCallingUid())) - .thenReturn(PERMISSION_DENIED); + when(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); WifiScanner.ScanSettings requestSettings = createRequest(channelsToSpec(2400, 5150, 5175), 0, 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); doSuccessfulSingleScan(requestSettings, computeSingleScanNativeSettings(requestSettings), @@ -2484,7 +2483,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 +2493,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 +2534,19 @@ 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(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); + // Location permission or mode check fail. doThrow(new SecurityException()).when(mWifiPermissionsUtil) .enforceCanAccessScanResultsForWifiScanner(any(), eq(Binder.getCallingUid()), @@ -2549,9 +2555,9 @@ 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(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); controlChannel.sendMessage(Message.obtain(null, WifiScanner.CMD_START_SINGLE_SCAN)); mLooper.dispatchAll(); @@ -2593,9 +2599,12 @@ 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(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); @@ -2653,9 +2662,12 @@ 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(mWifiPermissionsUtil.checkMainlineWifiStackPermission(Binder.getCallingUid())) + .thenReturn(false); Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); @@ -2715,9 +2727,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); |