diff options
5 files changed, 47 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java b/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java index 6cd5692ea..a7d9f0e3a 100644 --- a/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java @@ -19,10 +19,10 @@ package com.android.server.wifi; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; +import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.NetworkKey; import android.net.NetworkScoreManager; -import android.net.NetworkScorerAppData; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiNetworkScoreCache; @@ -48,6 +48,7 @@ public class ScoredNetworkEvaluator implements WifiNetworkSelector.NetworkEvalua private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private final NetworkScoreManager mNetworkScoreManager; + private final PackageManager mPackageManager; private final WifiConfigManager mWifiConfigManager; private final LocalLog mLocalLog; private final ContentObserver mContentObserver; @@ -57,12 +58,14 @@ public class ScoredNetworkEvaluator implements WifiNetworkSelector.NetworkEvalua ScoredNetworkEvaluator(final Context context, Handler handler, final FrameworkFacade frameworkFacade, NetworkScoreManager networkScoreManager, + PackageManager packageManager, WifiConfigManager wifiConfigManager, LocalLog localLog, WifiNetworkScoreCache wifiNetworkScoreCache, WifiPermissionsUtil wifiPermissionsUtil) { mScoreCache = wifiNetworkScoreCache; mWifiPermissionsUtil = wifiPermissionsUtil; mNetworkScoreManager = networkScoreManager; + mPackageManager = packageManager; mWifiConfigManager = wifiConfigManager; mLocalLog = localLog; mContentObserver = new ContentObserver(handler) { @@ -109,10 +112,15 @@ public class ScoredNetworkEvaluator implements WifiNetworkSelector.NetworkEvalua } private boolean activeScorerAllowedtoSeeScanResults() { - NetworkScorerAppData networkScorerAppData = mNetworkScoreManager.getActiveScorer(); String packageName = mNetworkScoreManager.getActiveScorerPackage(); - if (networkScorerAppData == null || packageName == null) return false; - int uid = networkScorerAppData.packageUid; + if (packageName == null) return false; + int uid = -1; + try { + uid = mPackageManager.getApplicationInfo(packageName, 0).uid; + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Failed to retrieve package uid", e); + return false; + } try { // TODO moltmann: Can we set a featureID here instead of null? mWifiPermissionsUtil.enforceCanAccessScanResults(packageName, null, uid, diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 78e893358..1adaec8f0 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -32,6 +32,7 @@ import android.net.wifi.WifiNetworkScoreCache; import android.net.wifi.WifiScanner; import android.os.BatteryStatsManager; import android.os.Handler; +import android.os.HandlerExecutor; import android.os.HandlerThread; import android.os.IBinder; import android.os.INetworkManagementService; @@ -175,6 +176,14 @@ public class WifiInjector { sWifiInjector = this; + // Now create and start handler threads + mAsyncChannelHandlerThread = new HandlerThread("AsyncChannelHandlerThread"); + mAsyncChannelHandlerThread.start(); + mWifiHandlerThread = new HandlerThread("WifiHandlerThread"); + mWifiHandlerThread.start(); + Looper wifiLooper = mWifiHandlerThread.getLooper(); + Handler wifiHandler = new Handler(wifiLooper); + mFrameworkFacade = new FrameworkFacade(); mMacAddressUtil = new MacAddressUtil(); mContext = context; @@ -185,20 +194,14 @@ public class WifiInjector { mWifiPermissionsWrapper = new WifiPermissionsWrapper(mContext); mNetworkScoreManager = mContext.getSystemService(NetworkScoreManager.class); mWifiNetworkScoreCache = new WifiNetworkScoreCache(mContext); - mNetworkScoreManager.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, - mWifiNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_NONE); + mNetworkScoreManager.registerNetworkScoreCallback(NetworkKey.TYPE_WIFI, + NetworkScoreManager.CACHE_FILTER_NONE, + new HandlerExecutor(wifiHandler), mWifiNetworkScoreCache); mUserManager = mContext.getSystemService(UserManager.class); mWifiPermissionsUtil = new WifiPermissionsUtil(mWifiPermissionsWrapper, mContext, mUserManager, this); mWifiBackupRestore = new WifiBackupRestore(mWifiPermissionsUtil); mWifiStateTracker = new WifiStateTracker(mBatteryStats); - // Now create and start handler threads - mAsyncChannelHandlerThread = new HandlerThread("AsyncChannelHandlerThread"); - mAsyncChannelHandlerThread.start(); - mWifiHandlerThread = new HandlerThread("WifiHandlerThread"); - mWifiHandlerThread.start(); - Looper wifiLooper = mWifiHandlerThread.getLooper(); - Handler wifiHandler = new Handler(wifiLooper); mWifiThreadRunner = new WifiThreadRunner(wifiHandler); mWifiP2pServiceHandlerThread = new HandlerThread("WifiP2pService"); mWifiP2pServiceHandlerThread.start(); @@ -297,7 +300,8 @@ public class WifiInjector { mNetworkSuggestionEvaluator = new NetworkSuggestionEvaluator(mWifiNetworkSuggestionsManager, mWifiConfigManager, mConnectivityLocalLog); mScoredNetworkEvaluator = new ScoredNetworkEvaluator(context, wifiHandler, - mFrameworkFacade, mNetworkScoreManager, mWifiConfigManager, mConnectivityLocalLog, + mFrameworkFacade, mNetworkScoreManager, context.getPackageManager(), + mWifiConfigManager, mConnectivityLocalLog, mWifiNetworkScoreCache, mWifiPermissionsUtil); mCarrierNetworkEvaluator = new CarrierNetworkEvaluator(mWifiConfigManager, mCarrierNetworkConfig, mConnectivityLocalLog, this); @@ -777,4 +781,8 @@ public class WifiInjector { public WifiChannelUtilization getWifiChannelUtilization() { return mWifiChannelUtilization; } + + public WifiNetworkScoreCache getWifiNetworkScoreCache() { + return mWifiNetworkScoreCache; + } } diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 6b2729788..29f3f139a 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -2693,6 +2693,11 @@ public class WifiServiceImpl extends BaseWifiService { SarManager sarManager = mWifiInjector.getSarManager(); sarManager.dump(fd, pw, args); pw.println(); + mWifiThreadRunner.run(() -> { + mWifiInjector.getWifiNetworkScoreCache().dumpWithLatestScanResults( + fd, pw, args, mScanRequestProxy.getScanResults()); + }); + pw.println(); } } diff --git a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java index bff45c99b..cae97dfd3 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java @@ -24,6 +24,8 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.NetworkKey; import android.net.NetworkScoreManager; @@ -72,6 +74,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest { @Mock private Clock mClock; @Mock private FrameworkFacade mFrameworkFacade; @Mock private NetworkScoreManager mNetworkScoreManager; + @Mock private PackageManager mPackageManager; @Mock private WifiConfigManager mWifiConfigManager; @Mock private WifiPermissionsUtil mWifiPermissionsUtil; @Mock private OnConnectableListener mOnConnectableListener; @@ -91,13 +94,18 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest { when(mFrameworkFacade.getIntegerSetting(mContext, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0)) .thenReturn(1); + ApplicationInfo appInfo = new ApplicationInfo(); + appInfo.uid = TEST_UID; + when(mPackageManager.getApplicationInfo(any(), anyInt())) + .thenReturn(appInfo); ArgumentCaptor<ContentObserver> observerCaptor = ArgumentCaptor.forClass(ContentObserver.class); mScoreCache = new WifiNetworkScoreCache(mContext); mScoredNetworkEvaluator = new ScoredNetworkEvaluator(mContext, new Handler(Looper.getMainLooper()), mFrameworkFacade, mNetworkScoreManager, - mWifiConfigManager, new LocalLog(0), mScoreCache, mWifiPermissionsUtil); + mPackageManager, mWifiConfigManager, new LocalLog(0), mScoreCache, + mWifiPermissionsUtil); verify(mFrameworkFacade).registerContentObserver(eq(mContext), any(Uri.class), eq(false), observerCaptor.capture()); mContentObserver = observerCaptor.getValue(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 2f5415ab9..fdabe35f9 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -110,6 +110,7 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.LocalOnlyHotspotCallback; import android.net.wifi.WifiManager.SoftApCallback; +import android.net.wifi.WifiNetworkScoreCache; import android.net.wifi.WifiNetworkSuggestion; import android.net.wifi.WifiSsid; import android.net.wifi.WifiStackClient; @@ -341,6 +342,8 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mClientModeImpl.getWifiScoreReport()).thenReturn(mWifiScoreReport); when(mWifiInjector.getWifiScoreCard()).thenReturn(mWifiScoreCard); when(mWifiInjector.getSarManager()).thenReturn(mSarManager); + when(mWifiInjector.getWifiNetworkScoreCache()) + .thenReturn(mock(WifiNetworkScoreCache.class)); when(mWifiInjector.getWifiThreadRunner()) .thenReturn(new WifiThreadRunner(new Handler(mLooper.getLooper()))); when(mClientModeImpl.syncStartSubscriptionProvisioning(anyInt(), |