diff options
11 files changed, 71 insertions, 64 deletions
diff --git a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java index 98cecf170..ff880f510 100644 --- a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java @@ -98,9 +98,7 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat } private void localLog(String log) { - if (mLocalLog != null) { - mLocalLog.log(log); - } + mLocalLog.log(log); } /** diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 6e32f9b31..7c38e5def 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -191,9 +191,7 @@ public class WifiConnectivityManager { // A helper to log debugging information in the local log buffer, which can // be retrieved in bugreport. private void localLog(String log) { - if (mLocalLog != null) { - mLocalLog.log(log); - } + mLocalLog.log(log); } // A periodic/PNO scan will be rescheduled up to MAX_SCAN_RESTART_ALLOWED times @@ -499,7 +497,8 @@ public class WifiConnectivityManager { WifiScanner scanner, WifiConfigManager configManager, WifiInfo wifiInfo, WifiNetworkSelector networkSelector, WifiConnectivityHelper connectivityHelper, WifiLastResortWatchdog wifiLastResortWatchdog, WifiMetrics wifiMetrics, - Looper looper, Clock clock, boolean enable, FrameworkFacade frameworkFacade, + Looper looper, Clock clock, LocalLog localLog, boolean enable, + FrameworkFacade frameworkFacade, SavedNetworkEvaluator savedNetworkEvaluator, RecommendedNetworkEvaluator recommendedNetworkEvaluator, PasspointNetworkEvaluator passpointNetworkEvaluator) { @@ -509,7 +508,7 @@ public class WifiConnectivityManager { mWifiInfo = wifiInfo; mNetworkSelector = networkSelector; mConnectivityHelper = connectivityHelper; - mLocalLog = networkSelector.getLocalLog(); + mLocalLog = localLog; mWifiLastResortWatchdog = wifiLastResortWatchdog; mWifiMetrics = wifiMetrics; mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); @@ -1290,11 +1289,11 @@ public class WifiConnectivityManager { /** * Dump the local logs. - * - * Note: this call temporarily calls in to NetworkSelector to dump the LocalLog. This should be - * refactored to dump from WifiConnectivityManager instead. */ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - mNetworkSelector.dump(fd, pw, args); + pw.println("Dump of WifiConnectivityManager"); + pw.println("WifiConnectivityManager - Log Begin ----"); + mLocalLog.dump(fd, pw, args); + pw.println("WifiConnectivityManager - Log End ----"); } } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index ff5d6e8cd..5fa0ee9ac 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -16,6 +16,7 @@ package com.android.server.wifi; +import android.app.ActivityManager; import android.content.Context; import android.net.NetworkScoreManager; import android.net.wifi.IApInterface; @@ -101,6 +102,7 @@ public class WifiInjector { private final WifiConfigStoreLegacy mWifiConfigStoreLegacy; private final WifiConfigManager mWifiConfigManager; private final WifiConnectivityHelper mWifiConnectivityHelper; + private final LocalLog mConnectivityLocalLog; private final WifiNetworkSelector mWifiNetworkSelector; private final SavedNetworkEvaluator mSavedNetworkEvaluator; private final PasspointNetworkEvaluator mPasspointNetworkEvaluator; @@ -193,18 +195,20 @@ public class WifiInjector { mWifiPermissionsWrapper, new NetworkListStoreData(), new DeletedEphemeralSsidsStoreData()); mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative); - mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiConfigManager, mClock); - LocalLog localLog = mWifiNetworkSelector.getLocalLog(); + mConnectivityLocalLog = new LocalLog(ActivityManager.isLowRamDeviceStatic() ? 256 : 512); + mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiConfigManager, mClock, + mConnectivityLocalLog); mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, - mWifiConfigManager, mClock, localLog, wifiStateMachineLooper, mFrameworkFacade); + mWifiConfigManager, mClock, mConnectivityLocalLog, wifiStateMachineLooper, + mFrameworkFacade); mRecommendedNetworkEvaluator = new RecommendedNetworkEvaluator(context, context.getContentResolver(), wifiStateMachineLooper, mFrameworkFacade, - mNetworkScoreManager, mWifiConfigManager, localLog); + mNetworkScoreManager, mWifiConfigManager, mConnectivityLocalLog); mSimAccessor = new SIMAccessor(mContext); mPasspointManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore); mPasspointNetworkEvaluator = new PasspointNetworkEvaluator( - mPasspointManager, mWifiConfigManager, localLog); + mPasspointManager, mWifiConfigManager, mConnectivityLocalLog); // mWifiStateMachine has an implicit dependency on mJavaRuntime due to WifiDiagnostics. mJavaRuntime = Runtime.getRuntime(); mWifiStateMachine = new WifiStateMachine(mContext, mFrameworkFacade, @@ -393,13 +397,6 @@ public class WifiInjector { } /** - * Obtain an instance of WifiNetworkSelector. - */ - public WifiNetworkSelector getWifiNetworkSelector() { - return mWifiNetworkSelector; - } - - /** * Obtain a new instance of WifiConnectivityManager. * * Create and return a new WifiConnectivityManager. @@ -412,8 +409,8 @@ public class WifiInjector { return new WifiConnectivityManager(mContext, mWifiStateMachine, getWifiScanner(), mWifiConfigManager, wifiInfo, mWifiNetworkSelector, mWifiConnectivityHelper, mWifiLastResortWatchdog, mWifiMetrics, mWifiStateMachineHandlerThread.getLooper(), - mClock, hasConnectionRequests, mFrameworkFacade, mSavedNetworkEvaluator, - mRecommendedNetworkEvaluator, mPasspointNetworkEvaluator); + mClock, mConnectivityLocalLog, hasConnectionRequests, mFrameworkFacade, + mSavedNetworkEvaluator, mRecommendedNetworkEvaluator, mPasspointNetworkEvaluator); } public WifiPermissionsUtil getWifiPermissionsUtil() { diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 5b3bc24ed..5b84537ae 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -18,7 +18,6 @@ package com.android.server.wifi; import android.annotation.NonNull; import android.annotation.Nullable; -import android.app.ActivityManager; import android.content.Context; import android.net.NetworkKey; import android.net.wifi.ScanResult; @@ -31,8 +30,6 @@ import android.util.Pair; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; -import java.io.FileDescriptor; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -48,11 +45,9 @@ public class WifiNetworkSelector { @VisibleForTesting public static final int MINIMUM_NETWORK_SELECTION_INTERVAL_MS = 10 * 1000; - private WifiConfigManager mWifiConfigManager; - private Clock mClock; - - private final LocalLog mLocalLog = - new LocalLog(ActivityManager.isLowRamDeviceStatic() ? 256 : 512); + private final WifiConfigManager mWifiConfigManager; + private final Clock mClock; + private final LocalLog mLocalLog; private long mLastNetworkSelectionTimeStamp = INVALID_TIME_STAMP; // Buffer of filtered scan results (Scan results considered by network selection) & associated // WifiConfiguration (if any). @@ -508,9 +503,11 @@ public class WifiNetworkSelector { return true; } - WifiNetworkSelector(Context context, WifiConfigManager configManager, Clock clock) { + WifiNetworkSelector(Context context, WifiConfigManager configManager, Clock clock, + LocalLog localLog) { mWifiConfigManager = configManager; mClock = clock; + mLocalLog = localLog; mThresholdQualifiedRssi24 = context.getResources().getInteger( R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz); @@ -523,21 +520,4 @@ public class WifiNetworkSelector { mEnableAutoJoinWhenAssociated = context.getResources().getBoolean( R.bool.config_wifi_framework_enable_associated_network_selection); } - - /** - * Retrieve the local log buffer created by WifiNetworkSelector. - */ - public LocalLog getLocalLog() { - return mLocalLog; - } - - /** - * Dump the local logs. - */ - public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - pw.println("Dump of WifiNetworkSelector"); - pw.println("WifiNetworkSelector - Log Begin ----"); - mLocalLog.dump(fd, pw, args); - pw.println("WifiNetworkSelector - Log End ----"); - } } diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 1e94f8e47..d6ef5e870 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -205,7 +205,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss private WifiPermissionsUtil mWifiPermissionsUtil; private WifiConfigManager mWifiConfigManager; private WifiConnectivityManager mWifiConnectivityManager; - private WifiNetworkSelector mWifiNetworkSelector; private INetworkManagementService mNwService; private IClientInterface mClientInterface; private ConnectivityManager mCm; @@ -903,7 +902,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss mWifiDiagnostics = mWifiInjector.makeWifiDiagnostics(mWifiNative); mWifiInfo = new WifiInfo(); - mWifiNetworkSelector = mWifiInjector.getWifiNetworkSelector(); mSupplicantStateTracker = mFacade.makeSupplicantStateTracker(context, mWifiConfigManager, getHandler()); @@ -2159,7 +2157,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss mWifiDiagnostics.captureBugReportData(WifiDiagnostics.REPORT_REASON_USER_ACTION); mWifiDiagnostics.dump(fd, pw, args); dumpIpManager(fd, pw, args); - mWifiNetworkSelector.dump(fd, pw, args); + if (mWifiConnectivityManager != null) { + mWifiConnectivityManager.dump(fd, pw, args); + } else { + pw.println("mWifiConnectivityManager is not initialized"); + } } public void handleUserSwitch(int userId) { diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java index 3baf5c6da..1bade6c52 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java @@ -172,8 +172,6 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } private void localLog(String log) { - if (mLocalLog != null) { - mLocalLog.log(log); - } + mLocalLog.log(log); } } diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java index a25823890..ec19e038c 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java @@ -33,6 +33,7 @@ import android.os.Looper; import android.os.SystemClock; import android.provider.Settings; import android.test.suitebuilder.annotation.SmallTest; +import android.util.LocalLog; import com.android.internal.R; import com.android.server.wifi.WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs; @@ -59,6 +60,7 @@ public class SavedNetworkEvaluatorTest { setupContext(); setupResource(); setupWifiConfigManager(); + mLocalLog = new LocalLog(512); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); when(mFrameworkFacade.getIntegerSetting(mContext, @@ -83,7 +85,7 @@ public class SavedNetworkEvaluatorTest { ArgumentCaptor.forClass(ContentObserver.class); mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, mWifiConfigManager, - mClock, null, Looper.getMainLooper(), mFrameworkFacade); + mClock, mLocalLog, Looper.getMainLooper(), mFrameworkFacade); verify(mFrameworkFacade, times(2)).registerContentObserver(eq(mContext), any(Uri.class), eq(false), observerCaptor.capture()); // SavedNetworkEvaluator uses a single ContentObserver for two registrations, we only need @@ -104,6 +106,7 @@ public class SavedNetworkEvaluatorTest { @Mock private FrameworkFacade mFrameworkFacade; @Mock private Resources mResource; @Mock private Clock mClock; + private LocalLog mLocalLog; private int mThresholdMinimumRssi2G; private int mThresholdMinimumRssi5G; private int mThresholdQualifiedRssi2G; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index b87b9c82b..55438449e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -44,6 +44,7 @@ import android.os.SystemClock; import android.os.WorkSource; import android.os.test.TestLooper; import android.test.suitebuilder.annotation.SmallTest; +import android.util.LocalLog; import com.android.internal.R; @@ -56,6 +57,9 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.io.FileDescriptor; +import java.io.PrintWriter; +import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; @@ -74,6 +78,7 @@ public class WifiConnectivityManagerTest { mResource = mockResource(); mAlarmManager = new TestAlarmManager(); mContext = mockContext(); + mLocalLog = new LocalLog(512); mWifiStateMachine = mockWifiStateMachine(); mWifiConfigManager = mockWifiConfigManager(); mWifiInfo = getWifiInfo(); @@ -107,6 +112,7 @@ public class WifiConnectivityManagerTest { private ScanData mScanData; private WifiConfigManager mWifiConfigManager; private WifiInfo mWifiInfo; + private LocalLog mLocalLog; @Mock private FrameworkFacade mFrameworkFacade; @Mock private NetworkScoreManager mNetworkScoreManager; @Mock private Clock mClock; @@ -274,8 +280,8 @@ public class WifiConnectivityManagerTest { WifiConnectivityManager createConnectivityManager() { return new WifiConnectivityManager(mContext, mWifiStateMachine, mWifiScanner, mWifiConfigManager, mWifiInfo, mWifiNS, mWifiConnectivityHelper, - mWifiLastResortWatchdog, mWifiMetrics, mLooper.getLooper(), mClock, true, - mFrameworkFacade, null, null, null); + mWifiLastResortWatchdog, mWifiMetrics, mLooper.getLooper(), mClock, + mLocalLog, true, mFrameworkFacade, null, null, null); } /** @@ -1530,4 +1536,21 @@ public class WifiConnectivityManagerTest { verify(mWifiStateMachine, times(0)).startRoamToNetwork(anyInt(), anyObject()); } + + /** + * Dump local log buffer. + * + * Expected behavior: Logs dumped from WifiConnectivityManager.dump() + * contain the message we put in mLocalLog. + */ + @Test + public void dumpLocalLog() { + final String localLogMessage = "This is a message from the test"; + mLocalLog.log(localLogMessage); + + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + mWifiConnectivityManager.dump(new FileDescriptor(), pw, new String[]{}); + assertTrue(sw.toString().contains(localLogMessage)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 73469a386..8ad9e078a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -30,6 +30,7 @@ import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiInfo; import android.os.SystemClock; import android.test.suitebuilder.annotation.SmallTest; +import android.util.LocalLog; import android.util.Pair; import com.android.internal.R; @@ -58,8 +59,10 @@ public class WifiNetworkSelectorTest { setupResources(); setupWifiConfigManager(); setupWifiInfo(); + mLocalLog = new LocalLog(512); - mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiConfigManager, mClock); + mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiConfigManager, mClock, + mLocalLog); mWifiNetworkSelector.registerNetworkEvaluator(mDummyEvaluator, 1); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); @@ -116,6 +119,7 @@ public class WifiNetworkSelectorTest { @Mock private Resources mResource; @Mock private WifiInfo mWifiInfo; @Mock private Clock mClock; + private LocalLog mLocalLog; private int mThresholdMinimumRssi2G; private int mThresholdMinimumRssi5G; private int mThresholdQualifiedRssi2G; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index ad441f54d..ab8ab0da0 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -360,7 +360,6 @@ public class WifiStateMachineTest { when(mWifiInjector.makeWificond()).thenReturn(mWificond); when(mWifiInjector.getWifiConfigManager()).thenReturn(mWifiConfigManager); when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner); - when(mWifiInjector.getWifiNetworkSelector()).thenReturn(mock(WifiNetworkSelector.class)); when(mWifiInjector.makeWifiConnectivityManager(any(WifiInfo.class), anyBoolean())) .thenReturn(mWifiConnectivityManager); when(mWifiInjector.makeSoftApManager(any(INetworkManagementService.class), diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java index 27e7c3da7..cb20d0ccd 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java @@ -33,6 +33,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.hotspot2.PasspointConfiguration; import android.net.wifi.hotspot2.pps.HomeSp; import android.test.suitebuilder.annotation.SmallTest; +import android.util.LocalLog; import android.util.Pair; import com.android.server.wifi.NetworkUpdateResult; @@ -66,6 +67,7 @@ public class PasspointNetworkEvaluatorTest { @Mock PasspointManager mPasspointManager; @Mock WifiConfigManager mWifiConfigManager; + LocalLog mLocalLog; PasspointNetworkEvaluator mEvaluator; /** @@ -122,7 +124,9 @@ public class PasspointNetworkEvaluatorTest { @Before public void setUp() throws Exception { initMocks(this); - mEvaluator = new PasspointNetworkEvaluator(mPasspointManager, mWifiConfigManager, null); + mLocalLog = new LocalLog(512); + mEvaluator = new PasspointNetworkEvaluator(mPasspointManager, mWifiConfigManager, + mLocalLog); } /** |