diff options
8 files changed, 170 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/ActiveModeManager.java b/service/java/com/android/server/wifi/ActiveModeManager.java index 6669e32f7..f193a0c94 100644 --- a/service/java/com/android/server/wifi/ActiveModeManager.java +++ b/service/java/com/android/server/wifi/ActiveModeManager.java @@ -22,6 +22,9 @@ import android.net.wifi.WifiManager; import android.os.UserHandle; import android.util.Log; +import java.io.FileDescriptor; +import java.io.PrintWriter; + /** * Base class for available WiFi operating modes. * @@ -41,6 +44,11 @@ public interface ActiveModeManager { void stop(); /** + * Method to dump for logging state. + */ + void dump(FileDescriptor fd, PrintWriter pw, String[] args); + + /** * Method that allows Mode Managers to update WifiScanner about the current state. * * @param context Context to use for the notification diff --git a/service/java/com/android/server/wifi/ClientModeManager.java b/service/java/com/android/server/wifi/ClientModeManager.java index f55d9d297..922d21958 100644 --- a/service/java/com/android/server/wifi/ClientModeManager.java +++ b/service/java/com/android/server/wifi/ClientModeManager.java @@ -31,6 +31,9 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.server.wifi.WifiNative.InterfaceCallback; +import java.io.FileDescriptor; +import java.io.PrintWriter; + /** * Manager WiFi in Client Mode where we connect to configured networks. */ @@ -48,7 +51,7 @@ public class ClientModeManager implements ActiveModeManager { private final WifiStateMachine mWifiStateMachine; private String mClientInterfaceName; - private boolean mIfaceIsUp; + private boolean mIfaceIsUp = false; ClientModeManager(Context context, @NonNull Looper looper, WifiNative wifiNative, Listener listener, WifiMetrics wifiMetrics, ScanRequestProxy scanRequestProxy, @@ -73,8 +76,7 @@ public class ClientModeManager implements ActiveModeManager { * Disconnect from any currently connected networks and stop client mode. */ public void stop() { - IState currentState = mStateMachine.getCurrentState(); - Log.d(TAG, " currentstate: " + currentState); + Log.d(TAG, " currentstate: " + getCurrentStateName()); if (mClientInterfaceName != null) { if (mIfaceIsUp) { updateWifiState(WifiManager.WIFI_STATE_DISABLING, @@ -88,6 +90,17 @@ public class ClientModeManager implements ActiveModeManager { } /** + * Dump info about this ClientMode manager. + */ + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.println("--Dump of ClientModeManager--"); + + pw.println("current StateMachine mode: " + getCurrentStateName()); + pw.println("mClientInterfaceName: " + mClientInterfaceName); + pw.println("mIfaceIsUp: " + mIfaceIsUp); + } + + /** * Listener for ClientMode state changes. */ public interface Listener { @@ -98,6 +111,16 @@ public class ClientModeManager implements ActiveModeManager { void onStateChanged(int state); } + private String getCurrentStateName() { + IState currentState = mStateMachine.getCurrentState(); + + if (currentState != null) { + return currentState.getName(); + } + + return "StateMachine not active"; + } + /** * Update Wifi state and send the broadcast. * @param newState new Wifi state diff --git a/service/java/com/android/server/wifi/DefaultModeManager.java b/service/java/com/android/server/wifi/DefaultModeManager.java index 6d51c9fde..3a164d644 100644 --- a/service/java/com/android/server/wifi/DefaultModeManager.java +++ b/service/java/com/android/server/wifi/DefaultModeManager.java @@ -20,6 +20,9 @@ import android.annotation.NonNull; import android.content.Context; import android.os.Looper; +import java.io.FileDescriptor; +import java.io.PrintWriter; + /** * Manager to handle API calls when wifi is disabled (other mode managers could be active, but this * class triggers calls to the default implementations). @@ -40,6 +43,11 @@ public class DefaultModeManager implements ActiveModeManager { */ public void stop() { }; + /** + * Dump is not used in default mode. + */ + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { } + DefaultModeManager(Context context, @NonNull Looper looper) { mContext = context; } diff --git a/service/java/com/android/server/wifi/ScanOnlyModeManager.java b/service/java/com/android/server/wifi/ScanOnlyModeManager.java index 985d025db..a98c6ba66 100644 --- a/service/java/com/android/server/wifi/ScanOnlyModeManager.java +++ b/service/java/com/android/server/wifi/ScanOnlyModeManager.java @@ -29,6 +29,9 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.server.wifi.WifiNative.InterfaceCallback; +import java.io.FileDescriptor; +import java.io.PrintWriter; + /** * Manager WiFi in Scan Only Mode - no network connections. */ @@ -47,6 +50,7 @@ public class ScanOnlyModeManager implements ActiveModeManager { private final WakeupController mWakeupController; private String mClientInterfaceName; + private boolean mIfaceIsUp = false; ScanOnlyModeManager(@NonNull Context context, @NonNull Looper looper, @NonNull WifiNative wifiNative, @NonNull Listener listener, @@ -73,12 +77,22 @@ public class ScanOnlyModeManager implements ActiveModeManager { * Cancel any pending scans and stop scan mode. */ public void stop() { - IState currentState = mStateMachine.getCurrentState(); - Log.d(TAG, " currentstate: " + currentState); + Log.d(TAG, " currentstate: " + getCurrentStateName()); mStateMachine.quitNow(); } /** + * Dump info about this ScanOnlyMode manager. + */ + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.println("--Dump of ScanOnlyModeManager--"); + + pw.println("current StateMachine mode: " + getCurrentStateName()); + pw.println("mClientInterfaceName: " + mClientInterfaceName); + pw.println("mIfaceIsUp: " + mIfaceIsUp); + } + + /** * Listener for ScanOnlyMode state changes. */ public interface Listener { @@ -89,6 +103,16 @@ public class ScanOnlyModeManager implements ActiveModeManager { void onStateChanged(int state); } + private String getCurrentStateName() { + IState currentState = mStateMachine.getCurrentState(); + + if (currentState != null) { + return currentState.getName(); + } + + return "StateMachine not active"; + } + /** * Update Wifi state. * @param state new Wifi state @@ -129,7 +153,6 @@ public class ScanOnlyModeManager implements ActiveModeManager { } } }; - private boolean mIfaceIsUp = false; ScanOnlyModeStateMachine(Looper looper) { super(TAG, looper); diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 1716015a2..99bdb5b98 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -45,6 +45,8 @@ import com.android.server.wifi.WifiNative.InterfaceCallback; import com.android.server.wifi.WifiNative.SoftApListener; import com.android.server.wifi.util.ApConfigUtil; +import java.io.FileDescriptor; +import java.io.PrintWriter; import java.util.Locale; /** @@ -81,6 +83,12 @@ public class SoftApManager implements ActiveModeManager { private final int mMode; private WifiConfiguration mApConfig; + private int mReportedFrequency = -1; + private int mReportedBandwidth = -1; + + private int mNumAssociatedStations = 0; + private boolean mTimeoutEnabled = false; + /** * Listener for soft AP events. */ @@ -135,8 +143,7 @@ public class SoftApManager implements ActiveModeManager { * Stop soft AP. */ public void stop() { - IState currentState = mStateMachine.getCurrentState(); - Log.d(TAG, " currentstate: " + currentState); + Log.d(TAG, " currentstate: " + getCurrentStateName()); if (mApInterfaceName != null) { if (mIfaceIsUp) { updateApState(WifiManager.WIFI_AP_STATE_DISABLING, @@ -150,6 +157,40 @@ public class SoftApManager implements ActiveModeManager { } /** + * Dump info about this softap manager. + */ + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.println("--Dump of SoftApManager--"); + + pw.println("current StateMachine mode: " + getCurrentStateName()); + pw.println("mApInterfaceName: " + mApInterfaceName); + pw.println("mIfaceIsUp: " + mIfaceIsUp); + pw.println("mMode: " + mMode); + pw.println("mCountryCode: " + mCountryCode); + if (mApConfig != null) { + pw.println("mApConfig.SSID: " + mApConfig.SSID); + pw.println("mApConfig.apBand: " + mApConfig.apBand); + pw.println("mApConfig.hiddenSSID: " + mApConfig.hiddenSSID); + } else { + pw.println("mApConfig: null"); + } + pw.println("mNumAssociatedStations: " + mNumAssociatedStations); + pw.println("mTimeoutEnabled: " + mTimeoutEnabled); + pw.println("mReportedFrequency: " + mReportedFrequency); + pw.println("mReportedBandwidth: " + mReportedBandwidth); + } + + private String getCurrentStateName() { + IState currentState = mStateMachine.getCurrentState(); + + if (currentState != null) { + return currentState.getName(); + } + + return "StateMachine not active"; + } + + /** * Update AP state. * @param newState new AP state * @param currentState current AP state @@ -324,9 +365,6 @@ public class SoftApManager implements ActiveModeManager { } private class StartedState extends State { - private int mNumAssociatedStations; - - private boolean mTimeoutEnabled; private int mTimeoutDelay; private WakeupMessage mSoftApTimeoutMessage; private SoftApTimeoutEnabledSettingObserver mSettingObserver; @@ -486,10 +524,12 @@ public class SoftApManager implements ActiveModeManager { setNumAssociatedStations(message.arg1); break; case CMD_SOFT_AP_CHANNEL_SWITCHED: - Log.d(TAG, "Channel switched. Frequency: " + message.arg1 + " Bandwidth: " - + message.arg2); - mWifiMetrics.addSoftApChannelSwitchedEvent(message.arg1, message.arg2, - mMode); + mReportedFrequency = message.arg1; + mReportedBandwidth = message.arg2; + Log.d(TAG, "Channel switched. Frequency: " + mReportedFrequency + + " Bandwidth: " + mReportedBandwidth); + mWifiMetrics.addSoftApChannelSwitchedEvent(mReportedFrequency, + mReportedBandwidth, mMode); break; case CMD_TIMEOUT_TOGGLE_CHANGED: boolean isEnabled = (message.arg1 == 1); diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index c2913ea73..ad5f133dc 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -148,6 +148,7 @@ public class WifiServiceImpl extends IWifiManager.Stub { private static final int RUN_WITH_SCISSORS_TIMEOUT_MILLIS = 4000; final WifiStateMachine mWifiStateMachine; + final WifiStateMachinePrime mWifiStateMachinePrime; final ScanRequestProxy mScanRequestProxy; private final Context mContext; @@ -453,6 +454,7 @@ public class WifiServiceImpl extends IWifiManager.Stub { mUserManager = mWifiInjector.getUserManager(); mCountryCode = mWifiInjector.getWifiCountryCode(); mWifiStateMachine = mWifiInjector.getWifiStateMachine(); + mWifiStateMachinePrime = mWifiInjector.getWifiStateMachinePrime(); mWifiStateMachine.enableRssiPolling(true); mScanRequestProxy = mWifiInjector.getScanRequestProxy(); mSettingsStore = mWifiInjector.getWifiSettingsStore(); @@ -2521,6 +2523,8 @@ public class WifiServiceImpl extends IWifiManager.Stub { pw.println(); mWifiMulticastLockManager.dump(pw); pw.println(); + mWifiStateMachinePrime.dump(fd, pw, args); + pw.println(); mWifiStateMachine.dump(fd, pw, args); pw.println(); mWifiStateMachine.updateWifiMetrics(); diff --git a/service/java/com/android/server/wifi/WifiStateMachinePrime.java b/service/java/com/android/server/wifi/WifiStateMachinePrime.java index fdacd1460..3becd9bad 100644 --- a/service/java/com/android/server/wifi/WifiStateMachinePrime.java +++ b/service/java/com/android/server/wifi/WifiStateMachinePrime.java @@ -34,6 +34,9 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.server.wifi.WifiNative.StatusListener; +import java.io.FileDescriptor; +import java.io.PrintWriter; + /** * This class provides the implementation for different WiFi operating modes. * @@ -216,6 +219,21 @@ public class WifiStateMachinePrime { }); } + /** + * Dump current state for active mode managers. + * + * Must be called from WifiStateMachine thread. + */ + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.println("Dump of " + TAG); + + pw.println("Current wifi mode: " + getCurrentMode()); + pw.println("NumActiveModeManagers: " + mActiveModeManagers.size()); + for (ActiveModeManager manager : mActiveModeManagers) { + manager.dump(fd, pw, args); + } + } + protected String getCurrentMode() { return mModeStateMachine.getCurrentMode(); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachinePrimeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachinePrimeTest.java index ec1c0e8fe..651c0f88d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachinePrimeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachinePrimeTest.java @@ -38,6 +38,9 @@ import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; + /** * Unit tests for {@link com.android.server.wifi.WifiStateMachinePrime}. */ @@ -644,4 +647,32 @@ public class WifiStateMachinePrimeTest { verify(mSoftApStateMachineCallback).onStateChanged(WifiManager.WIFI_AP_STATE_DISABLED, 0); } + /** + * Verify that we do not crash when calling dump and wifi is fully disabled. + */ + @Test + public void dumpWhenWifiFullyOffDoesNotCrash() throws Exception { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(stream); + mWifiStateMachinePrime.dump(null, writer, null); + } + + /** + * Verify that we trigger dump on active mode managers. + */ + @Test + public void dumpCallsActiveModeManagers() throws Exception { + enterSoftApActiveMode(); + enterClientModeActiveState(); + enterScanOnlyModeActiveState(); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(stream); + mWifiStateMachinePrime.dump(null, writer, null); + + verify(mSoftApManager).dump(eq(null), eq(writer), eq(null)); + // can only be in scan or client, so we should not have a client mode active + verify(mClientModeManager, never()).dump(eq(null), eq(writer), eq(null)); + verify(mScanOnlyModeManager).dump(eq(null), eq(writer), eq(null)); + } } |