From 3871ff67f4a6970f1831fc8951392746c9e2bfa2 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Wed, 12 Apr 2017 22:39:16 -0700 Subject: WifiServiceImpl: setWifiApEnabled unit tests Add unit tests to cover setWifiApEnabled. This did require a small change to check a tethering permission and add the user manager. Bug: 37294233 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I7bdfdcbdfa60605bc2e61f18aa8abeb4bcaf5c56 Merged-In: I77413789b1b2a19c9330f4c9b9978c4a0f5b5bf8 Merged-In: I33ae84d7282dea967a53a644018e20eb2902eca3 --- service/java/com/android/server/wifi/WifiInjector.java | 4 ++++ service/java/com/android/server/wifi/WifiServiceImpl.java | 5 ++--- .../java/com/android/server/wifi/util/WifiPermissionsUtil.java | 10 ++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index af470eee8..3d444a448 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -237,6 +237,10 @@ public class WifiInjector { return sWifiInjector; } + public UserManager getUserManager() { + return UserManager.get(mContext); + } + public WifiMetrics getWifiMetrics() { return mWifiMetrics; } diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index c6166cdb2..f83923979 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -39,7 +39,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; import android.database.ContentObserver; -import android.net.ConnectivityManager; import android.net.DhcpInfo; import android.net.DhcpResults; import android.net.IpConfiguration; @@ -332,7 +331,7 @@ public class WifiServiceImpl extends IWifiManager.Stub { mFacade = mWifiInjector.getFrameworkFacade(); mWifiMetrics = mWifiInjector.getWifiMetrics(); mTrafficPoller = mWifiInjector.getWifiTrafficPoller(); - mUserManager = UserManager.get(mContext); + mUserManager = mWifiInjector.getUserManager(); mCountryCode = mWifiInjector.getWifiCountryCode(); mWifiStateMachine = mWifiInjector.getWifiStateMachine(); mWifiStateMachine.enableRssiPolling(true); @@ -670,7 +669,7 @@ public class WifiServiceImpl extends IWifiManager.Stub { @Override public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { enforceChangePermission(); - ConnectivityManager.enforceTetherChangePermission(mContext); + mWifiPermissionsUtil.enforceTetherChangePermission(mContext); mLog.trace("setWifiApEnabled uid=% enable=%").c(Binder.getCallingUid()).c(enabled).flush(); diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java index 2010dcfa7..6de39ac3d 100644 --- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java +++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java @@ -21,6 +21,7 @@ import android.app.AppOpsManager; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.UserInfo; +import android.net.ConnectivityManager; import android.net.NetworkScoreManager; import android.os.RemoteException; import android.os.UserManager; @@ -74,6 +75,15 @@ public class WifiPermissionsUtil { } } + /** + * Check and enforce tether change permission. + * + * @param context Context object of the caller. + */ + public void enforceTetherChangePermission(Context context) { + ConnectivityManager.enforceTetherChangePermission(context); + } + /** * API to determine if the caller has permissions to get * scan results. -- cgit v1.2.3