diff options
author | Mingguang Xu <mingguangxu@google.com> | 2020-08-26 15:36:56 -0700 |
---|---|---|
committer | Mingguang Xu <mingguangxu@google.com> | 2020-09-04 05:37:10 +0000 |
commit | e39ae652622987db1bfbb3410a9f13a813e20abd (patch) | |
tree | a4e64ca44731bd5891a0739ccb18a074aa34765a /service | |
parent | edc209e114cb84977b592bd4ef2fe8203a68951c (diff) |
Add Adaptive Connectivity toggle
The Adaptive Connectivity toggle is enabled by default: no behavior
change in WifiScoreReport. When it is disabled the following changes
are made:
1. Send a constant score of 51 to connectivity service.
2. Never recommend a NUD check.
Bug: 166644305
Test: atest com.android.server.wifi
Signed-off-by: Mingguang Xu <mingguangxu@google.com>
Change-Id: I72762fc129c9f026ca9323b11e4e159ed2706cb7
Merged-In: I72762fc129c9f026ca9323b11e4e159ed2706cb7
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/ClientModeImpl.java | 3 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiScoreReport.java | 78 |
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 95983096a..0b67fa319 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(); + } } |