summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorMingguang Xu <mingguangxu@google.com>2020-09-08 23:37:41 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-09-08 23:37:41 +0000
commitd83dbd96b83de60f26209d23f8129ccbdefe6bdf (patch)
treea4dac632f108a8a5abf05281c561daf141a94d03 /service
parenta0d01b665d79abaeabcbddba79c46d7d3b10e168 (diff)
parente39ae652622987db1bfbb3410a9f13a813e20abd (diff)
Merge "Add Adaptive Connectivity toggle" into rvc-qpr-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java3
-rw-r--r--service/java/com/android/server/wifi/WifiScoreReport.java78
2 files changed, 79 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 9f4c41f83..e7371a9f1 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -812,7 +812,7 @@ public class ClientModeImpl extends StateMachine {
mWifiScoreReport = new WifiScoreReport(mWifiInjector.getScoringParams(), mClock,
mWifiMetrics, mWifiInfo, mWifiNative, mBssidBlocklistMonitor,
mWifiInjector.getWifiThreadRunner(), mWifiInjector.getDeviceConfigFacade(),
- mContext);
+ mContext, looper, mFacade);
mNetworkCapabilitiesFilter = new NetworkCapabilities.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
@@ -3441,6 +3441,7 @@ public class ClientModeImpl extends StateMachine {
break;
case CMD_INITIALIZE:
mWifiNative.initialize();
+ mWifiScoreReport.initialize();
break;
case CMD_BOOT_COMPLETED:
// get other services that we need to manage
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java
index 89f0445cb..381be7f2b 100644
--- a/service/java/com/android/server/wifi/WifiScoreReport.java
+++ b/service/java/com/android/server/wifi/WifiScoreReport.java
@@ -17,16 +17,22 @@
package com.android.server.wifi;
import android.content.Context;
+import android.database.ContentObserver;
import android.net.Network;
import android.net.NetworkAgent;
+import android.net.Uri;
import android.net.wifi.IScoreUpdateObserver;
import android.net.wifi.IWifiConnectedNetworkScorer;
import android.net.wifi.WifiInfo;
import android.net.wifi.nl80211.WifiNl80211Manager;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.RemoteException;
+import android.provider.Settings;
import android.util.Log;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.wifi.resources.R;
import java.io.FileDescriptor;
@@ -57,6 +63,15 @@ public class WifiScoreReport {
private static final long DURATION_TO_BLOCKLIST_BSSID_AFTER_FIRST_EXITING_MILLIS = 30000;
private static final long INVALID_WALL_CLOCK_MILLIS = -1;
+ /**
+ * Copy of the settings string. Can't directly use the constant because it is @hide.
+ * See {@link android.provider.Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED}.
+ * TODO(b/167709538) remove this hardcoded string and create new API in Wifi mainline.
+ */
+ @VisibleForTesting
+ public static final String SETTINGS_SECURE_ADAPTIVE_CONNECTIVITY_ENABLED =
+ "adaptive_connectivity_enabled";
+
// Cache of the last score
private int mScore = ConnectedScore.WIFI_MAX_SCORE;
@@ -78,6 +93,8 @@ public class WifiScoreReport {
WifiNative mWifiNative;
WifiThreadRunner mWifiThreadRunner;
DeviceConfigFacade mDeviceConfigFacade;
+ Handler mHandler;
+ FrameworkFacade mFrameworkFacade;
/**
* Callback proxy. See {@link android.net.wifi.WifiManager.ScoreUpdateObserver}.
@@ -200,6 +217,10 @@ public class WifiScoreReport {
return;
}
}
+ // Stay a notch above the transition score if adaptive connectivity is disabled.
+ if (!mAdaptiveConnectivityEnabled) {
+ score = ConnectedScore.WIFI_TRANSITION_SCORE + 1;
+ }
mNetworkAgent.sendNetworkScore(score);
}
@@ -286,10 +307,50 @@ public class WifiScoreReport {
private WifiConnectedNetworkScorerHolder mWifiConnectedNetworkScorerHolder;
+ /**
+ * Observer for adaptive connectivity enable settings changes.
+ * This is enabled by default. Will be toggled off via adb command or a settings
+ * toggle by the user to disable adaptive connectivity.
+ */
+ private class AdaptiveConnectivityEnabledSettingObserver extends ContentObserver {
+ AdaptiveConnectivityEnabledSettingObserver(Handler handler) {
+ super(handler);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ mAdaptiveConnectivityEnabled = getValue();
+ Log.d(TAG, "Adaptive connectivity status changed: " + mAdaptiveConnectivityEnabled);
+ }
+
+ /**
+ * Register settings change observer.
+ */
+ public void initialize() {
+ Uri uri = Settings.Secure.getUriFor(SETTINGS_SECURE_ADAPTIVE_CONNECTIVITY_ENABLED);
+ if (uri == null) {
+ Log.e(TAG, "Adaptive connectivity user toggle does not exist in Settings");
+ return;
+ }
+ mFrameworkFacade.registerContentObserver(mContext, uri, true, this);
+ mAdaptiveConnectivityEnabled = mAdaptiveConnectivityEnabledSettingObserver.getValue();
+ }
+
+ public boolean getValue() {
+ return mFrameworkFacade.getIntegerSetting(
+ mContext, SETTINGS_SECURE_ADAPTIVE_CONNECTIVITY_ENABLED, 1) == 1;
+ }
+ }
+
+ private final AdaptiveConnectivityEnabledSettingObserver
+ mAdaptiveConnectivityEnabledSettingObserver;
+ private boolean mAdaptiveConnectivityEnabled = true;
+
WifiScoreReport(ScoringParams scoringParams, Clock clock, WifiMetrics wifiMetrics,
WifiInfo wifiInfo, WifiNative wifiNative, BssidBlocklistMonitor bssidBlocklistMonitor,
WifiThreadRunner wifiThreadRunner, DeviceConfigFacade deviceConfigFacade,
- Context context) {
+ Context context, Looper looper, FrameworkFacade frameworkFacade) {
mScoringParams = scoringParams;
mClock = clock;
mAggressiveConnectedScore = new AggressiveConnectedScore(scoringParams, clock);
@@ -301,6 +362,10 @@ public class WifiScoreReport {
mWifiThreadRunner = wifiThreadRunner;
mDeviceConfigFacade = deviceConfigFacade;
mContext = context;
+ mFrameworkFacade = frameworkFacade;
+ mHandler = new Handler(looper);
+ mAdaptiveConnectivityEnabledSettingObserver =
+ new AdaptiveConnectivityEnabledSettingObserver(mHandler);
}
/**
@@ -463,6 +528,10 @@ public class WifiScoreReport {
* @return true to indicate that an IP reachability check is recommended
*/
public boolean shouldCheckIpLayer() {
+ // Don't recommend if adaptive connectivity is disabled.
+ if (!mAdaptiveConnectivityEnabled) {
+ return false;
+ }
int nud = mScoringParams.getNudKnob();
if (nud == 0) {
return false;
@@ -703,4 +772,11 @@ public class WifiScoreReport {
mWifiConnectedNetworkScorerHolder = null;
mWifiMetrics.setIsExternalWifiScorerOn(false);
}
+
+ /**
+ * Initialize WifiScoreReport
+ */
+ public void initialize() {
+ mAdaptiveConnectivityEnabledSettingObserver.initialize();
+ }
}