summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-10-27 02:32:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-10-27 02:32:34 +0000
commit3361c92f40a4ebbe7ce4f83664f37cfd00011bbf (patch)
tree4d75fed4c62a281e0ebef6ca306138b3cbd14077 /service
parentf2ee75ec451962dd7e8902aeda05f9208b5a992f (diff)
parentbda99994b4efd25d0b59af53ee10cceedc2b061c (diff)
Merge changes I3b31a5e2,I292ccafe
* changes: ActiveModeWarden: Remove redundant SoftApCallback ActiveModeWarden: Add roles for each mode manager
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ActiveModeManager.java61
-rw-r--r--service/java/com/android/server/wifi/ActiveModeWarden.java151
-rw-r--r--service/java/com/android/server/wifi/ClientModeManager.java73
-rw-r--r--service/java/com/android/server/wifi/DefaultModeManager.java19
-rw-r--r--service/java/com/android/server/wifi/SoftApManager.java21
5 files changed, 188 insertions, 137 deletions
diff --git a/service/java/com/android/server/wifi/ActiveModeManager.java b/service/java/com/android/server/wifi/ActiveModeManager.java
index 0908e26eb..aa0bf9f6b 100644
--- a/service/java/com/android/server/wifi/ActiveModeManager.java
+++ b/service/java/com/android/server/wifi/ActiveModeManager.java
@@ -22,6 +22,8 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Arrays;
+import java.util.List;
/**
* Base class for available WiFi operating modes.
@@ -57,20 +59,61 @@ public interface ActiveModeManager {
*/
void stop();
+ /** Roles assigned to each mode manager. */
+ int ROLE_UNSPECIFIED = -1;
+ // SoftApManager - Tethering, will respond to public APIs.
+ int ROLE_SOFTAP_TETHERED = 0;
+ // SoftApManager - Local only hotspot.
+ int ROLE_SOFTAP_LOCAL_ONLY = 1;
+ // ClientModeManager, primary STA, will respond to public APIs
+ int ROLE_CLIENT_PRIMARY = 2;
+ // ClientModeManager, secondary STA, can switch to primary later.
+ int ROLE_CLIENT_SECONDARY = 3;
+ // ClientModeManager, secondary STA created for local connection (no internet connectivity).
+ int ROLE_CLIENT_LOCAL_ONLY = 4;
+ // ClientModeManager, STA created for scans only.
+ int ROLE_CLIENT_SCAN_ONLY = 5;
- /** Scan Modes */
- int SCAN_NONE = 0;
- int SCAN_WITHOUT_HIDDEN_NETWORKS = 1;
- int SCAN_WITH_HIDDEN_NETWORKS = 2;
-
- @IntDef({SCAN_NONE, SCAN_WITHOUT_HIDDEN_NETWORKS, SCAN_WITH_HIDDEN_NETWORKS})
+ @IntDef(prefix = { "ROLE_" }, value = {
+ ROLE_SOFTAP_TETHERED,
+ ROLE_SOFTAP_LOCAL_ONLY,
+ ROLE_CLIENT_PRIMARY,
+ ROLE_CLIENT_SECONDARY,
+ ROLE_CLIENT_LOCAL_ONLY,
+ ROLE_CLIENT_SCAN_ONLY
+ })
@Retention(RetentionPolicy.SOURCE)
- @interface ScanMode{}
+ @interface Role{}
+
+ /** List of Client roles */
+ List<Integer> CLIENT_ROLES = Arrays.asList(
+ ROLE_CLIENT_PRIMARY,
+ ROLE_CLIENT_SECONDARY,
+ ROLE_CLIENT_LOCAL_ONLY,
+ ROLE_CLIENT_SCAN_ONLY);
+ /** List of Client roles that could initiate a wifi connection */
+ List<Integer> CLIENT_CONNECTIVITY_ROLES = Arrays.asList(
+ ROLE_CLIENT_PRIMARY,
+ ROLE_CLIENT_SECONDARY,
+ ROLE_CLIENT_LOCAL_ONLY);
+ /** List of Client roles that could initiate a wifi connection for internet connectivity */
+ List<Integer> CLIENT_INTERNET_CONNECTIVITY_ROLES = Arrays.asList(
+ ROLE_CLIENT_PRIMARY,
+ ROLE_CLIENT_SECONDARY);
+ /** List of SoftAp roles */
+ List<Integer> SOFTAP_ROLES = Arrays.asList(
+ ROLE_SOFTAP_LOCAL_ONLY,
+ ROLE_SOFTAP_TETHERED);
+
+ /**
+ * Method to get the role for a mode manager.
+ */
+ @Role int getRole();
/**
- * Method to get the scan mode for a given Wifi operation mode.
+ * Method to set the role for a mode manager.
*/
- @ScanMode int getScanMode();
+ void setRole(@Role int role);
/**
* Method to dump for logging state.
diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java
index 3253b962a..679b62dd4 100644
--- a/service/java/com/android/server/wifi/ActiveModeWarden.java
+++ b/service/java/com/android/server/wifi/ActiveModeWarden.java
@@ -16,13 +16,15 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY;
+import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
+
import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
-import android.net.wifi.WifiClient;
import android.net.wifi.WifiManager;
import android.os.BatteryStats;
import android.os.BatteryStatsManager;
@@ -190,28 +192,59 @@ public class ActiveModeWarden {
return !mActiveModeManagers.isEmpty();
}
- private boolean hasAnyClientModeManager() {
+ /**
+ * @return true if any mode managers in specified role.
+ */
+ private boolean hasAnyModeManagerInRole(@ActiveModeManager.Role int role) {
for (ActiveModeManager manager : mActiveModeManagers) {
- if (manager instanceof ClientModeManager) return true;
+ if (manager.getRole() == role) return true;
}
return false;
}
/**
- * @return true if all client mode managers are in scan mode,
- * false if there are no client mode managers present or if any of them are not in scan mode.
+ * @return true if any mode managers in one of the specified roles.
*/
- private boolean areAllClientModeManagersInScanMode() {
+ private boolean hasAnyModeManagerInOneOfRoles(List<Integer> rolesList) {
+ for (ActiveModeManager manager : mActiveModeManagers) {
+ if (rolesList.contains(manager.getRole())) return true;
+ }
+ return false;
+ }
+
+ private boolean hasAnyClientModeManager() {
+ return hasAnyModeManagerInOneOfRoles(ActiveModeManager.CLIENT_ROLES);
+ }
+
+ private boolean hasAnyClientModeManagerInConnectivityRole() {
+ return hasAnyModeManagerInOneOfRoles(ActiveModeManager.CLIENT_CONNECTIVITY_ROLES);
+ }
+
+ private boolean hasAnySoftApManager() {
+ return hasAnyModeManagerInOneOfRoles(ActiveModeManager.SOFTAP_ROLES);
+ }
+
+ /**
+ * @return true if all the client mode managers are in scan only role,
+ * false if there are no client mode managers present or if any of them are not in scan only
+ * role.
+ */
+ private boolean areAllClientModeManagersInScanOnlyRole() {
boolean hasAnyClientModeManager = false;
for (ActiveModeManager manager : mActiveModeManagers) {
- if (!(manager instanceof ClientModeManager)) continue;
- ClientModeManager clientModeManager = (ClientModeManager) manager;
- hasAnyClientModeManager = true;
- if (!clientModeManager.isInScanOnlyMode()) return false;
+ if (ActiveModeManager.CLIENT_ROLES.contains(manager.getRole())) {
+ hasAnyClientModeManager = true;
+ if (manager.getRole() != ActiveModeManager.ROLE_CLIENT_SCAN_ONLY) return false;
+ }
}
return hasAnyClientModeManager;
}
+ private @ActiveModeManager.Role int getRoleForSoftApIpMode(int ipMode) {
+ return ipMode == IFACE_IP_MODE_TETHERED
+ ? ActiveModeManager.ROLE_SOFTAP_TETHERED : ActiveModeManager.ROLE_SOFTAP_LOCAL_ONLY;
+ }
+
/**
* Method to enable soft ap for wifi hotspot.
*
@@ -224,13 +257,18 @@ public class ActiveModeWarden {
private void startSoftApModeManager(@NonNull SoftApModeConfiguration softApConfig) {
Log.d(TAG, "Starting SoftApModeManager config = "
+ softApConfig.getWifiConfiguration());
+ Preconditions.checkState(softApConfig.getTargetMode() == IFACE_IP_MODE_LOCAL_ONLY
+ || softApConfig.getTargetMode() == IFACE_IP_MODE_TETHERED);
- SoftApCallbackImpl callback = new SoftApCallbackImpl(softApConfig.getTargetMode());
+ WifiManager.SoftApCallback callback =
+ softApConfig.getTargetMode() == IFACE_IP_MODE_LOCAL_ONLY
+ ? mLohsCallback : mSoftApCallback;
SoftApListener listener = new SoftApListener();
ActiveModeManager manager =
mWifiInjector.makeSoftApManager(listener, callback, softApConfig);
listener.setActiveModeManager(manager);
manager.start();
+ manager.setRole(getRoleForSoftApIpMode(softApConfig.getTargetMode()));
mActiveModeManagers.add(manager);
}
@@ -239,22 +277,21 @@ public class ActiveModeWarden {
*
* This method will stop any active softAp mode managers.
*
- * @param mode the operating mode of APs to bring down (ex,
+ * @param ipMode the operating mode of APs to bring down (ex,
* {@link WifiManager#IFACE_IP_MODE_TETHERED} or
* {@link WifiManager#IFACE_IP_MODE_LOCAL_ONLY}).
* Use {@link WifiManager#IFACE_IP_MODE_UNSPECIFIED} to stop all APs.
*/
- private void stopSoftApModeManagers(int mode) {
- Log.d(TAG, "Shutting down all softap mode managers in mode " + mode);
+ private void stopSoftApModeManagers(int ipMode) {
+ Log.d(TAG, "Shutting down all softap mode managers in mode " + ipMode);
for (ActiveModeManager manager : mActiveModeManagers) {
if (!(manager instanceof SoftApManager)) continue;
SoftApManager softApManager = (SoftApManager) manager;
- if (mode != WifiManager.IFACE_IP_MODE_UNSPECIFIED
- && mode != softApManager.getIpMode()) {
- continue;
+ if (ipMode == WifiManager.IFACE_IP_MODE_UNSPECIFIED
+ || getRoleForSoftApIpMode(ipMode) == softApManager.getRole()) {
+ softApManager.stop();
}
- softApManager.stop();
}
}
@@ -267,7 +304,7 @@ public class ActiveModeWarden {
ClientModeManager manager = mWifiInjector.makeClientModeManager(listener);
listener.setActiveModeManager(manager);
manager.start();
- if (!switchClientMode(manager)) {
+ if (!switchClientModeManagerRole(manager)) {
return false;
}
mActiveModeManagers.add(manager);
@@ -295,7 +332,7 @@ public class ActiveModeWarden {
for (ActiveModeManager manager : mActiveModeManagers) {
if (!(manager instanceof ClientModeManager)) continue;
ClientModeManager clientModeManager = (ClientModeManager) manager;
- if (!switchClientMode(clientModeManager)) {
+ if (!switchClientModeManagerRole(clientModeManager)) {
return false;
}
}
@@ -307,11 +344,11 @@ public class ActiveModeWarden {
* Method to switch a client mode manager mode of operation (from ScanOnly To Connect &
* vice-versa) based on the toggle state.
*/
- private boolean switchClientMode(@NonNull ClientModeManager modeManager) {
+ private boolean switchClientModeManagerRole(@NonNull ClientModeManager modeManager) {
if (mSettingsStore.isWifiToggleEnabled()) {
- modeManager.switchToConnectMode();
+ modeManager.setRole(ActiveModeManager.ROLE_CLIENT_PRIMARY);
} else if (checkScanOnlyModeAvailable()) {
- modeManager.switchToScanOnlyMode();
+ modeManager.setRole(ActiveModeManager.ROLE_CLIENT_SCAN_ONLY);
} else {
Log.e(TAG, "Something is wrong, no client mode toggles enabled");
return false;
@@ -338,10 +375,10 @@ public class ActiveModeWarden {
pw.println("Dump of " + TAG);
pw.println("Current wifi mode: " + getCurrentMode());
pw.println("NumActiveModeManagers: " + mActiveModeManagers.size());
+ mWifiController.dump(fd, pw, args);
for (ActiveModeManager manager : mActiveModeManagers) {
manager.dump(fd, pw, args);
}
- mWifiController.dump(fd, pw, args);
}
@VisibleForTesting
@@ -376,47 +413,9 @@ public class ActiveModeWarden {
}
}
- private class SoftApCallbackImpl implements WifiManager.SoftApCallback {
- private final int mMode;
-
- SoftApCallbackImpl(int mode) {
- Preconditions.checkArgument(mode == WifiManager.IFACE_IP_MODE_TETHERED
- || mode == WifiManager.IFACE_IP_MODE_LOCAL_ONLY);
- mMode = mode;
- }
-
- @Override
- public void onStateChanged(int state, int reason) {
- switch (mMode) {
- case WifiManager.IFACE_IP_MODE_TETHERED:
- if (mSoftApCallback != null) mSoftApCallback.onStateChanged(state, reason);
- break;
- case WifiManager.IFACE_IP_MODE_LOCAL_ONLY:
- if (mLohsCallback != null) mLohsCallback.onStateChanged(state, reason);
- break;
- }
- }
-
- @Override
- public void onConnectedClientsChanged(List<WifiClient> clients) {
- switch (mMode) {
- case WifiManager.IFACE_IP_MODE_TETHERED:
- if (mSoftApCallback != null) {
- mSoftApCallback.onConnectedClientsChanged(clients);
- }
- break;
- case WifiManager.IFACE_IP_MODE_LOCAL_ONLY:
- if (mLohsCallback != null) {
- mLohsCallback.onConnectedClientsChanged(clients);
- }
- break;
- }
- }
- }
-
private void updateBatteryStats() {
updateBatteryStatsWifiState(hasAnyModeManager());
- if (areAllClientModeManagersInScanMode()) {
+ if (areAllClientModeManagersInScanOnlyRole()) {
updateBatteryStatsScanModeActive();
}
}
@@ -445,14 +444,14 @@ public class ActiveModeWarden {
private class ClientListener extends ModeCallback implements ActiveModeManager.Listener {
@Override
public void onStarted() {
- updateScanMode();
+ updateClientScanMode();
updateBatteryStats();
}
@Override
public void onStopped() {
mActiveModeManagers.remove(getActiveModeManager());
- updateScanMode();
+ updateClientScanMode();
updateBatteryStats();
mWifiController.sendMessage(WifiController.CMD_STA_STOPPED);
}
@@ -460,30 +459,16 @@ public class ActiveModeWarden {
@Override
public void onStartFailure() {
mActiveModeManagers.remove(getActiveModeManager());
- updateScanMode();
+ updateClientScanMode();
updateBatteryStats();
mWifiController.sendMessage(WifiController.CMD_STA_START_FAILURE);
}
}
// Update the scan state based on all active mode managers.
- private void updateScanMode() {
- boolean scanEnabled = false;
- boolean scanningForHiddenNetworksEnabled = false;
- for (ActiveModeManager modeManager : mActiveModeManagers) {
- @ActiveModeManager.ScanMode int scanState = modeManager.getScanMode();
- switch (scanState) {
- case ActiveModeManager.SCAN_NONE:
- break;
- case ActiveModeManager.SCAN_WITHOUT_HIDDEN_NETWORKS:
- scanEnabled = true;
- break;
- case ActiveModeManager.SCAN_WITH_HIDDEN_NETWORKS:
- scanEnabled = true;
- scanningForHiddenNetworksEnabled = true;
- break;
- }
- }
+ private void updateClientScanMode() {
+ boolean scanEnabled = hasAnyClientModeManager();
+ boolean scanningForHiddenNetworksEnabled = hasAnyClientModeManagerInConnectivityRole();
mScanRequestProxy.enableScanning(scanEnabled, scanningForHiddenNetworksEnabled);
}
diff --git a/service/java/com/android/server/wifi/ClientModeManager.java b/service/java/com/android/server/wifi/ClientModeManager.java
index 020664684..f1e91af2f 100644
--- a/service/java/com/android/server/wifi/ClientModeManager.java
+++ b/service/java/com/android/server/wifi/ClientModeManager.java
@@ -27,6 +27,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.internal.util.IState;
+import com.android.internal.util.Preconditions;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.server.wifi.WifiNative.InterfaceCallback;
@@ -52,6 +53,7 @@ public class ClientModeManager implements ActiveModeManager {
private String mClientInterfaceName;
private boolean mIfaceIsUp = false;
+ private @Role int mRole = ROLE_UNSPECIFIED;
ClientModeManager(Context context, @NonNull Looper looper, WifiNative wifiNative,
Listener listener, WifiMetrics wifiMetrics, SarManager sarManager,
@@ -69,6 +71,7 @@ public class ClientModeManager implements ActiveModeManager {
/**
* Start client mode.
*/
+ @Override
public void start() {
mStateMachine.sendMessage(ClientModeStateMachine.CMD_START);
}
@@ -76,51 +79,45 @@ public class ClientModeManager implements ActiveModeManager {
/**
* Disconnect from any currently connected networks and stop client mode.
*/
+ @Override
public void stop() {
Log.d(TAG, " currentstate: " + getCurrentStateName());
- if (isInConnectMode()) {
- if (mIfaceIsUp) {
- updateConnectModeState(WifiManager.WIFI_STATE_DISABLING,
- WifiManager.WIFI_STATE_ENABLED);
- } else {
- updateConnectModeState(WifiManager.WIFI_STATE_DISABLING,
- WifiManager.WIFI_STATE_ENABLING);
- }
- }
- mStateMachine.quitNow();
- }
-
- public @ScanMode int getScanMode() {
- if (isInConnectMode()) {
- return SCAN_WITH_HIDDEN_NETWORKS;
- } else if (isInScanOnlyMode()) {
- return SCAN_WITHOUT_HIDDEN_NETWORKS;
+ if (mIfaceIsUp) {
+ updateConnectModeState(WifiManager.WIFI_STATE_DISABLING,
+ WifiManager.WIFI_STATE_ENABLED);
} else {
- return SCAN_NONE;
+ updateConnectModeState(WifiManager.WIFI_STATE_DISABLING,
+ WifiManager.WIFI_STATE_ENABLING);
}
+ mStateMachine.quitNow();
}
- /**
- * Switch client mode manager to scan only mode.
- */
- public void switchToScanOnlyMode() {
- mStateMachine.sendMessage(ClientModeStateMachine.CMD_SWITCH_TO_SCAN_ONLY_MODE);
+ @Override
+ public @Role int getRole() {
+ return mRole;
}
- /**
- * Switch client mode manager to connect mode.
- */
- public void switchToConnectMode() {
- mStateMachine.sendMessage(ClientModeStateMachine.CMD_SWITCH_TO_CONNECT_MODE);
+ @Override
+ public void setRole(@Role int role) {
+ Preconditions.checkState(CLIENT_ROLES.contains(role));
+ if (role == ROLE_CLIENT_SCAN_ONLY) {
+ // Switch client mode manager to scan only mode.
+ mStateMachine.sendMessage(ClientModeStateMachine.CMD_SWITCH_TO_SCAN_ONLY_MODE);
+ } else if (CLIENT_CONNECTIVITY_ROLES.contains(role)) {
+ // Switch client mode manager to connect mode.
+ mStateMachine.sendMessage(ClientModeStateMachine.CMD_SWITCH_TO_CONNECT_MODE, role);
+ }
}
/**
* Dump info about this ClientMode manager.
*/
+ @Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("--Dump of ClientModeManager--");
pw.println("current StateMachine mode: " + getCurrentStateName());
+ pw.println("mRole: " + mRole);
pw.println("mClientInterfaceName: " + mClientInterfaceName);
pw.println("mIfaceIsUp: " + mIfaceIsUp);
mStateMachine.dump(fd, pw, args);
@@ -146,6 +143,10 @@ public class ClientModeManager implements ActiveModeManager {
// do not need to broadcast failure to system
return;
}
+ if (mRole != ROLE_CLIENT_PRIMARY) {
+ // do not raise public broadcast unless this is the primary client mode manager
+ return;
+ }
mClientModeImpl.setWifiStateForApiCalls(newState);
@@ -156,14 +157,6 @@ public class ClientModeManager implements ActiveModeManager {
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
}
- public boolean isInConnectMode() {
- return mStateMachine.getCurrentState() == mStateMachine.mConnectModeState;
- }
-
- public boolean isInScanOnlyMode() {
- return mStateMachine.getCurrentState() == mStateMachine.mScanOnlyModeState;
- }
-
private class ClientModeStateMachine extends StateMachine {
// Commands for the state machine.
public static final int CMD_START = 0;
@@ -280,6 +273,7 @@ public class ClientModeManager implements ActiveModeManager {
// Already started, ignore this command.
break;
case CMD_SWITCH_TO_CONNECT_MODE:
+ mRole = message.arg1; // could be any one of possible connect mode roles.
updateConnectModeState(WifiManager.WIFI_STATE_ENABLING,
WifiManager.WIFI_STATE_DISABLED);
if (!mWifiNative.switchClientInterfaceToConnectivityMode(
@@ -294,12 +288,12 @@ public class ClientModeManager implements ActiveModeManager {
transitionTo(mConnectModeState);
break;
case CMD_SWITCH_TO_SCAN_ONLY_MODE:
+ updateConnectModeState(WifiManager.WIFI_STATE_DISABLING,
+ WifiManager.WIFI_STATE_ENABLED);
if (!mWifiNative.switchClientInterfaceToScanMode(mClientInterfaceName)) {
mModeListener.onStartFailure();
break;
}
- updateConnectModeState(WifiManager.WIFI_STATE_DISABLING,
- WifiManager.WIFI_STATE_ENABLED);
transitionTo(mScanOnlyModeState);
break;
case CMD_INTERFACE_DOWN:
@@ -337,6 +331,7 @@ public class ClientModeManager implements ActiveModeManager {
}
// once we leave started, nothing else to do... stop the state machine
+ mRole = ROLE_UNSPECIFIED;
mStateMachine.quitNow();
mModeListener.onStopped();
}
@@ -349,6 +344,7 @@ public class ClientModeManager implements ActiveModeManager {
mClientModeImpl.setOperationalMode(ClientModeImpl.SCAN_ONLY_MODE,
mClientInterfaceName);
mModeListener.onStarted();
+ mRole = ROLE_CLIENT_SCAN_ONLY;
// Inform sar manager that scan only is being enabled
mSarManager.setScanOnlyWifiState(WifiManager.WIFI_STATE_ENABLED);
@@ -393,6 +389,7 @@ public class ClientModeManager implements ActiveModeManager {
public boolean processMessage(Message message) {
switch (message.what) {
case CMD_SWITCH_TO_CONNECT_MODE:
+ mRole = message.arg1;
// Already in connect mode, ignore this command.
break;
case CMD_SWITCH_TO_SCAN_ONLY_MODE:
diff --git a/service/java/com/android/server/wifi/DefaultModeManager.java b/service/java/com/android/server/wifi/DefaultModeManager.java
index 88d657b14..cda4978b8 100644
--- a/service/java/com/android/server/wifi/DefaultModeManager.java
+++ b/service/java/com/android/server/wifi/DefaultModeManager.java
@@ -18,6 +18,8 @@ package com.android.server.wifi;
import android.content.Context;
+import com.android.internal.util.Preconditions;
+
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -34,18 +36,29 @@ public class DefaultModeManager implements ActiveModeManager {
/**
* Start is not used in default mode.
*/
+ @Override
public void start() { };
/**
* Stop is not used in default mode.
*/
+ @Override
public void stop() { };
/**
- * Scanning is disabled in default mode.
+ * No role specified in default mode.
+ */
+ @Override
+ public @Role int getRole() {
+ return ROLE_UNSPECIFIED;
+ }
+
+ /**
+ * No role specified in default mode.
*/
- public @ScanMode int getScanMode() {
- return SCAN_NONE;
+ @Override
+ public void setRole(@Role int role) {
+ Preconditions.checkState(role == ROLE_UNSPECIFIED);
}
/**
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
index 1f6a5fcc6..a89f4334e 100644
--- a/service/java/com/android/server/wifi/SoftApManager.java
+++ b/service/java/com/android/server/wifi/SoftApManager.java
@@ -41,6 +41,7 @@ import android.util.Log;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IState;
+import com.android.internal.util.Preconditions;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.internal.util.WakeupMessage;
@@ -107,6 +108,8 @@ public class SoftApManager implements ActiveModeManager {
private BaseWifiDiagnostics mWifiDiagnostics;
+ private @Role int mRole = ROLE_UNSPECIFIED;
+
/**
* Listener for soft AP events.
*/
@@ -163,6 +166,7 @@ public class SoftApManager implements ActiveModeManager {
/**
* Start soft AP, as configured in the constructor.
*/
+ @Override
public void start() {
mStateMachine.sendMessage(SoftApStateMachine.CMD_START);
}
@@ -170,6 +174,7 @@ public class SoftApManager implements ActiveModeManager {
/**
* Stop soft AP.
*/
+ @Override
public void stop() {
Log.d(TAG, " currentstate: " + getCurrentStateName());
if (mApInterfaceName != null) {
@@ -184,21 +189,28 @@ public class SoftApManager implements ActiveModeManager {
mStateMachine.quitNow();
}
- public @ScanMode int getScanMode() {
- return SCAN_NONE;
+ @Override
+ public @Role int getRole() {
+ return mRole;
}
- public int getIpMode() {
- return mApConfig.getTargetMode();
+ @Override
+ public void setRole(@Role int role) {
+ // softap does not allow in-place switching of roles.
+ Preconditions.checkState(mRole == ROLE_UNSPECIFIED);
+ Preconditions.checkState(SOFTAP_ROLES.contains(role));
+ mRole = role;
}
/**
* Dump info about this softap manager.
*/
+ @Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("--Dump of SoftApManager--");
pw.println("current StateMachine mode: " + getCurrentStateName());
+ pw.println("mRole: " + mRole);
pw.println("mApInterfaceName: " + mApInterfaceName);
pw.println("mIfaceIsUp: " + mIfaceIsUp);
pw.println("mSoftApCountryCode: " + mCountryCode);
@@ -643,6 +655,7 @@ public class SoftApManager implements ActiveModeManager {
mApInterfaceName = null;
mIfaceIsUp = false;
mIfaceIsDestroyed = false;
+ mRole = ROLE_UNSPECIFIED;
mStateMachine.quitNow();
mModeListener.onStopped();
}