summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/ScoredNetworkEvaluator.java16
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java28
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java5
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java10
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java3
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 5aca1d26c..b8f8b47eb 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;
@@ -173,6 +174,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;
@@ -183,20 +192,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();
@@ -295,7 +298,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);
@@ -773,4 +777,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 d42735458..6245a3cf9 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2678,6 +2678,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 ddb49f0b1..a916a2bd6 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -111,6 +111,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;
@@ -342,6 +343,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(),