summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorAmin Shaikh <ashaikh@google.com>2017-01-06 16:28:45 -0800
committerAmin Shaikh <ashaikh@google.com>2017-01-09 17:09:06 -0800
commitdfc4219e2d230cdce654c26aed3680fece04ddb5 (patch)
treef71b65e4d54669b2bd1ab6d5c583be12a2414f98 /service
parent83418537b8188242e94c11e33298a51ea2606edd (diff)
Observe settings in RecommendedNetworkEvaluator.
If NETWORK_RECOMMENDATIONS_ENABLED is set, use RecommendedNetworkEvaluator, otherwise use ExternalScoreEvaluator. Previously, this setting was only respected at boot time, however, users can toggle this setting at runtime. This change forwards method calls on RecommendedNetworkEvaluator to ExternalScoreEvaluator when this setting is disabled. ExternalScoreEvaluator will be removed in a later change. Test: runtests.sh Bug: 33694202 Change-Id: I67e73d4e2c4cdff465d23056b59554fc9d8ab64a
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java45
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java12
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java11
3 files changed, 50 insertions, 18 deletions
diff --git a/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java b/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java
index 2d481ec45..88e17b991 100644
--- a/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java
@@ -16,6 +16,9 @@
package com.android.server.wifi;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
import android.net.NetworkKey;
import android.net.NetworkScoreManager;
import android.net.RecommendationRequest;
@@ -25,11 +28,15 @@ import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiNetworkScoreCache;
+import android.os.Handler;
+import android.os.Looper;
import android.os.Process;
+import android.provider.Settings;
import android.util.LocalLog;
import android.util.Pair;
import android.util.Slog;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.util.ScanResultUtil;
import java.util.ArrayList;
@@ -45,19 +52,42 @@ public class RecommendedNetworkEvaluator implements WifiNetworkSelector.NetworkE
private final WifiNetworkScoreCache mNetworkScoreCache;
private final WifiConfigManager mWifiConfigManager;
private final LocalLog mLocalLog;
+ private final ExternalScoreEvaluator mExternalScoreEvaluator;
+ @VisibleForTesting final ContentObserver mContentObserver;
+ private boolean mNetworkRecommendationsEnabled;
- RecommendedNetworkEvaluator(WifiNetworkScoreCache networkScoreCache,
+ RecommendedNetworkEvaluator(final Context context, ContentResolver contentResolver,
+ Looper looper, final FrameworkFacade frameworkFacade,
+ WifiNetworkScoreCache networkScoreCache,
NetworkScoreManager networkScoreManager, WifiConfigManager wifiConfigManager,
- LocalLog localLog) {
+ LocalLog localLog, ExternalScoreEvaluator externalScoreEvaluator) {
mNetworkScoreCache = networkScoreCache;
mNetworkScoreManager = networkScoreManager;
mWifiConfigManager = wifiConfigManager;
mLocalLog = localLog;
+ mExternalScoreEvaluator = externalScoreEvaluator; // TODO(b/33694202): Remove
+ mContentObserver = new ContentObserver(new Handler(looper)) {
+ @Override
+ public void onChange(boolean selfChange) {
+ mNetworkRecommendationsEnabled = frameworkFacade.getIntegerSetting(context,
+ Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
+ }
+ };
+ contentResolver.registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED),
+ false /* notifyForDescendents */, mContentObserver);
+ mContentObserver.onChange(false /* unused */);
+ mLocalLog.log("RecommendedNetworkEvaluator constructed. mNetworkRecommendationsEnabled: "
+ + mNetworkRecommendationsEnabled);
}
@Override
public void update(List<ScanDetail> scanDetails) {
- updateNetworkScoreCache(scanDetails);
+ if (mNetworkRecommendationsEnabled) {
+ updateNetworkScoreCache(scanDetails);
+ } else {
+ mExternalScoreEvaluator.update(scanDetails);
+ }
}
private void updateNetworkScoreCache(List<ScanDetail> scanDetails) {
@@ -91,6 +121,10 @@ public class RecommendedNetworkEvaluator implements WifiNetworkSelector.NetworkE
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed,
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks) {
+ if (!mNetworkRecommendationsEnabled) {
+ return mExternalScoreEvaluator.evaluateNetworks(scanDetails, currentNetwork,
+ currentBssid, connected, untrustedNetworkAllowed, connectableNetworks);
+ }
List<ScanResult> scanResults = new ArrayList<>();
for (int i = 0; i < scanDetails.size(); i++) {
ScanDetail scanDetail = scanDetails.get(i);
@@ -169,6 +203,9 @@ public class RecommendedNetworkEvaluator implements WifiNetworkSelector.NetworkE
@Override
public String getName() {
- return TAG;
+ if (mNetworkRecommendationsEnabled) {
+ return TAG;
+ }
+ return TAG + "-" + mExternalScoreEvaluator.getName();
}
}
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index feda6063e..bd4887a22 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -29,7 +29,6 @@ import android.net.wifi.WifiScanner.PnoSettings;
import android.net.wifi.WifiScanner.ScanSettings;
import android.os.Handler;
import android.os.Looper;
-import android.provider.Settings;
import android.util.LocalLog;
import com.android.internal.R;
@@ -119,7 +118,7 @@ public class WifiConnectivityManager {
// Saved network evaluator priority
private static final int SAVED_NETWORK_EVALUATOR_PRIORITY = 1;
- private static final int EXTERNAL_SCORE_EVALUATOR_PRIORITY = 2;
+ private static final int RECOMMENDED_NETWORK_EVALUATOR_PRIORITY = 2;
private final WifiStateMachine mStateMachine;
private final WifiScanner mScanner;
@@ -472,7 +471,6 @@ public class WifiConnectivityManager {
WifiLastResortWatchdog wifiLastResortWatchdog, WifiMetrics wifiMetrics,
Looper looper, Clock clock, boolean enable, FrameworkFacade frameworkFacade,
SavedNetworkEvaluator savedNetworkEvaluator,
- ExternalScoreEvaluator externalScoreEvaluator,
RecommendedNetworkEvaluator recommendedNetworkEvaluator) {
mStateMachine = stateMachine;
mScanner = scanner;
@@ -520,12 +518,8 @@ public class WifiConnectivityManager {
// Register the network evaluators
mNetworkSelector.registerNetworkEvaluator(savedNetworkEvaluator,
SAVED_NETWORK_EVALUATOR_PRIORITY);
- final WifiNetworkSelector.NetworkEvaluator networkEvaluator =
- frameworkFacade.getIntegerSetting(context,
- Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1
- ? recommendedNetworkEvaluator : externalScoreEvaluator;
- mNetworkSelector.registerNetworkEvaluator(networkEvaluator,
- EXTERNAL_SCORE_EVALUATOR_PRIORITY);
+ mNetworkSelector.registerNetworkEvaluator(recommendedNetworkEvaluator,
+ RECOMMENDED_NETWORK_EVALUATOR_PRIORITY);
// Register for all single scan results
mScanner.registerScanListener(mAllSingleScanListener);
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index b08404bc8..5fcfb5d79 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -91,7 +91,6 @@ public class WifiInjector {
private final WifiConfigManager mWifiConfigManager;
private final WifiNetworkSelector mWifiNetworkSelector;
private final SavedNetworkEvaluator mSavedNetworkEvaluator;
- private final ExternalScoreEvaluator mExternalScoreEvaluator;
private final RecommendedNetworkEvaluator mRecommendedNetworkEvaluator;
private final WifiNetworkScoreCache mWifiNetworkScoreCache;
private final NetworkScoreManager mNetworkScoreManager;
@@ -163,10 +162,12 @@ public class WifiInjector {
LocalLog localLog = mWifiNetworkSelector.getLocalLog();
mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext,
mWifiConfigManager, mClock, localLog);
- mExternalScoreEvaluator = new ExternalScoreEvaluator(
+ ExternalScoreEvaluator externalScoreEvaluator = new ExternalScoreEvaluator(
mContext, mWifiConfigManager, mWifiNetworkScoreCache, mClock, localLog);
- mRecommendedNetworkEvaluator = new RecommendedNetworkEvaluator(
- mWifiNetworkScoreCache, mNetworkScoreManager, mWifiConfigManager, localLog);
+ mRecommendedNetworkEvaluator = new RecommendedNetworkEvaluator(context,
+ context.getContentResolver(), mWifiStateMachineHandlerThread.getLooper(),
+ mFrameworkFacade, mWifiNetworkScoreCache, mNetworkScoreManager, mWifiConfigManager,
+ localLog, externalScoreEvaluator);
mWifiStateMachine = new WifiStateMachine(mContext, mFrameworkFacade,
mWifiStateMachineHandlerThread.getLooper(), UserManager.get(mContext),
this, mBackupManagerProxy, mCountryCode, mWifiNative);
@@ -375,7 +376,7 @@ public class WifiInjector {
mWifiConfigManager, wifiInfo, mWifiNetworkSelector, mWifiLastResortWatchdog,
mWifiMetrics, mWifiStateMachineHandlerThread.getLooper(), mClock,
hasConnectionRequests, mFrameworkFacade, mSavedNetworkEvaluator,
- mExternalScoreEvaluator, mRecommendedNetworkEvaluator);
+ mRecommendedNetworkEvaluator);
}
public WifiPermissionsUtil getWifiPermissionsUtil() {