Use SoftAp API to get number of connected device

Create unit test because robolectric doesn't have the new API

Bug: 68058038
Test: SettingsUnitTest

Change-Id: I9fa27d51c4d270b2fb92db7dfc3955e33d4a3f4a
This commit is contained in:
jackqdyulei
2018-01-19 09:41:58 -08:00
parent 6411b170a5
commit d506894f5d
3 changed files with 116 additions and 5 deletions

View File

@@ -0,0 +1,47 @@
package com.android.settings.wifi.tether;
import android.net.wifi.WifiManager;
import android.os.Handler;
/**
* Wrapper for {@link android.net.wifi.WifiManager.SoftApCallback} to pass the robo test
*/
public class WifiTetherSoftApManager {
private WifiManager mWifiManager;
private WifiTetherSoftApCallback mWifiTetherSoftApCallback;
private WifiManager.SoftApCallback mSoftApCallback = new WifiManager.SoftApCallback() {
@Override
public void onStateChanged(int state, int failureReason) {
mWifiTetherSoftApCallback.onStateChanged(state, failureReason);
}
@Override
public void onNumClientsChanged(int numClients) {
mWifiTetherSoftApCallback.onNumClientsChanged(numClients);
}
};
private Handler mHandler;
WifiTetherSoftApManager(WifiManager wifiManager,
WifiTetherSoftApCallback wifiTetherSoftApCallback) {
mWifiManager = wifiManager;
mWifiTetherSoftApCallback = wifiTetherSoftApCallback;
mHandler = new Handler();
}
public void registerSoftApCallback() {
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler);
}
public void unRegisterSoftApCallback() {
mWifiManager.unregisterSoftApCallback(mSoftApCallback);
}
public interface WifiTetherSoftApCallback {
void onStateChanged(int state, int failureReason);
void onNumClientsChanged(int numClients);
}
}