summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-02-07 07:13:57 -0800
committerRoshan Pius <rpius@google.com>2020-02-10 07:03:23 -0800
commita9a4162adfe985e1415781d4d617055ffa98fc0a (patch)
treea772cac7c22f1f42b762d8de508cd4c8a10b5a93
parentfb6cf1c5a2b575ed386032ce24808fefa0db61e9 (diff)
ScoredNetworkNominator: Use getActiveScorerPackage() instead of settings
Use the getActiveScorerPackage() instead of using the settings value. This method will always return null when recommendations are disabled by the user (or if there are no scorers attached). Bug: 148514485 Test: atest com.android.server.wifi Test: Manually verified the Wi-Fi assistant toggle & ensured the scored network nominator was enabled/disabled accordingly. Change-Id: I5b181b9c4f6d578516a763ad6072c94498ffac24
-rw-r--r--service/java/com/android/server/wifi/ScoredNetworkNominator.java32
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java38
3 files changed, 18 insertions, 56 deletions
diff --git a/service/java/com/android/server/wifi/ScoredNetworkNominator.java b/service/java/com/android/server/wifi/ScoredNetworkNominator.java
index e3cc2abdf..0f71e7f01 100644
--- a/service/java/com/android/server/wifi/ScoredNetworkNominator.java
+++ b/service/java/com/android/server/wifi/ScoredNetworkNominator.java
@@ -18,16 +18,12 @@ 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.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
-import android.os.Handler;
import android.os.Process;
-import android.provider.Settings;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.Log;
@@ -50,13 +46,10 @@ public class ScoredNetworkNominator implements WifiNetworkSelector.NetworkNomina
private final PackageManager mPackageManager;
private final WifiConfigManager mWifiConfigManager;
private final LocalLog mLocalLog;
- private final ContentObserver mContentObserver;
private final WifiPermissionsUtil mWifiPermissionsUtil;
- private boolean mNetworkRecommendationsEnabled;
private WifiNetworkScoreCache mScoreCache;
- ScoredNetworkNominator(final Context context, Handler handler,
- final FrameworkFacade frameworkFacade, NetworkScoreManager networkScoreManager,
+ ScoredNetworkNominator(NetworkScoreManager networkScoreManager,
PackageManager packageManager,
WifiConfigManager wifiConfigManager, LocalLog localLog,
WifiNetworkScoreCache wifiNetworkScoreCache,
@@ -67,24 +60,19 @@ public class ScoredNetworkNominator implements WifiNetworkSelector.NetworkNomina
mPackageManager = packageManager;
mWifiConfigManager = wifiConfigManager;
mLocalLog = localLog;
- mContentObserver = new ContentObserver(handler) {
- @Override
- public void onChange(boolean selfChange) {
- mNetworkRecommendationsEnabled = frameworkFacade.getIntegerSetting(context,
- Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
- }
- };
- frameworkFacade.registerContentObserver(context,
- Settings.Global.getUriFor(Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED),
- false /* notifyForDescendents */, mContentObserver);
- mContentObserver.onChange(false /* unused */);
mLocalLog.log("ScoredNetworkNominator constructed. mNetworkRecommendationsEnabled: "
- + mNetworkRecommendationsEnabled);
+ + isNetworkRecommendationsEnabled());
+ }
+
+ private boolean isNetworkRecommendationsEnabled() {
+ // Check if we have any active scorer, not enabled otherwise.
+ String packageName = mNetworkScoreManager.getActiveScorerPackage();
+ return !TextUtils.isEmpty(packageName);
}
@Override
public void update(List<ScanDetail> scanDetails) {
- if (mNetworkRecommendationsEnabled) {
+ if (isNetworkRecommendationsEnabled()) {
updateNetworkScoreCache(scanDetails);
}
}
@@ -133,7 +121,7 @@ public class ScoredNetworkNominator implements WifiNetworkSelector.NetworkNomina
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed,
@NonNull OnConnectableListener onConnectableListener) {
- if (!mNetworkRecommendationsEnabled) {
+ if (!isNetworkRecommendationsEnabled()) {
mLocalLog.log("Skipping nominateNetworks; Network recommendations disabled.");
return;
}
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index fb34de55e..8246d020e 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -294,8 +294,8 @@ public class WifiInjector {
mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mTelephonyUtil);
mNetworkSuggestionNominator = new NetworkSuggestionNominator(mWifiNetworkSuggestionsManager,
mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mTelephonyUtil);
- mScoredNetworkNominator = new ScoredNetworkNominator(mContext, wifiHandler,
- mFrameworkFacade, mNetworkScoreManager, mContext.getPackageManager(),
+ mScoredNetworkNominator = new ScoredNetworkNominator(mNetworkScoreManager,
+ mContext.getPackageManager(),
mWifiConfigManager, mConnectivityLocalLog,
mWifiNetworkScoreCache, mWifiPermissionsUtil);
diff --git a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java
index 2c5945173..8cac464aa 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java
@@ -25,17 +25,11 @@ 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;
-import android.net.NetworkScorerAppData;
-import android.net.Uri;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
-import android.os.Handler;
-import android.os.Looper;
import android.os.SystemClock;
-import android.provider.Settings;
import android.util.LocalLog;
import androidx.test.filters.SmallTest;
@@ -63,15 +57,11 @@ import java.util.List;
public class ScoredNetworkNominatorTest extends WifiBaseTest {
private static final String TEST_PACKAGE_NAME = "name.package.test";
private static final int TEST_UID = 12345;
- private static final NetworkScorerAppData TEST_APP_DATA = new NetworkScorerAppData(
- TEST_UID, null, null, null, null);
- private ContentObserver mContentObserver;
private int mThresholdQualifiedRssi2G;
private int mThresholdQualifiedRssi5G;
@Mock private Context mContext;
@Mock private Clock mClock;
- @Mock private FrameworkFacade mFrameworkFacade;
@Mock private NetworkScoreManager mNetworkScoreManager;
@Mock private PackageManager mPackageManager;
@Mock private WifiConfigManager mWifiConfigManager;
@@ -90,28 +80,17 @@ public class ScoredNetworkNominatorTest extends WifiBaseTest {
MockitoAnnotations.initMocks(this);
- 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);
- mScoredNetworkNominator = new ScoredNetworkNominator(mContext,
- new Handler(Looper.getMainLooper()), mFrameworkFacade, mNetworkScoreManager,
+ mScoredNetworkNominator = new ScoredNetworkNominator(mNetworkScoreManager,
mPackageManager, mWifiConfigManager, new LocalLog(0), mScoreCache,
mWifiPermissionsUtil);
- verify(mFrameworkFacade).registerContentObserver(eq(mContext), any(Uri.class), eq(false),
- observerCaptor.capture());
- mContentObserver = observerCaptor.getValue();
reset(mNetworkScoreManager);
- when(mNetworkScoreManager.getActiveScorer())
- .thenReturn(TEST_APP_DATA);
when(mNetworkScoreManager.getActiveScorerPackage())
.thenReturn(TEST_PACKAGE_NAME);
@@ -136,13 +115,10 @@ public class ScoredNetworkNominatorTest extends WifiBaseTest {
.setupScanDetailsAndConfigStore(
ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock);
- when(mFrameworkFacade.getIntegerSetting(mContext,
- Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0))
- .thenReturn(0);
-
- mContentObserver.onChange(false /* unused */);
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(null);
mScoredNetworkNominator.update(scanDetailsAndConfigs.getScanDetails());
+ verify(mNetworkScoreManager).getActiveScorerPackage();
verifyZeroInteractions(mNetworkScoreManager);
}
@@ -161,6 +137,7 @@ public class ScoredNetworkNominatorTest extends WifiBaseTest {
ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock);
mScoredNetworkNominator.update(new ArrayList<ScanDetail>());
+ verify(mNetworkScoreManager).getActiveScorerPackage();
verifyZeroInteractions(mNetworkScoreManager);
}
@@ -225,15 +202,12 @@ public class ScoredNetworkNominatorTest extends WifiBaseTest {
@Test
public void testEvaluateNetworks_recommendationsDisabled() {
- when(mFrameworkFacade.getIntegerSetting(mContext,
- Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0))
- .thenReturn(0);
-
- mContentObserver.onChange(false /* unused */);
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(null);
mScoredNetworkNominator.nominateNetworks(null, null, null, false, false,
mOnConnectableListener);
+ verify(mNetworkScoreManager).getActiveScorerPackage();
verifyZeroInteractions(mWifiConfigManager, mNetworkScoreManager);
}