diff options
author | James Mattis <jmattis@google.com> | 2019-10-04 18:19:07 -0700 |
---|---|---|
committer | James Mattis <jmattis@google.com> | 2019-10-24 17:11:44 -0700 |
commit | b1a1f59a259f79574e33b2cbd1d47a5573244858 (patch) | |
tree | c678e7ef4dc0b76242989afe7b854cd843e69ee6 /service | |
parent | 2d22d21a2bf52b552880742ecb1fa50d734beff1 (diff) |
Support for hotspot client visibility.
Adding support for visibility into clients that connect to an active hotspot.
Bug: 137309578
Test: atest FrameworksWifiTests:com.android.server.wifi.ActiveModeWardenTest
atest FrameworksWifiTests:com.android.server.wifi.SoftApManagerTest
atest FrameworksWifiTests:com.android.server.wifi.WifiServiceImplTest
atest FrameworksWifiTests:com.android.server.wifi.WificondControlTest
Change-Id: Ifab5be1c969106916412617043074c7b5bc9a2d1
Diffstat (limited to 'service')
5 files changed, 106 insertions, 55 deletions
diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java index 315ae5f0a..818c410ae 100644 --- a/service/java/com/android/server/wifi/ActiveModeWarden.java +++ b/service/java/com/android/server/wifi/ActiveModeWarden.java @@ -22,6 +22,7 @@ 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.Handler; @@ -44,6 +45,7 @@ import com.android.server.wifi.util.WifiPermissionsUtil; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.Collection; +import java.util.List; /** * This class provides the implementation for different WiFi operating modes. @@ -397,13 +399,17 @@ public class ActiveModeWarden { } @Override - public void onNumClientsChanged(int numClients) { + public void onConnectedClientsChanged(List<WifiClient> clients) { switch (mMode) { case WifiManager.IFACE_IP_MODE_TETHERED: - if (mSoftApCallback != null) mSoftApCallback.onNumClientsChanged(numClients); + if (mSoftApCallback != null) { + mSoftApCallback.onConnectedClientsChanged(clients); + } break; case WifiManager.IFACE_IP_MODE_LOCAL_ONLY: - if (mLohsCallback != null) mLohsCallback.onNumClientsChanged(numClients); + if (mLohsCallback != null) { + mLohsCallback.onConnectedClientsChanged(clients); + } break; } } diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 3c4a6797c..1f6a5fcc6 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.database.ContentObserver; import android.net.MacAddress; import android.net.wifi.ScanResult; +import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Handler; @@ -46,11 +47,14 @@ import com.android.internal.util.WakeupMessage; import com.android.server.wifi.WifiNative.InterfaceCallback; import com.android.server.wifi.WifiNative.SoftApListener; import com.android.server.wifi.util.ApConfigUtil; +import com.android.server.wifi.wificond.NativeWifiClient; import java.io.FileDescriptor; import java.io.PrintWriter; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Locale; /** @@ -92,7 +96,7 @@ public class SoftApManager implements ActiveModeManager { private int mReportedFrequency = -1; private int mReportedBandwidth = -1; - private int mNumAssociatedStations = 0; + private List<WifiClient> mConnectedClients = new ArrayList<>(); private boolean mTimeoutEnabled = false; private final SarManager mSarManager; @@ -114,9 +118,9 @@ public class SoftApManager implements ActiveModeManager { } @Override - public void onNumAssociatedStationsChanged(int numStations) { - mStateMachine.sendMessage( - SoftApStateMachine.CMD_NUM_ASSOCIATED_STATIONS_CHANGED, numStations); + public void onConnectedClientsChanged(List<NativeWifiClient> clients) { + mStateMachine.sendMessage(SoftApStateMachine.CMD_ASSOCIATED_STATIONS_CHANGED, + clients); } @Override @@ -203,7 +207,7 @@ public class SoftApManager implements ActiveModeManager { pw.println("mApConfig.wifiConfiguration.SSID: " + wifiConfig.SSID); pw.println("mApConfig.wifiConfiguration.apBand: " + wifiConfig.apBand); pw.println("mApConfig.wifiConfiguration.hiddenSSID: " + wifiConfig.hiddenSSID); - pw.println("mNumAssociatedStations: " + mNumAssociatedStations); + pw.println("mConnectedClients.size(): " + mConnectedClients.size()); pw.println("mTimeoutEnabled: " + mTimeoutEnabled); pw.println("mReportedFrequency: " + mReportedFrequency); pw.println("mReportedBandwidth: " + mReportedBandwidth); @@ -223,9 +227,10 @@ public class SoftApManager implements ActiveModeManager { /** * Update AP state. - * @param newState new AP state + * + * @param newState new AP state * @param currentState current AP state - * @param reason Failure reason if the new AP state is in failure state + * @param reason Failure reason if the new AP state is in failure state */ private void updateApState(int newState, int currentState, int reason) { mSoftApCallback.onStateChanged(newState, reason); @@ -363,7 +368,7 @@ public class SoftApManager implements ActiveModeManager { public static final int CMD_START = 0; public static final int CMD_FAILURE = 2; public static final int CMD_INTERFACE_STATUS_CHANGED = 3; - public static final int CMD_NUM_ASSOCIATED_STATIONS_CHANGED = 4; + public static final int CMD_ASSOCIATED_STATIONS_CHANGED = 4; public static final int CMD_NO_ASSOCIATED_STATIONS_TIMEOUT = 5; public static final int CMD_TIMEOUT_TOGGLE_CHANGED = 6; public static final int CMD_INTERFACE_DESTROYED = 7; @@ -439,8 +444,8 @@ public class SoftApManager implements ActiveModeManager { failureReason = WifiManager.SAP_START_FAILURE_NO_CHANNEL; } updateApState(WifiManager.WIFI_AP_STATE_FAILED, - WifiManager.WIFI_AP_STATE_ENABLING, - failureReason); + WifiManager.WIFI_AP_STATE_ENABLING, + failureReason); stopSoftAp(); mWifiMetrics.incrementSoftApStartResult(false, failureReason); mModeListener.onStartFailure(); @@ -463,8 +468,8 @@ public class SoftApManager implements ActiveModeManager { private SoftApTimeoutEnabledSettingObserver mSettingObserver; /** - * Observer for timeout settings changes. - */ + * Observer for timeout settings changes. + */ private class SoftApTimeoutEnabledSettingObserver extends ContentObserver { SoftApTimeoutEnabledSettingObserver(Handler handler) { super(handler); @@ -520,35 +525,61 @@ public class SoftApManager implements ActiveModeManager { } /** - * Set number of stations associated with this soft AP - * @param numStations Number of connected stations + * Set stations associated with this soft AP + * @param clients The connected stations */ - private void setNumAssociatedStations(int numStations) { - if (mNumAssociatedStations == numStations) { + private void setConnectedClients(List<NativeWifiClient> clients) { + if (clients == null) { + return; + } + + List<WifiClient> convertedClients = createWifiClients(clients); + if (mConnectedClients.equals(convertedClients)) { return; } - mNumAssociatedStations = numStations; - Log.d(TAG, "Number of associated stations changed: " + mNumAssociatedStations); + + mConnectedClients = new ArrayList<>(convertedClients); + Log.d(TAG, "The connected wifi stations have changed with count: " + + clients.size()); if (mSoftApCallback != null) { - mSoftApCallback.onNumClientsChanged(mNumAssociatedStations); + mSoftApCallback.onConnectedClientsChanged(mConnectedClients); } else { - Log.e(TAG, "SoftApCallback is null. Dropping NumClientsChanged event."); + Log.e(TAG, + "SoftApCallback is null. Dropping ConnectedClientsChanged event." + ); } + mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent( - mNumAssociatedStations, mApConfig.getTargetMode()); + mConnectedClients.size(), mApConfig.getTargetMode()); - if (mNumAssociatedStations == 0) { + if (mConnectedClients.size() == 0) { scheduleTimeoutMessage(); } else { cancelTimeoutMessage(); } } + private List<WifiClient> createWifiClients(List<NativeWifiClient> nativeClients) { + List<WifiClient> clients = new ArrayList<>(); + if (nativeClients == null || nativeClients.size() == 0) { + return clients; + } + + for (int i = 0; i < nativeClients.size(); i++) { + MacAddress macAddress = MacAddress.fromBytes(nativeClients.get(i).macAddress); + WifiClient client = new WifiClient(macAddress); + clients.add(client); + } + + return clients; + } + private void onUpChanged(boolean isUp) { if (isUp == mIfaceIsUp) { return; // no change } + mIfaceIsUp = isUp; if (isUp) { Log.d(TAG, "SoftAp is ready for use"); @@ -557,7 +588,7 @@ public class SoftApManager implements ActiveModeManager { mModeListener.onStarted(); mWifiMetrics.incrementSoftApStartResult(true, 0); if (mSoftApCallback != null) { - mSoftApCallback.onNumClientsChanged(mNumAssociatedStations); + mSoftApCallback.onConnectedClientsChanged(mConnectedClients); } } else { // the interface was up, but goes down @@ -585,8 +616,8 @@ public class SoftApManager implements ActiveModeManager { mSarManager.setSapWifiState(WifiManager.WIFI_AP_STATE_ENABLED); - Log.d(TAG, "Resetting num stations on start"); - mNumAssociatedStations = 0; + Log.d(TAG, "Resetting connected clients on start"); + mConnectedClients = new ArrayList<>(); scheduleTimeoutMessage(); } @@ -600,7 +631,7 @@ public class SoftApManager implements ActiveModeManager { mSettingObserver.unregister(); } Log.d(TAG, "Resetting num stations on stop"); - setNumAssociatedStations(0); + setConnectedClients(new ArrayList<>()); cancelTimeoutMessage(); // Need this here since we are exiting |Started| state and won't handle any // future CMD_INTERFACE_STATUS_CHANGED events after this point @@ -620,9 +651,9 @@ public class SoftApManager implements ActiveModeManager { int band = mApConfig.getWifiConfiguration().apBand; boolean bandPreferenceViolated = (band == WifiConfiguration.AP_BAND_2GHZ - && ScanResult.is5GHz(mReportedFrequency)) - || (band == WifiConfiguration.AP_BAND_5GHZ - && ScanResult.is24GHz(mReportedFrequency)); + && ScanResult.is5GHz(mReportedFrequency)) + || (band == WifiConfiguration.AP_BAND_5GHZ + && ScanResult.is24GHz(mReportedFrequency)); if (bandPreferenceViolated) { Log.e(TAG, "Channel does not satisfy user band preference: " + mReportedFrequency); @@ -633,13 +664,16 @@ public class SoftApManager implements ActiveModeManager { @Override public boolean processMessage(Message message) { switch (message.what) { - case CMD_NUM_ASSOCIATED_STATIONS_CHANGED: - if (message.arg1 < 0) { - Log.e(TAG, "Invalid number of associated stations: " + message.arg1); + case CMD_ASSOCIATED_STATIONS_CHANGED: + if (!(message.obj instanceof List)) { + Log.e(TAG, "Invalid type returned for" + + " CMD_ASSOCIATED_STATIONS_CHANGED"); break; } - Log.d(TAG, "Setting num stations on CMD_NUM_ASSOCIATED_STATIONS_CHANGED"); - setNumAssociatedStations(message.arg1); + + Log.d(TAG, "Setting connected stations on" + + " CMD_ASSOCIATED_STATIONS_CHANGED"); + setConnectedClients((List<NativeWifiClient>) message.obj); break; case CMD_SOFT_AP_CHANNEL_SWITCHED: mReportedFrequency = message.arg1; @@ -659,7 +693,7 @@ public class SoftApManager implements ActiveModeManager { if (!mTimeoutEnabled) { cancelTimeoutMessage(); } - if (mTimeoutEnabled && mNumAssociatedStations == 0) { + if (mTimeoutEnabled && mConnectedClients.size() == 0) { scheduleTimeoutMessage(); } break; @@ -676,7 +710,7 @@ public class SoftApManager implements ActiveModeManager { + " Dropping."); break; } - if (mNumAssociatedStations != 0) { + if (mConnectedClients.size() != 0) { Log.wtf(TAG, "Timeout message received but has clients. Dropping."); break; } diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 7b55af147..b9e766811 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -39,6 +39,7 @@ import com.android.internal.util.HexDump; import com.android.server.net.BaseNetworkObserver; import com.android.server.wifi.util.FrameParser; import com.android.server.wifi.util.NativeUtil; +import com.android.server.wifi.wificond.NativeWifiClient; import java.io.PrintWriter; import java.io.StringWriter; @@ -1618,9 +1619,9 @@ public class WifiNative { void onFailure(); /** - * Invoked when the number of associated stations changes. + * Invoked when the associated stations changes. */ - void onNumAssociatedStationsChanged(int numStations); + void onConnectedClientsChanged(List<NativeWifiClient> clients); /** * Invoked when the channel switch event happens. diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 26415465f..9d3f422cb 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -59,6 +59,7 @@ import android.net.wifi.ITrafficStateCallback; import android.net.wifi.ITxPacketCountListener; import android.net.wifi.ScanResult; import android.net.wifi.WifiActivityEnergyInfo; +import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; @@ -831,7 +832,7 @@ public class WifiServiceImpl extends BaseWifiService { */ private final Object mLock = new Object(); private int mTetheredSoftApState = WIFI_AP_STATE_DISABLED; - private int mTetheredSoftApNumClients = 0; + private List<WifiClient> mTetheredSoftApConnectedClients = new ArrayList<>(); public int getState() { synchronized (mLock) { @@ -848,8 +849,8 @@ public class WifiServiceImpl extends BaseWifiService { } } - public int getNumClients() { - return mTetheredSoftApNumClients; + public List<WifiClient> getConnectedClients() { + return mTetheredSoftApConnectedClients; } private final ExternalCallbackTracker<ISoftApCallback> mRegisteredSoftApCallbacks = @@ -894,22 +895,22 @@ public class WifiServiceImpl extends BaseWifiService { } /** - * Called when number of connected clients to soft AP changes. + * Called when the connected clients to soft AP changes. * - * @param numClients number of connected clients to soft AP + * @param clients connected clients to soft AP */ @Override - public void onNumClientsChanged(int numClients) { - mTetheredSoftApNumClients = numClients; + public void onConnectedClientsChanged(List<WifiClient> clients) { + mTetheredSoftApConnectedClients = new ArrayList<>(clients); Iterator<ISoftApCallback> iterator = mRegisteredSoftApCallbacks.getCallbacks().iterator(); while (iterator.hasNext()) { ISoftApCallback callback = iterator.next(); try { - callback.onNumClientsChanged(numClients); + callback.onConnectedClientsChanged(mTetheredSoftApConnectedClients); } catch (RemoteException e) { - Log.e(TAG, "onNumClientsChanged: remote exception -- " + e); + Log.e(TAG, "onConnectedClientsChanged: remote exception -- " + e); // TODO(b/138863863) remove does nothing, getCallbacks() returns a copy iterator.remove(); } @@ -1210,8 +1211,9 @@ public class WifiServiceImpl extends BaseWifiService { mLohsState = state; } } + @Override - public void onNumClientsChanged(int numClients) { + public void onConnectedClientsChanged(List<WifiClient> clients) { // Nothing to do } } @@ -1254,7 +1256,7 @@ public class WifiServiceImpl extends BaseWifiService { // Update the client about the current state immediately after registering the callback try { callback.onStateChanged(mTetheredSoftApTracker.getState(), 0); - callback.onNumClientsChanged(mTetheredSoftApTracker.getNumClients()); + callback.onConnectedClientsChanged(mTetheredSoftApTracker.getConnectedClients()); } catch (RemoteException e) { Log.e(TAG, "registerSoftApCallback: remote exception -- " + e); } @@ -2166,7 +2168,7 @@ public class WifiServiceImpl extends BaseWifiService { final boolean privilegedFinal = privileged; return mWifiThreadRunner.call( () -> mPasspointManager.getProviderConfigs(uid, privilegedFinal), - Collections.emptyList()); + Collections.emptyList()); } /** diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index 217a0dd98..0fc151bb8 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -46,6 +46,7 @@ import com.android.server.wifi.wificond.ISendMgmtFrameEvent; import com.android.server.wifi.wificond.IWifiScannerImpl; import com.android.server.wifi.wificond.IWificond; import com.android.server.wifi.wificond.NativeScanResult; +import com.android.server.wifi.wificond.NativeWifiClient; import com.android.server.wifi.wificond.PnoNetwork; import com.android.server.wifi.wificond.PnoSettings; import com.android.server.wifi.wificond.RadioChainInfo; @@ -173,8 +174,15 @@ public class WificondControl implements IBinder.DeathRecipient { } @Override - public void onNumAssociatedStationsChanged(int numStations) { - mSoftApListener.onNumAssociatedStationsChanged(numStations); + public void onConnectedClientsChanged(NativeWifiClient[] clients) { + if (mVerboseLoggingEnabled) { + Log.d(TAG, "onConnectedClientsChanged called with " + clients.length + " clients"); + for (int i = 0; i < clients.length; i++) { + Log.d(TAG, " mac " + clients[i].macAddress); + } + } + + mSoftApListener.onConnectedClientsChanged(Arrays.asList(clients)); } @Override |