diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/SoftApManager.java | 80 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 38 |
2 files changed, 103 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index c28d224ff..757c1de31 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.SoftApInfo; import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; @@ -48,6 +49,7 @@ 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.IApInterfaceEventCallback; import com.android.server.wifi.wificond.NativeWifiClient; import java.io.FileDescriptor; @@ -94,8 +96,8 @@ public class SoftApManager implements ActiveModeManager { @NonNull private SoftApModeConfiguration mApConfig; - private int mReportedFrequency = -1; - private int mReportedBandwidth = -1; + @NonNull + private SoftApInfo mCurrentSoftApInfo = new SoftApInfo(); private List<WifiClient> mConnectedClients = new ArrayList<>(); private boolean mTimeoutEnabled = false; @@ -226,8 +228,7 @@ public class SoftApManager implements ActiveModeManager { pw.println("mApConfig.wifiConfiguration.hiddenSSID: " + wifiConfig.hiddenSSID); pw.println("mConnectedClients.size(): " + mConnectedClients.size()); pw.println("mTimeoutEnabled: " + mTimeoutEnabled); - pw.println("mReportedFrequency: " + mReportedFrequency); - pw.println("mReportedBandwidth: " + mReportedBandwidth); + pw.println("mCurrentSoftApInfo " + mCurrentSoftApInfo); pw.println("mStartTimestamp: " + mStartTimestamp); mStateMachine.dump(fd, pw, args); } @@ -600,6 +601,55 @@ public class SoftApManager implements ActiveModeManager { return clients; } + private void setSoftApChannel(int freq, int bandwidth) { + int apBandwidth; + + Log.d(TAG, "Channel switched. Frequency: " + freq + + " Bandwidth: " + bandwidth); + switch(bandwidth) { + case IApInterfaceEventCallback.BANDWIDTH_INVALID: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_INVALID; + break; + case IApInterfaceEventCallback.BANDWIDTH_20_NOHT: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_20MHZ_NOHT; + break; + case IApInterfaceEventCallback.BANDWIDTH_20: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_20MHZ; + break; + case IApInterfaceEventCallback.BANDWIDTH_40: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_40MHZ; + break; + case IApInterfaceEventCallback.BANDWIDTH_80: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_80MHZ; + break; + case IApInterfaceEventCallback.BANDWIDTH_80P80: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_80MHZ_PLUS_MHZ; + break; + case IApInterfaceEventCallback.BANDWIDTH_160: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_160MHZ; + break; + default: + apBandwidth = SoftApInfo.CHANNEL_WIDTH_INVALID; + break; + } + + if (freq == mCurrentSoftApInfo.getFrequency() + && apBandwidth == mCurrentSoftApInfo.getBandwidth()) { + return; // no change + } + + mCurrentSoftApInfo.setFrequency(freq); + mCurrentSoftApInfo.setBandwidth(apBandwidth); + mSoftApCallback.onInfoChanged(mCurrentSoftApInfo); + + // ignore invalid freq and softap disable case for metrics + if (freq > 0 && apBandwidth != SoftApInfo.CHANNEL_WIDTH_INVALID) { + mWifiMetrics.addSoftApChannelSwitchedEvent(mCurrentSoftApInfo.getFrequency(), + mCurrentSoftApInfo.getBandwidth(), mApConfig.getTargetMode()); + updateUserBandPreferenceViolationMetricsIfNeeded(); + } + } + private void onUpChanged(boolean isUp) { if (isUp == mIfaceIsUp) { return; // no change @@ -658,6 +708,7 @@ public class SoftApManager implements ActiveModeManager { Log.d(TAG, "Resetting num stations on stop"); 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 mWifiMetrics.addSoftApUpChangedEvent(false, mApConfig.getTargetMode()); @@ -671,18 +722,19 @@ public class SoftApManager implements ActiveModeManager { mRole = ROLE_UNSPECIFIED; mStateMachine.quitNow(); mModeListener.onStopped(); + setSoftApChannel(0, SoftApInfo.CHANNEL_WIDTH_INVALID); } private void updateUserBandPreferenceViolationMetricsIfNeeded() { 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(mCurrentSoftApInfo.getFrequency())) + || (band == WifiConfiguration.AP_BAND_5GHZ + && ScanResult.is24GHz(mCurrentSoftApInfo.getFrequency())); if (bandPreferenceViolated) { Log.e(TAG, "Channel does not satisfy user band preference: " - + mReportedFrequency); + + mCurrentSoftApInfo.getFrequency()); mWifiMetrics.incrementNumSoftApUserBandPreferenceUnsatisfied(); } } @@ -702,13 +754,11 @@ public class SoftApManager implements ActiveModeManager { setConnectedClients((List<NativeWifiClient>) message.obj); break; case CMD_SOFT_AP_CHANNEL_SWITCHED: - mReportedFrequency = message.arg1; - mReportedBandwidth = message.arg2; - Log.d(TAG, "Channel switched. Frequency: " + mReportedFrequency - + " Bandwidth: " + mReportedBandwidth); - mWifiMetrics.addSoftApChannelSwitchedEvent(mReportedFrequency, - mReportedBandwidth, mApConfig.getTargetMode()); - updateUserBandPreferenceViolationMetricsIfNeeded(); + if (message.arg1 < 0) { + Log.e(TAG, "Invalid ap channel frequency: " + message.arg1); + break; + } + setSoftApChannel(message.arg1, message.arg2); 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 d2a4678ad..6ec72137b 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.SoftApConfiguration; +import android.net.wifi.SoftApInfo; import android.net.wifi.WifiActivityEnergyInfo; import android.net.wifi.WifiClient; import android.net.wifi.WifiConfiguration; @@ -838,6 +839,7 @@ public class WifiServiceImpl extends BaseWifiService { private final Object mLock = new Object(); private int mTetheredSoftApState = WIFI_AP_STATE_DISABLED; private List<WifiClient> mTetheredSoftApConnectedClients = new ArrayList<>(); + private SoftApInfo mTetheredSoftApInfo = new SoftApInfo(); public int getState() { synchronized (mLock) { @@ -858,6 +860,10 @@ public class WifiServiceImpl extends BaseWifiService { return mTetheredSoftApConnectedClients; } + public SoftApInfo getSoftApInfo() { + return mTetheredSoftApInfo; + } + private final ExternalCallbackTracker<ISoftApCallback> mRegisteredSoftApCallbacks = new ExternalCallbackTracker<>(mClientModeImplHandler); @@ -921,6 +927,27 @@ public class WifiServiceImpl extends BaseWifiService { } } } + + /** + * Called when information of softap changes. + * + * @param softApInfo is the softap information. {@link SoftApInfo} + */ + @Override + public void onInfoChanged(SoftApInfo softApInfo) { + mTetheredSoftApInfo = new SoftApInfo(softApInfo); + + Iterator<ISoftApCallback> iterator = + mRegisteredSoftApCallbacks.getCallbacks().iterator(); + while (iterator.hasNext()) { + ISoftApCallback callback = iterator.next(); + try { + callback.onInfoChanged(mTetheredSoftApInfo); + } catch (RemoteException e) { + Log.e(TAG, "onInfoChanged: remote exception -- " + e); + } + } + } } /** @@ -1247,6 +1274,16 @@ public class WifiServiceImpl extends BaseWifiService { public void onConnectedClientsChanged(List<WifiClient> clients) { // Nothing to do } + + /** + * Called when information of softap changes. + * + * @param softApInfo is the softap information. {@link SoftApInfo} + */ + @Override + public void onInfoChanged(SoftApInfo softApInfo) { + // Nothing to do + } } /** @@ -1288,6 +1325,7 @@ public class WifiServiceImpl extends BaseWifiService { try { callback.onStateChanged(mTetheredSoftApTracker.getState(), 0); callback.onConnectedClientsChanged(mTetheredSoftApTracker.getConnectedClients()); + callback.onInfoChanged(mTetheredSoftApTracker.getSoftApInfo()); } catch (RemoteException e) { Log.e(TAG, "registerSoftApCallback: remote exception -- " + e); } |