summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-08-28 10:19:52 -0700
committerRoshan Pius <rpius@google.com>2019-10-01 06:37:50 -0700
commit0bb82132745675a099c7d3c10e821dd6872b59a1 (patch)
tree490f6a69a5046c9005cfa294f7297d7ab47f8649
parent92954cee2f13a21b4f8f6b19e2f1223eb56ec051 (diff)
ActiveModeManager: Add a generic mode manager callback
Add a generic mode manager callback for each mode manager to indicate the following events: a) start failure b) stopped c) started (this is temporary). Will be removed in a future CL when ScanOnlyModeManager is removed. ActiveModeWarden only needs to know when the corresponding mode manager is no longer needed (either due to failure or if it was stopped). So, it doesn't need to know any of the other intermediate events, This also avoids mixing the public broadcast constants for Client mode & Softap with mode management related callback. Also, added a dump of state machine for each mode manager. TODO: Will fix unit tests in a later CL. Bug: 128585344 Bug: 127624451 Test: Manual tests in progress. Change-Id: Id93361a4dd2ec1d7dd12701228b839920c8b71cb
-rw-r--r--service/java/com/android/server/wifi/ActiveModeManager.java18
-rw-r--r--service/java/com/android/server/wifi/ActiveModeWarden.java119
-rw-r--r--service/java/com/android/server/wifi/ClientModeManager.java36
-rw-r--r--service/java/com/android/server/wifi/ScanOnlyModeManager.java50
-rw-r--r--service/java/com/android/server/wifi/SoftApManager.java22
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java5
6 files changed, 127 insertions, 123 deletions
diff --git a/service/java/com/android/server/wifi/ActiveModeManager.java b/service/java/com/android/server/wifi/ActiveModeManager.java
index 7c50726f9..59287cb71 100644
--- a/service/java/com/android/server/wifi/ActiveModeManager.java
+++ b/service/java/com/android/server/wifi/ActiveModeManager.java
@@ -30,6 +30,24 @@ import java.lang.annotation.RetentionPolicy;
*/
public interface ActiveModeManager {
/**
+ * Listener for ActiveModeManager state changes.
+ */
+ interface Listener {
+ /**
+ * Invoked when mode manager completes start.
+ */
+ void onStarted();
+ /**
+ * Invoked when mode manager completes stop.
+ */
+ void onStopped();
+ /**
+ * Invoked when mode manager encountered a failure on start.
+ */
+ void onStartFailure();
+ }
+
+ /**
* Method used to start the Manager for a given Wifi operational mode.
*/
void start();
diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java
index adc708e1c..0ae7e0f12 100644
--- a/service/java/com/android/server/wifi/ActiveModeWarden.java
+++ b/service/java/com/android/server/wifi/ActiveModeWarden.java
@@ -205,8 +205,10 @@ public class ActiveModeWarden {
+ softApConfig.getWifiConfiguration());
SoftApCallbackImpl callback = new SoftApCallbackImpl(softApConfig.getTargetMode());
- ActiveModeManager manager = mWifiInjector.makeSoftApManager(callback, softApConfig);
- callback.setActiveModeManager(manager);
+ SoftApListener listener = new SoftApListener();
+ ActiveModeManager manager =
+ mWifiInjector.makeSoftApManager(listener, callback, softApConfig);
+ listener.setActiveModeManager(manager);
manager.start();
mActiveModeManagers.add(manager);
updateBatteryStatsWifiState(true);
@@ -298,7 +300,7 @@ public class ActiveModeWarden {
}
}
- private class SoftApCallbackImpl extends ModeCallback implements WifiManager.SoftApCallback {
+ private class SoftApCallbackImpl implements WifiManager.SoftApCallback {
private final int mMode;
SoftApCallbackImpl(int mode) {
@@ -309,13 +311,6 @@ public class ActiveModeWarden {
@Override
public void onStateChanged(int state, int reason) {
- if (state == WifiManager.WIFI_AP_STATE_DISABLED) {
- mActiveModeManagers.remove(getActiveModeManager());
- updateBatteryStatsWifiState(false);
- } else if (state == WifiManager.WIFI_AP_STATE_FAILED) {
- mActiveModeManagers.remove(getActiveModeManager());
- updateBatteryStatsWifiState(false);
- }
switch (mMode) {
case WifiManager.IFACE_IP_MODE_TETHERED:
if (mSoftApCallback != null) mSoftApCallback.onStateChanged(state, reason);
@@ -339,6 +334,23 @@ public class ActiveModeWarden {
}
}
+ private class SoftApListener extends ModeCallback implements ActiveModeManager.Listener {
+ @Override
+ public void onStarted() { }
+
+ @Override
+ public void onStopped() {
+ mActiveModeManagers.remove(getActiveModeManager());
+ updateBatteryStatsWifiState(false);
+ }
+
+ @Override
+ public void onStartFailure() {
+ mActiveModeManagers.remove(getActiveModeManager());
+ updateBatteryStatsWifiState(false);
+ }
+ }
+
/**
* Helper method to report wifi state as on/off (doesn't matter which mode).
*
@@ -716,30 +728,38 @@ public class ActiveModeWarden {
}
class StaEnabledState extends ModeActiveState {
- private class ClientListener implements ClientModeManager.Listener {
+ private class ClientListener implements ActiveModeManager.Listener {
@Override
- public void onStateChanged(int state) {
+ public void onStarted() {
// make sure this listener is still active
if (this != mListener) {
- log("Client mode state change from previous manager");
+ log("Client mode callback from previous manager");
return;
}
+ log("client mode active");
+ onModeActivationComplete();
+ }
- log("State changed from client mode. state = " + state);
-
- if (state == WifiManager.WIFI_STATE_UNKNOWN) {
- // error while setting up client mode or an unexpected failure.
- sendMessage(CMD_STA_START_FAILURE, this);
- } else if (state == WifiManager.WIFI_STATE_DISABLED) {
- // client mode stopped
- sendMessage(CMD_STA_STOPPED, this);
- } else if (state == WifiManager.WIFI_STATE_ENABLED) {
- // client mode is ready to go
- log("client mode active");
- onModeActivationComplete();
- } else {
- // only care if client mode stopped or started, dropping
+ @Override
+ public void onStopped() {
+ // make sure this listener is still active
+ if (this != mListener) {
+ log("Client mode callback from previous manager");
+ return;
}
+ log("client mode stopped");
+ sendMessage(CMD_STA_STOPPED, this);
+ }
+
+ @Override
+ public void onStartFailure() {
+ // make sure this listener is still active
+ if (this != mListener) {
+ log("Client mode callback from previous manager");
+ return;
+ }
+ log("client mode failure");
+ sendMessage(CMD_STA_START_FAILURE, this);
}
}
private ClientListener mListener;
@@ -844,29 +864,40 @@ public class ActiveModeWarden {
}
class StaDisabledWithScanState extends ModeActiveState {
- private class ScanOnlyListener implements ScanOnlyModeManager.Listener {
+ private class ScanOnlyListener implements ActiveModeManager.Listener {
@Override
- public void onStateChanged(int state) {
+ public void onStarted() {
+ // make sure this listener is still active
if (this != mListener) {
- log("ScanOnly mode state change from previous manager");
+ log("Scanonly mode callback from previous manager");
return;
}
+ log("Scanonly mode active");
+ onModeActivationComplete();
+ }
- if (state == WifiManager.WIFI_STATE_UNKNOWN) {
- log("StaDisabledWithScanState mode failed");
- // error while setting up scan mode or an unexpected failure.
- sendMessage(CMD_SCANNING_START_FAILURE, this);
- } else if (state == WifiManager.WIFI_STATE_DISABLED) {
- log("StaDisabledWithScanState stopped");
- //scan only mode stopped
- sendMessage(CMD_SCANNING_STOPPED, this);
- } else if (state == WifiManager.WIFI_STATE_ENABLED) {
- // scan mode is ready to go
- log("scan mode active");
- onModeActivationComplete();
- } else {
- log("unexpected state update: " + state);
+ @Override
+ public void onStopped() {
+ // make sure this listener is still active
+ if (this != mListener) {
+ log("Scanonly mode callback from previous manager");
+ return;
+ }
+ // client mode is ready to go
+ log("Scanonly mode stopped");
+ // client mode stopped
+ sendMessage(CMD_SCANNING_STOPPED, this);
+ }
+
+ @Override
+ public void onStartFailure() {
+ // make sure this listener is still active
+ if (this != mListener) {
+ log("Scanonly mode callback from previous manager");
+ return;
}
+ log("Scanonly mode failure");
+ sendMessage(CMD_SCANNING_START_FAILURE, this);
}
}
private ScanOnlyListener mListener;
diff --git a/service/java/com/android/server/wifi/ClientModeManager.java b/service/java/com/android/server/wifi/ClientModeManager.java
index d2fbe1b76..15256602d 100644
--- a/service/java/com/android/server/wifi/ClientModeManager.java
+++ b/service/java/com/android/server/wifi/ClientModeManager.java
@@ -46,19 +46,17 @@ public class ClientModeManager implements ActiveModeManager {
private final WifiNative mWifiNative;
private final WifiMetrics mWifiMetrics;
- private final Listener mListener;
+ private final Listener mModeListener;
private final ClientModeImpl mClientModeImpl;
private String mClientInterfaceName;
private boolean mIfaceIsUp = false;
- private boolean mExpectedStop = false;
-
ClientModeManager(Context context, @NonNull Looper looper, WifiNative wifiNative,
Listener listener, WifiMetrics wifiMetrics, ClientModeImpl clientModeImpl) {
mContext = context;
mWifiNative = wifiNative;
- mListener = listener;
+ mModeListener = listener;
mWifiMetrics = wifiMetrics;
mClientModeImpl = clientModeImpl;
mStateMachine = new ClientModeStateMachine(looper);
@@ -76,7 +74,6 @@ public class ClientModeManager implements ActiveModeManager {
*/
public void stop() {
Log.d(TAG, " currentstate: " + getCurrentStateName());
- mExpectedStop = true;
if (mClientInterfaceName != null) {
if (mIfaceIsUp) {
updateWifiState(WifiManager.WIFI_STATE_DISABLING,
@@ -102,17 +99,7 @@ public class ClientModeManager implements ActiveModeManager {
pw.println("current StateMachine mode: " + getCurrentStateName());
pw.println("mClientInterfaceName: " + mClientInterfaceName);
pw.println("mIfaceIsUp: " + mIfaceIsUp);
- }
-
- /**
- * Listener for ClientMode state changes.
- */
- public interface Listener {
- /**
- * Invoke when wifi state changes.
- * @param state new wifi state
- */
- void onStateChanged(int state);
+ mStateMachine.dump(fd, pw, args);
}
private String getCurrentStateName() {
@@ -131,20 +118,6 @@ public class ClientModeManager implements ActiveModeManager {
* @param currentState current wifi state
*/
private void updateWifiState(int newState, int currentState) {
- if (!mExpectedStop) {
- mListener.onStateChanged(newState);
- } else {
- Log.d(TAG, "expected stop, not triggering callbacks: newState = " + newState);
- }
-
- // Once we report the mode has stopped/failed any other stop signals are redundant
- // note: this can happen in failure modes where we get multiple callbacks as underlying
- // components/interface stops or the underlying interface is destroyed in cleanup
- if (newState == WifiManager.WIFI_STATE_UNKNOWN
- || newState == WifiManager.WIFI_STATE_DISABLED) {
- mExpectedStop = true;
- }
-
if (newState == WifiManager.WIFI_STATE_UNKNOWN) {
// do not need to broadcast failure to system
return;
@@ -233,6 +206,7 @@ public class ClientModeManager implements ActiveModeManager {
WifiManager.WIFI_STATE_ENABLING);
updateWifiState(WifiManager.WIFI_STATE_DISABLED,
WifiManager.WIFI_STATE_UNKNOWN);
+ mModeListener.onStartFailure();
break;
}
transitionTo(mStartedState);
@@ -258,6 +232,7 @@ public class ClientModeManager implements ActiveModeManager {
mClientInterfaceName);
updateWifiState(WifiManager.WIFI_STATE_ENABLED,
WifiManager.WIFI_STATE_ENABLING);
+ mModeListener.onStarted();
} else {
if (mClientModeImpl.isConnectedMacRandomizationEnabled()) {
// Handle the error case where our underlying interface went down if we
@@ -329,6 +304,7 @@ public class ClientModeManager implements ActiveModeManager {
// once we leave started, nothing else to do... stop the state machine
mStateMachine.quitNow();
+ mModeListener.onStopped();
}
}
}
diff --git a/service/java/com/android/server/wifi/ScanOnlyModeManager.java b/service/java/com/android/server/wifi/ScanOnlyModeManager.java
index c3547be5d..460e77d7d 100644
--- a/service/java/com/android/server/wifi/ScanOnlyModeManager.java
+++ b/service/java/com/android/server/wifi/ScanOnlyModeManager.java
@@ -45,13 +45,12 @@ public class ScanOnlyModeManager implements ActiveModeManager {
private final WifiNative mWifiNative;
private final WifiMetrics mWifiMetrics;
- private final Listener mListener;
+ private final Listener mModeListener;
private final WakeupController mWakeupController;
private final SarManager mSarManager;
private String mClientInterfaceName;
private boolean mIfaceIsUp = false;
-
private boolean mExpectedStop = false;
ScanOnlyModeManager(@NonNull Context context, @NonNull Looper looper,
@@ -61,7 +60,7 @@ public class ScanOnlyModeManager implements ActiveModeManager {
@NonNull SarManager sarManager) {
mContext = context;
mWifiNative = wifiNative;
- mListener = listener;
+ mModeListener = listener;
mWifiMetrics = wifiMetrics;
mWakeupController = wakeupController;
mSarManager = sarManager;
@@ -97,17 +96,7 @@ public class ScanOnlyModeManager implements ActiveModeManager {
pw.println("current StateMachine mode: " + getCurrentStateName());
pw.println("mClientInterfaceName: " + mClientInterfaceName);
pw.println("mIfaceIsUp: " + mIfaceIsUp);
- }
-
- /**
- * Listener for ScanOnlyMode state changes.
- */
- public interface Listener {
- /**
- * Invoke when wifi state changes.
- * @param state new wifi state
- */
- void onStateChanged(int state);
+ mStateMachine.dump(fd, pw, args);
}
private String getCurrentStateName() {
@@ -120,26 +109,6 @@ public class ScanOnlyModeManager implements ActiveModeManager {
return "StateMachine not active";
}
- /**
- * Update Wifi state.
- * @param state new Wifi state
- */
- private void updateWifiState(int state) {
- if (mExpectedStop) {
- Log.d(TAG, "expected stop, not triggering callbacks: state = " + state);
- return;
- }
-
- // Once we report the mode has stopped/failed any other stop signals are redundant
- // note: this can happen in failure modes where we get multiple callbacks as underlying
- // components/interface stops or the underlying interface is destroyed in cleanup
- if (state == WifiManager.WIFI_STATE_UNKNOWN || state == WifiManager.WIFI_STATE_DISABLED) {
- mExpectedStop = true;
- }
-
- mListener.onStateChanged(state);
- }
-
private class ScanOnlyModeStateMachine extends StateMachine {
// Commands for the state machine.
public static final int CMD_START = 0;
@@ -199,7 +168,7 @@ public class ScanOnlyModeManager implements ActiveModeManager {
mWifiNativeInterfaceCallback);
if (TextUtils.isEmpty(mClientInterfaceName)) {
Log.e(TAG, "Failed to create ClientInterface. Sit in Idle");
- updateWifiState(WifiManager.WIFI_STATE_UNKNOWN);
+ mModeListener.onStartFailure();
break;
}
transitionTo(mStartedState);
@@ -222,7 +191,7 @@ public class ScanOnlyModeManager implements ActiveModeManager {
if (isUp) {
Log.d(TAG, "Wifi is ready to use for scanning");
mWakeupController.start();
- updateWifiState(WifiManager.WIFI_STATE_ENABLED);
+ mModeListener.onStarted();
} else {
// if the interface goes down we should exit and go back to idle state.
Log.d(TAG, "interface down - stop scan mode");
@@ -256,7 +225,6 @@ public class ScanOnlyModeManager implements ActiveModeManager {
break;
case CMD_INTERFACE_DOWN:
Log.d(TAG, "interface down! stop mode");
- updateWifiState(WifiManager.WIFI_STATE_UNKNOWN);
transitionTo(mIdleState);
break;
default:
@@ -275,11 +243,13 @@ public class ScanOnlyModeManager implements ActiveModeManager {
mWifiNative.teardownInterface(mClientInterfaceName);
mClientInterfaceName = null;
}
- updateWifiState(WifiManager.WIFI_STATE_DISABLED);
mSarManager.setScanOnlyWifiState(WifiManager.WIFI_STATE_DISABLED);
- // once we leave started, nothing else to do... stop the state machine
- mStateMachine.quitNow();
+ if (!mExpectedStop) {
+ // once we leave started, nothing else to do... stop the state machine
+ mStateMachine.quitNow();
+ mModeListener.onStopped();
+ }
}
}
}
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
index b02ec2402..8802b5a71 100644
--- a/service/java/com/android/server/wifi/SoftApManager.java
+++ b/service/java/com/android/server/wifi/SoftApManager.java
@@ -74,7 +74,8 @@ public class SoftApManager implements ActiveModeManager {
private final SoftApStateMachine mStateMachine;
- private final WifiManager.SoftApCallback mCallback;
+ private final Listener mModeListener;
+ private final WifiManager.SoftApCallback mSoftApCallback;
private String mApInterfaceName;
private boolean mIfaceIsUp;
@@ -129,6 +130,7 @@ public class SoftApManager implements ActiveModeManager {
@NonNull FrameworkFacade framework,
@NonNull WifiNative wifiNative,
String countryCode,
+ @NonNull Listener listener,
@NonNull WifiManager.SoftApCallback callback,
@NonNull WifiApConfigStore wifiApConfigStore,
@NonNull SoftApModeConfiguration apConfig,
@@ -139,7 +141,8 @@ public class SoftApManager implements ActiveModeManager {
mFrameworkFacade = framework;
mWifiNative = wifiNative;
mCountryCode = countryCode;
- mCallback = callback;
+ mModeListener = listener;
+ mSoftApCallback = callback;
mWifiApConfigStore = wifiApConfigStore;
mApConfig = apConfig;
if (mApConfig.getWifiConfiguration() == null) {
@@ -204,6 +207,7 @@ public class SoftApManager implements ActiveModeManager {
pw.println("mReportedFrequency: " + mReportedFrequency);
pw.println("mReportedBandwidth: " + mReportedBandwidth);
pw.println("mStartTimestamp: " + mStartTimestamp);
+ mStateMachine.dump(fd, pw, args);
}
private String getCurrentStateName() {
@@ -223,7 +227,7 @@ public class SoftApManager implements ActiveModeManager {
* @param reason Failure reason if the new AP state is in failure state
*/
private void updateApState(int newState, int currentState, int reason) {
- mCallback.onStateChanged(newState, reason);
+ mSoftApCallback.onStateChanged(newState, reason);
//send the AP state change broadcast
final Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
@@ -390,6 +394,7 @@ public class SoftApManager implements ActiveModeManager {
WifiManager.SAP_START_FAILURE_GENERAL);
mWifiMetrics.incrementSoftApStartResult(
false, WifiManager.SAP_START_FAILURE_GENERAL);
+ mModeListener.onStartFailure();
break;
}
updateApState(WifiManager.WIFI_AP_STATE_ENABLING,
@@ -405,6 +410,7 @@ public class SoftApManager implements ActiveModeManager {
failureReason);
stopSoftAp();
mWifiMetrics.incrementSoftApStartResult(false, failureReason);
+ mModeListener.onStartFailure();
break;
}
transitionTo(mStartedState);
@@ -491,8 +497,8 @@ public class SoftApManager implements ActiveModeManager {
mNumAssociatedStations = numStations;
Log.d(TAG, "Number of associated stations changed: " + mNumAssociatedStations);
- if (mCallback != null) {
- mCallback.onNumClientsChanged(mNumAssociatedStations);
+ if (mSoftApCallback != null) {
+ mSoftApCallback.onNumClientsChanged(mNumAssociatedStations);
} else {
Log.e(TAG, "SoftApCallback is null. Dropping NumClientsChanged event.");
}
@@ -515,9 +521,10 @@ public class SoftApManager implements ActiveModeManager {
Log.d(TAG, "SoftAp is ready for use");
updateApState(WifiManager.WIFI_AP_STATE_ENABLED,
WifiManager.WIFI_AP_STATE_ENABLING, 0);
+ mModeListener.onStarted();
mWifiMetrics.incrementSoftApStartResult(true, 0);
- if (mCallback != null) {
- mCallback.onNumClientsChanged(mNumAssociatedStations);
+ if (mSoftApCallback != null) {
+ mSoftApCallback.onNumClientsChanged(mNumAssociatedStations);
}
} else {
// the interface was up, but goes down
@@ -573,6 +580,7 @@ public class SoftApManager implements ActiveModeManager {
mIfaceIsUp = false;
mIfaceIsDestroyed = false;
mStateMachine.quitNow();
+ mModeListener.onStopped();
}
private void updateUserBandPreferenceViolationMetricsIfNeeded() {
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index f6ab91acf..3ac6286fa 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -516,10 +516,11 @@ public class WifiInjector {
* @param config SoftApModeConfiguration object holding the config and mode
* @return an instance of SoftApManager
*/
- public SoftApManager makeSoftApManager(@NonNull WifiManager.SoftApCallback callback,
+ public SoftApManager makeSoftApManager(@NonNull ActiveModeManager.Listener listener,
+ @NonNull WifiManager.SoftApCallback callback,
@NonNull SoftApModeConfiguration config) {
return new SoftApManager(mContext, mWifiHandlerThread.getLooper(),
- mFrameworkFacade, mWifiNative, mCountryCode.getCountryCode(), callback,
+ mFrameworkFacade, mWifiNative, mCountryCode.getCountryCode(), listener, callback,
mWifiApConfigStore, config, mWifiMetrics, mSarManager, mWifiDiagnostics);
}