cleanup for concurrency
Allow multiple instances of WifiMonitor and WifiNative to be created in preparation for multiple socket connections Change-Id: I06a227f87f1406dc62f884d56ad639ac623414b6
This commit is contained in:
@@ -39,6 +39,7 @@ class SupplicantStateTracker extends StateMachine {
|
||||
private static final boolean DBG = false;
|
||||
|
||||
private WifiStateMachine mWifiStateMachine;
|
||||
private WifiConfigStore mWifiConfigStore;
|
||||
private int mAuthenticationFailuresCount = 0;
|
||||
/* Indicates authentication failure in supplicant broadcast.
|
||||
* TODO: enhance auth failure reporting to include notification
|
||||
@@ -62,11 +63,12 @@ class SupplicantStateTracker extends StateMachine {
|
||||
private State mCompletedState = new CompletedState();
|
||||
private State mDormantState = new DormantState();
|
||||
|
||||
public SupplicantStateTracker(Context context, WifiStateMachine wsm, Handler target) {
|
||||
super(TAG, target.getLooper());
|
||||
public SupplicantStateTracker(Context c, WifiStateMachine wsm, WifiConfigStore wcs, Handler t) {
|
||||
super(TAG, t.getLooper());
|
||||
|
||||
mContext = context;
|
||||
mContext = c;
|
||||
mWifiStateMachine = wsm;
|
||||
mWifiConfigStore = wcs;
|
||||
addState(mDefaultState);
|
||||
addState(mUninitializedState, mDefaultState);
|
||||
addState(mInactiveState, mDefaultState);
|
||||
@@ -85,11 +87,11 @@ class SupplicantStateTracker extends StateMachine {
|
||||
private void handleNetworkConnectionFailure(int netId) {
|
||||
/* If other networks disabled during connection, enable them */
|
||||
if (mNetworksDisabledDuringConnect) {
|
||||
WifiConfigStore.enableAllNetworks();
|
||||
mWifiConfigStore.enableAllNetworks();
|
||||
mNetworksDisabledDuringConnect = false;
|
||||
}
|
||||
/* Disable failed network */
|
||||
WifiConfigStore.disableNetwork(netId, WifiConfiguration.DISABLED_AUTH_FAILURE);
|
||||
mWifiConfigStore.disableNetwork(netId, WifiConfiguration.DISABLED_AUTH_FAILURE);
|
||||
}
|
||||
|
||||
private void transitionOnSupplicantStateChange(StateChangeResult stateChangeResult) {
|
||||
@@ -285,7 +287,7 @@ class SupplicantStateTracker extends StateMachine {
|
||||
/* Reset authentication failure count */
|
||||
mAuthenticationFailuresCount = 0;
|
||||
if (mNetworksDisabledDuringConnect) {
|
||||
WifiConfigStore.enableAllNetworks();
|
||||
mWifiConfigStore.enableAllNetworks();
|
||||
mNetworksDisabledDuringConnect = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
*/
|
||||
class WifiConfigStore {
|
||||
|
||||
private static Context sContext;
|
||||
private Context mContext;
|
||||
private static final String TAG = "WifiConfigStore";
|
||||
private static final boolean DBG = false;
|
||||
|
||||
/* configured networks with network id as the key */
|
||||
private static HashMap<Integer, WifiConfiguration> sConfiguredNetworks =
|
||||
private HashMap<Integer, WifiConfiguration> mConfiguredNetworks =
|
||||
new HashMap<Integer, WifiConfiguration>();
|
||||
|
||||
/* A network id is a unique identifier for a network configured in the
|
||||
@@ -118,11 +118,11 @@ class WifiConfigStore {
|
||||
* that is generated from SSID and security type of the network. A mapping
|
||||
* from the generated unique id to network id of the network is needed to
|
||||
* map supplicant config to IP configuration. */
|
||||
private static HashMap<Integer, Integer> sNetworkIds =
|
||||
private HashMap<Integer, Integer> mNetworkIds =
|
||||
new HashMap<Integer, Integer>();
|
||||
|
||||
/* Tracks the highest priority of configured networks */
|
||||
private static int sLastPriority = -1;
|
||||
private int mLastPriority = -1;
|
||||
|
||||
private static final String ipConfigFile = Environment.getDataDirectory() +
|
||||
"/misc/wifi/ipconfig.txt";
|
||||
@@ -141,20 +141,19 @@ class WifiConfigStore {
|
||||
private static final String EXCLUSION_LIST_KEY = "exclusionList";
|
||||
private static final String EOS = "eos";
|
||||
|
||||
private static HandlerThread sDiskWriteHandlerThread;
|
||||
private static DiskWriteHandler sDiskWriteHandler;
|
||||
private static Object sDiskWriteHandlerSync = new Object();
|
||||
/* Tracks multiple writes on the same thread */
|
||||
private static int sWriteSequence = 0;
|
||||
private static final int WRITE = 1;
|
||||
private WifiNative mWifiNative;
|
||||
|
||||
WifiConfigStore(Context c, WifiNative wn) {
|
||||
mContext = c;
|
||||
mWifiNative = wn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize context, fetch the list of configured networks
|
||||
* Fetch the list of configured networks
|
||||
* and enable all stored networks in supplicant.
|
||||
*/
|
||||
static void initialize(Context context) {
|
||||
void initialize() {
|
||||
if (DBG) log("Loading config and enabling all networks");
|
||||
sContext = context;
|
||||
loadConfiguredNetworks();
|
||||
enableAllNetworks();
|
||||
}
|
||||
@@ -163,9 +162,9 @@ class WifiConfigStore {
|
||||
* Fetch the list of currently configured networks
|
||||
* @return List of networks
|
||||
*/
|
||||
static List<WifiConfiguration> getConfiguredNetworks() {
|
||||
List<WifiConfiguration> getConfiguredNetworks() {
|
||||
List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
|
||||
for(WifiConfiguration config : sConfiguredNetworks.values()) {
|
||||
for(WifiConfiguration config : mConfiguredNetworks.values()) {
|
||||
networks.add(new WifiConfiguration(config));
|
||||
}
|
||||
return networks;
|
||||
@@ -175,11 +174,11 @@ class WifiConfigStore {
|
||||
* enable all networks and save config. This will be a no-op if the list
|
||||
* of configured networks indicates all networks as being enabled
|
||||
*/
|
||||
static void enableAllNetworks() {
|
||||
void enableAllNetworks() {
|
||||
boolean networkEnabledStateChanged = false;
|
||||
for(WifiConfiguration config : sConfiguredNetworks.values()) {
|
||||
for(WifiConfiguration config : mConfiguredNetworks.values()) {
|
||||
if(config != null && config.status == Status.DISABLED) {
|
||||
if(WifiNative.enableNetwork(config.networkId, false)) {
|
||||
if(mWifiNative.enableNetwork(config.networkId, false)) {
|
||||
networkEnabledStateChanged = true;
|
||||
config.status = Status.ENABLED;
|
||||
} else {
|
||||
@@ -189,7 +188,7 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
if (networkEnabledStateChanged) {
|
||||
WifiNative.saveConfig();
|
||||
mWifiNative.saveConfig();
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
}
|
||||
}
|
||||
@@ -206,7 +205,7 @@ class WifiConfigStore {
|
||||
* @param config The configuration details in WifiConfiguration
|
||||
* @return the networkId now associated with the specified configuration
|
||||
*/
|
||||
static int selectNetwork(WifiConfiguration config) {
|
||||
int selectNetwork(WifiConfiguration config) {
|
||||
if (config != null) {
|
||||
NetworkUpdateResult result = addOrUpdateNetworkNative(config);
|
||||
int netId = result.getNetworkId();
|
||||
@@ -231,25 +230,25 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param netId network to select for connection
|
||||
*/
|
||||
static void selectNetwork(int netId) {
|
||||
void selectNetwork(int netId) {
|
||||
// Reset the priority of each network at start or if it goes too high.
|
||||
if (sLastPriority == -1 || sLastPriority > 1000000) {
|
||||
for(WifiConfiguration config : sConfiguredNetworks.values()) {
|
||||
if (mLastPriority == -1 || mLastPriority > 1000000) {
|
||||
for(WifiConfiguration config : mConfiguredNetworks.values()) {
|
||||
if (config.networkId != INVALID_NETWORK_ID) {
|
||||
config.priority = 0;
|
||||
addOrUpdateNetworkNative(config);
|
||||
}
|
||||
}
|
||||
sLastPriority = 0;
|
||||
mLastPriority = 0;
|
||||
}
|
||||
|
||||
// Set to the highest priority and save the configuration.
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.networkId = netId;
|
||||
config.priority = ++sLastPriority;
|
||||
config.priority = ++mLastPriority;
|
||||
|
||||
addOrUpdateNetworkNative(config);
|
||||
WifiNative.saveConfig();
|
||||
mWifiNative.saveConfig();
|
||||
|
||||
/* Enable the given network while disabling all other networks */
|
||||
enableNetworkWithoutBroadcast(netId, true);
|
||||
@@ -263,23 +262,23 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param config WifiConfiguration to be saved
|
||||
*/
|
||||
static NetworkUpdateResult saveNetwork(WifiConfiguration config) {
|
||||
NetworkUpdateResult saveNetwork(WifiConfiguration config) {
|
||||
boolean newNetwork = (config.networkId == INVALID_NETWORK_ID);
|
||||
NetworkUpdateResult result = addOrUpdateNetworkNative(config);
|
||||
int netId = result.getNetworkId();
|
||||
/* enable a new network */
|
||||
if (newNetwork && netId != INVALID_NETWORK_ID) {
|
||||
WifiNative.enableNetwork(netId, false);
|
||||
sConfiguredNetworks.get(netId).status = Status.ENABLED;
|
||||
mWifiNative.enableNetwork(netId, false);
|
||||
mConfiguredNetworks.get(netId).status = Status.ENABLED;
|
||||
}
|
||||
WifiNative.saveConfig();
|
||||
mWifiNative.saveConfig();
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
return result;
|
||||
}
|
||||
|
||||
static void updateStatus(int netId, DetailedState state) {
|
||||
void updateStatus(int netId, DetailedState state) {
|
||||
if (netId != INVALID_NETWORK_ID) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config == null) return;
|
||||
switch (state) {
|
||||
case CONNECTED:
|
||||
@@ -300,13 +299,13 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param netId network to forget
|
||||
*/
|
||||
static void forgetNetwork(int netId) {
|
||||
if (WifiNative.removeNetwork(netId)) {
|
||||
WifiNative.saveConfig();
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
void forgetNetwork(int netId) {
|
||||
if (mWifiNative.removeNetwork(netId)) {
|
||||
mWifiNative.saveConfig();
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null) {
|
||||
sConfiguredNetworks.remove(netId);
|
||||
sNetworkIds.remove(configKey(config));
|
||||
mConfiguredNetworks.remove(netId);
|
||||
mNetworkIds.remove(configKey(config));
|
||||
}
|
||||
writeIpAndProxyConfigurations();
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
@@ -323,7 +322,7 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param config wifi configuration to add/update
|
||||
*/
|
||||
static int addOrUpdateNetwork(WifiConfiguration config) {
|
||||
int addOrUpdateNetwork(WifiConfiguration config) {
|
||||
NetworkUpdateResult result = addOrUpdateNetworkNative(config);
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
return result.getNetworkId();
|
||||
@@ -337,13 +336,13 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param netId network to be removed
|
||||
*/
|
||||
static boolean removeNetwork(int netId) {
|
||||
boolean ret = WifiNative.removeNetwork(netId);
|
||||
boolean removeNetwork(int netId) {
|
||||
boolean ret = mWifiNative.removeNetwork(netId);
|
||||
if (ret) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null) {
|
||||
sConfiguredNetworks.remove(netId);
|
||||
sNetworkIds.remove(configKey(config));
|
||||
mConfiguredNetworks.remove(netId);
|
||||
mNetworkIds.remove(configKey(config));
|
||||
}
|
||||
}
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
@@ -358,16 +357,16 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param netId network to be removed
|
||||
*/
|
||||
static boolean enableNetwork(int netId, boolean disableOthers) {
|
||||
boolean enableNetwork(int netId, boolean disableOthers) {
|
||||
boolean ret = enableNetworkWithoutBroadcast(netId, disableOthers);
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static boolean enableNetworkWithoutBroadcast(int netId, boolean disableOthers) {
|
||||
boolean ret = WifiNative.enableNetwork(netId, disableOthers);
|
||||
boolean enableNetworkWithoutBroadcast(int netId, boolean disableOthers) {
|
||||
boolean ret = mWifiNative.enableNetwork(netId, disableOthers);
|
||||
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null) config.status = Status.ENABLED;
|
||||
|
||||
if (disableOthers) {
|
||||
@@ -380,7 +379,7 @@ class WifiConfigStore {
|
||||
* Disable a network. Note that there is no saveConfig operation.
|
||||
* @param netId network to be disabled
|
||||
*/
|
||||
static boolean disableNetwork(int netId) {
|
||||
boolean disableNetwork(int netId) {
|
||||
return disableNetwork(netId, WifiConfiguration.DISABLED_UNKNOWN_REASON);
|
||||
}
|
||||
|
||||
@@ -389,9 +388,9 @@ class WifiConfigStore {
|
||||
* @param netId network to be disabled
|
||||
* @param reason reason code network was disabled
|
||||
*/
|
||||
static boolean disableNetwork(int netId, int reason) {
|
||||
boolean ret = WifiNative.disableNetwork(netId);
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
boolean disableNetwork(int netId, int reason) {
|
||||
boolean ret = mWifiNative.disableNetwork(netId);
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
/* Only change the reason if the network was not previously disabled */
|
||||
if (config != null && config.status != Status.DISABLED) {
|
||||
config.status = Status.DISABLED;
|
||||
@@ -404,17 +403,17 @@ class WifiConfigStore {
|
||||
/**
|
||||
* Save the configured networks in supplicant to disk
|
||||
*/
|
||||
static boolean saveConfig() {
|
||||
return WifiNative.saveConfig();
|
||||
boolean saveConfig() {
|
||||
return mWifiNative.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start WPS pin method configuration with pin obtained
|
||||
* from the access point
|
||||
*/
|
||||
static WpsResult startWpsWithPinFromAccessPoint(WpsInfo config) {
|
||||
WpsResult startWpsWithPinFromAccessPoint(WpsInfo config) {
|
||||
WpsResult result = new WpsResult();
|
||||
if (WifiNative.startWpsRegistrar(config.BSSID, config.pin)) {
|
||||
if (mWifiNative.startWpsRegistrar(config.BSSID, config.pin)) {
|
||||
/* WPS leaves all networks disabled */
|
||||
markAllNetworksDisabled();
|
||||
result.status = WpsResult.Status.SUCCESS;
|
||||
@@ -430,9 +429,9 @@ class WifiConfigStore {
|
||||
* from the device
|
||||
* @return WpsResult indicating status and pin
|
||||
*/
|
||||
static WpsResult startWpsWithPinFromDevice(WpsInfo config) {
|
||||
WpsResult startWpsWithPinFromDevice(WpsInfo config) {
|
||||
WpsResult result = new WpsResult();
|
||||
result.pin = WifiNative.startWpsPinDisplay(config.BSSID);
|
||||
result.pin = mWifiNative.startWpsPinDisplay(config.BSSID);
|
||||
/* WPS leaves all networks disabled */
|
||||
if (!TextUtils.isEmpty(result.pin)) {
|
||||
markAllNetworksDisabled();
|
||||
@@ -447,9 +446,9 @@ class WifiConfigStore {
|
||||
/**
|
||||
* Start WPS push button configuration
|
||||
*/
|
||||
static WpsResult startWpsPbc(WpsInfo config) {
|
||||
WpsResult startWpsPbc(WpsInfo config) {
|
||||
WpsResult result = new WpsResult();
|
||||
if (WifiNative.startWpsPbc(config.BSSID)) {
|
||||
if (mWifiNative.startWpsPbc(config.BSSID)) {
|
||||
/* WPS leaves all networks disabled */
|
||||
markAllNetworksDisabled();
|
||||
result.status = WpsResult.Status.SUCCESS;
|
||||
@@ -463,8 +462,8 @@ class WifiConfigStore {
|
||||
/**
|
||||
* Fetch the link properties for a given network id
|
||||
*/
|
||||
static LinkProperties getLinkProperties(int netId) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
LinkProperties getLinkProperties(int netId) {
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null) return new LinkProperties(config.linkProperties);
|
||||
return null;
|
||||
}
|
||||
@@ -476,7 +475,7 @@ class WifiConfigStore {
|
||||
* that, we should remove handling DhcpInfo and move
|
||||
* to using LinkProperties
|
||||
*/
|
||||
static DhcpInfoInternal getIpConfiguration(int netId) {
|
||||
DhcpInfoInternal getIpConfiguration(int netId) {
|
||||
DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
|
||||
LinkProperties linkProperties = getLinkProperties(netId);
|
||||
|
||||
@@ -502,10 +501,10 @@ class WifiConfigStore {
|
||||
/**
|
||||
* set IP configuration for a given network id
|
||||
*/
|
||||
static void setIpConfiguration(int netId, DhcpInfoInternal dhcpInfo) {
|
||||
void setIpConfiguration(int netId, DhcpInfoInternal dhcpInfo) {
|
||||
LinkProperties linkProperties = dhcpInfo.makeLinkProperties();
|
||||
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null) {
|
||||
// add old proxy details
|
||||
if(config.linkProperties != null) {
|
||||
@@ -518,8 +517,8 @@ class WifiConfigStore {
|
||||
/**
|
||||
* clear IP configuration for a given network id
|
||||
*/
|
||||
static void clearIpConfiguration(int netId) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
void clearIpConfiguration(int netId) {
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null && config.linkProperties != null) {
|
||||
// Clear everything except proxy
|
||||
ProxyProperties proxy = config.linkProperties.getHttpProxy();
|
||||
@@ -532,7 +531,7 @@ class WifiConfigStore {
|
||||
/**
|
||||
* Fetch the proxy properties for a given network id
|
||||
*/
|
||||
static ProxyProperties getProxyProperties(int netId) {
|
||||
ProxyProperties getProxyProperties(int netId) {
|
||||
LinkProperties linkProperties = getLinkProperties(netId);
|
||||
if (linkProperties != null) {
|
||||
return new ProxyProperties(linkProperties.getHttpProxy());
|
||||
@@ -543,26 +542,26 @@ class WifiConfigStore {
|
||||
/**
|
||||
* Return if the specified network is using static IP
|
||||
*/
|
||||
static boolean isUsingStaticIp(int netId) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
boolean isUsingStaticIp(int netId) {
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null && config.ipAssignment == IpAssignment.STATIC) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void sendConfiguredNetworksChangedBroadcast() {
|
||||
private void sendConfiguredNetworksChangedBroadcast() {
|
||||
Intent intent = new Intent(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||
sContext.sendBroadcast(intent);
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
static void loadConfiguredNetworks() {
|
||||
String listStr = WifiNative.listNetworks();
|
||||
sLastPriority = 0;
|
||||
void loadConfiguredNetworks() {
|
||||
String listStr = mWifiNative.listNetworks();
|
||||
mLastPriority = 0;
|
||||
|
||||
sConfiguredNetworks.clear();
|
||||
sNetworkIds.clear();
|
||||
mConfiguredNetworks.clear();
|
||||
mNetworkIds.clear();
|
||||
|
||||
if (listStr == null)
|
||||
return;
|
||||
@@ -589,19 +588,19 @@ class WifiConfigStore {
|
||||
config.status = WifiConfiguration.Status.ENABLED;
|
||||
}
|
||||
readNetworkVariables(config);
|
||||
if (config.priority > sLastPriority) {
|
||||
sLastPriority = config.priority;
|
||||
if (config.priority > mLastPriority) {
|
||||
mLastPriority = config.priority;
|
||||
}
|
||||
sConfiguredNetworks.put(config.networkId, config);
|
||||
sNetworkIds.put(configKey(config), config.networkId);
|
||||
mConfiguredNetworks.put(config.networkId, config);
|
||||
mNetworkIds.put(configKey(config), config.networkId);
|
||||
}
|
||||
|
||||
readIpAndProxyConfigurations();
|
||||
sendConfiguredNetworksChangedBroadcast();
|
||||
}
|
||||
|
||||
static void updateIpAndProxyFromWpsConfig(int netId, WpsInfo wpsConfig) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(netId);
|
||||
void updateIpAndProxyFromWpsConfig(int netId, WpsInfo wpsConfig) {
|
||||
WifiConfiguration config = mConfiguredNetworks.get(netId);
|
||||
if (config != null) {
|
||||
config.ipAssignment = wpsConfig.ipAssignment;
|
||||
config.proxySettings = wpsConfig.proxySettings;
|
||||
@@ -611,8 +610,8 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
/* Mark all networks except specified netId as disabled */
|
||||
private static void markAllNetworksDisabledExcept(int netId) {
|
||||
for(WifiConfiguration config : sConfiguredNetworks.values()) {
|
||||
private void markAllNetworksDisabledExcept(int netId) {
|
||||
for(WifiConfiguration config : mConfiguredNetworks.values()) {
|
||||
if(config != null && config.networkId != netId) {
|
||||
if (config.status != Status.DISABLED) {
|
||||
config.status = Status.DISABLED;
|
||||
@@ -622,43 +621,49 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
private static void markAllNetworksDisabled() {
|
||||
private void markAllNetworksDisabled() {
|
||||
markAllNetworksDisabledExcept(INVALID_NETWORK_ID);
|
||||
}
|
||||
|
||||
private static void writeIpAndProxyConfigurations() {
|
||||
private void writeIpAndProxyConfigurations() {
|
||||
|
||||
/* Make a copy */
|
||||
List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
|
||||
for(WifiConfiguration config : sConfiguredNetworks.values()) {
|
||||
for(WifiConfiguration config : mConfiguredNetworks.values()) {
|
||||
networks.add(new WifiConfiguration(config));
|
||||
}
|
||||
|
||||
/* Do a delayed write to disk on a seperate handler thread */
|
||||
synchronized (sDiskWriteHandlerSync) {
|
||||
if (++sWriteSequence == 1) {
|
||||
sDiskWriteHandlerThread = new HandlerThread("WifiConfigThread");
|
||||
sDiskWriteHandlerThread.start();
|
||||
sDiskWriteHandler = new DiskWriteHandler(sDiskWriteHandlerThread.getLooper());
|
||||
}
|
||||
}
|
||||
|
||||
sDiskWriteHandler.sendMessage(Message.obtain(sDiskWriteHandler, WRITE, networks));
|
||||
DelayedDiskWrite.write(networks);
|
||||
}
|
||||
|
||||
private static class DiskWriteHandler extends Handler {
|
||||
private static class DelayedDiskWrite {
|
||||
|
||||
DiskWriteHandler(android.os.Looper l) {
|
||||
super(l);
|
||||
}
|
||||
private static HandlerThread sDiskWriteHandlerThread;
|
||||
private static Handler sDiskWriteHandler;
|
||||
/* Tracks multiple writes on the same thread */
|
||||
private static int sWriteSequence = 0;
|
||||
private static final String TAG = "DelayedDiskWrite";
|
||||
|
||||
public void handleMessage(Message msg) {
|
||||
static void write (final List<WifiConfiguration> networks) {
|
||||
|
||||
if (msg.what != WRITE) {
|
||||
throw new RuntimeException("Unsupported message in WifiConfigStore: " + msg);
|
||||
/* Do a delayed write to disk on a seperate handler thread */
|
||||
synchronized (DelayedDiskWrite.class) {
|
||||
if (++sWriteSequence == 1) {
|
||||
sDiskWriteHandlerThread = new HandlerThread("WifiConfigThread");
|
||||
sDiskWriteHandlerThread.start();
|
||||
sDiskWriteHandler = new Handler(sDiskWriteHandlerThread.getLooper());
|
||||
}
|
||||
}
|
||||
|
||||
List<WifiConfiguration> networks = (List<WifiConfiguration>) msg.obj;
|
||||
sDiskWriteHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onWriteCalled(networks);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void onWriteCalled(List<WifiConfiguration> networks) {
|
||||
|
||||
DataOutputStream out = null;
|
||||
try {
|
||||
@@ -740,7 +745,7 @@ class WifiConfigStore {
|
||||
/* Ignore */
|
||||
break;
|
||||
default:
|
||||
loge("Ignore invalid proxy settings while writing");
|
||||
loge("Ignthisore invalid proxy settings while writing");
|
||||
break;
|
||||
}
|
||||
if (writeToFile) {
|
||||
@@ -763,18 +768,22 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
//Quit if no more writes sent
|
||||
synchronized (sDiskWriteHandlerSync) {
|
||||
synchronized (DelayedDiskWrite.class) {
|
||||
if (--sWriteSequence == 0) {
|
||||
getLooper().quit();
|
||||
sDiskWriteHandler.getLooper().quit();
|
||||
sDiskWriteHandler = null;
|
||||
sDiskWriteHandlerThread = null;
|
||||
sDiskWriteHandler= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void loge(String s) {
|
||||
Log.e(TAG, s);
|
||||
}
|
||||
}
|
||||
|
||||
private static void readIpAndProxyConfigurations() {
|
||||
private void readIpAndProxyConfigurations() {
|
||||
|
||||
DataInputStream in = null;
|
||||
try {
|
||||
@@ -847,8 +856,8 @@ class WifiConfigStore {
|
||||
} while (true);
|
||||
|
||||
if (id != -1) {
|
||||
WifiConfiguration config = sConfiguredNetworks.get(
|
||||
sNetworkIds.get(id));
|
||||
WifiConfiguration config = mConfiguredNetworks.get(
|
||||
mNetworkIds.get(id));
|
||||
|
||||
if (config == null) {
|
||||
loge("configuration found for missing network, ignored");
|
||||
@@ -901,7 +910,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
private static NetworkUpdateResult addOrUpdateNetworkNative(WifiConfiguration config) {
|
||||
private NetworkUpdateResult addOrUpdateNetworkNative(WifiConfiguration config) {
|
||||
/*
|
||||
* If the supplied networkId is INVALID_NETWORK_ID, we create a new empty
|
||||
* network configuration. Otherwise, the networkId should
|
||||
@@ -911,12 +920,12 @@ class WifiConfigStore {
|
||||
boolean newNetwork = false;
|
||||
// networkId of INVALID_NETWORK_ID means we want to create a new network
|
||||
if (netId == INVALID_NETWORK_ID) {
|
||||
Integer savedNetId = sNetworkIds.get(configKey(config));
|
||||
Integer savedNetId = mNetworkIds.get(configKey(config));
|
||||
if (savedNetId != null) {
|
||||
netId = savedNetId;
|
||||
} else {
|
||||
newNetwork = true;
|
||||
netId = WifiNative.addNetwork();
|
||||
netId = mWifiNative.addNetwork();
|
||||
if (netId < 0) {
|
||||
loge("Failed to add a network!");
|
||||
return new NetworkUpdateResult(INVALID_NETWORK_ID);
|
||||
@@ -929,7 +938,7 @@ class WifiConfigStore {
|
||||
setVariables: {
|
||||
|
||||
if (config.SSID != null &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.ssidVarName,
|
||||
config.SSID)) {
|
||||
@@ -938,7 +947,7 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
if (config.BSSID != null &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.bssidVarName,
|
||||
config.BSSID)) {
|
||||
@@ -949,7 +958,7 @@ class WifiConfigStore {
|
||||
String allowedKeyManagementString =
|
||||
makeString(config.allowedKeyManagement, WifiConfiguration.KeyMgmt.strings);
|
||||
if (config.allowedKeyManagement.cardinality() != 0 &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.KeyMgmt.varName,
|
||||
allowedKeyManagementString)) {
|
||||
@@ -961,7 +970,7 @@ class WifiConfigStore {
|
||||
String allowedProtocolsString =
|
||||
makeString(config.allowedProtocols, WifiConfiguration.Protocol.strings);
|
||||
if (config.allowedProtocols.cardinality() != 0 &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.Protocol.varName,
|
||||
allowedProtocolsString)) {
|
||||
@@ -973,7 +982,7 @@ class WifiConfigStore {
|
||||
String allowedAuthAlgorithmsString =
|
||||
makeString(config.allowedAuthAlgorithms, WifiConfiguration.AuthAlgorithm.strings);
|
||||
if (config.allowedAuthAlgorithms.cardinality() != 0 &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.AuthAlgorithm.varName,
|
||||
allowedAuthAlgorithmsString)) {
|
||||
@@ -986,7 +995,7 @@ class WifiConfigStore {
|
||||
makeString(config.allowedPairwiseCiphers,
|
||||
WifiConfiguration.PairwiseCipher.strings);
|
||||
if (config.allowedPairwiseCiphers.cardinality() != 0 &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.PairwiseCipher.varName,
|
||||
allowedPairwiseCiphersString)) {
|
||||
@@ -998,7 +1007,7 @@ class WifiConfigStore {
|
||||
String allowedGroupCiphersString =
|
||||
makeString(config.allowedGroupCiphers, WifiConfiguration.GroupCipher.strings);
|
||||
if (config.allowedGroupCiphers.cardinality() != 0 &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.GroupCipher.varName,
|
||||
allowedGroupCiphersString)) {
|
||||
@@ -1010,7 +1019,7 @@ class WifiConfigStore {
|
||||
// Prevent client screw-up by passing in a WifiConfiguration we gave it
|
||||
// by preventing "*" as a key.
|
||||
if (config.preSharedKey != null && !config.preSharedKey.equals("*") &&
|
||||
!WifiNative.setNetworkVariable(
|
||||
!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.pskVarName,
|
||||
config.preSharedKey)) {
|
||||
@@ -1024,7 +1033,7 @@ class WifiConfigStore {
|
||||
// Prevent client screw-up by passing in a WifiConfiguration we gave it
|
||||
// by preventing "*" as a key.
|
||||
if (config.wepKeys[i] != null && !config.wepKeys[i].equals("*")) {
|
||||
if (!WifiNative.setNetworkVariable(
|
||||
if (!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.wepKeyVarNames[i],
|
||||
config.wepKeys[i])) {
|
||||
@@ -1037,7 +1046,7 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
if (hasSetKey) {
|
||||
if (!WifiNative.setNetworkVariable(
|
||||
if (!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.wepTxKeyIdxVarName,
|
||||
Integer.toString(config.wepTxKeyIndex))) {
|
||||
@@ -1046,7 +1055,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
if (!WifiNative.setNetworkVariable(
|
||||
if (!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.priorityVarName,
|
||||
Integer.toString(config.priority))) {
|
||||
@@ -1055,7 +1064,7 @@ class WifiConfigStore {
|
||||
break setVariables;
|
||||
}
|
||||
|
||||
if (config.hiddenSSID && !WifiNative.setNetworkVariable(
|
||||
if (config.hiddenSSID && !mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
WifiConfiguration.hiddenSSIDVarName,
|
||||
Integer.toString(config.hiddenSSID ? 1 : 0))) {
|
||||
@@ -1072,7 +1081,7 @@ class WifiConfigStore {
|
||||
if (field != config.eap) {
|
||||
value = (value.length() == 0) ? "NULL" : convertToQuotedString(value);
|
||||
}
|
||||
if (!WifiNative.setNetworkVariable(
|
||||
if (!mWifiNative.setNetworkVariable(
|
||||
netId,
|
||||
varName,
|
||||
value)) {
|
||||
@@ -1087,37 +1096,37 @@ class WifiConfigStore {
|
||||
|
||||
if (updateFailed) {
|
||||
if (newNetwork) {
|
||||
WifiNative.removeNetwork(netId);
|
||||
mWifiNative.removeNetwork(netId);
|
||||
loge("Failed to set a network variable, removed network: " + netId);
|
||||
}
|
||||
return new NetworkUpdateResult(INVALID_NETWORK_ID);
|
||||
}
|
||||
|
||||
/* An update of the network variables requires reading them
|
||||
* back from the supplicant to update sConfiguredNetworks.
|
||||
* back from the supplicant to update mConfiguredNetworks.
|
||||
* This is because some of the variables (SSID, wep keys &
|
||||
* passphrases) reflect different values when read back than
|
||||
* when written. For example, wep key is stored as * irrespective
|
||||
* of the value sent to the supplicant
|
||||
*/
|
||||
WifiConfiguration sConfig = sConfiguredNetworks.get(netId);
|
||||
if (sConfig == null) {
|
||||
sConfig = new WifiConfiguration();
|
||||
sConfig.networkId = netId;
|
||||
WifiConfiguration currentConfig = mConfiguredNetworks.get(netId);
|
||||
if (currentConfig == null) {
|
||||
currentConfig = new WifiConfiguration();
|
||||
currentConfig.networkId = netId;
|
||||
}
|
||||
|
||||
readNetworkVariables(sConfig);
|
||||
readNetworkVariables(currentConfig);
|
||||
|
||||
sConfiguredNetworks.put(netId, sConfig);
|
||||
sNetworkIds.put(configKey(sConfig), netId);
|
||||
mConfiguredNetworks.put(netId, currentConfig);
|
||||
mNetworkIds.put(configKey(currentConfig), netId);
|
||||
|
||||
NetworkUpdateResult result = writeIpAndProxyConfigurationsOnChange(sConfig, config);
|
||||
NetworkUpdateResult result = writeIpAndProxyConfigurationsOnChange(currentConfig, config);
|
||||
result.setNetworkId(netId);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Compare current and new configuration and write to file on change */
|
||||
private static NetworkUpdateResult writeIpAndProxyConfigurationsOnChange(
|
||||
private NetworkUpdateResult writeIpAndProxyConfigurationsOnChange(
|
||||
WifiConfiguration currentConfig,
|
||||
WifiConfiguration newConfig) {
|
||||
boolean ipChanged = false;
|
||||
@@ -1216,7 +1225,7 @@ class WifiConfigStore {
|
||||
return new NetworkUpdateResult(ipChanged, proxyChanged);
|
||||
}
|
||||
|
||||
private static void addIpSettingsFromConfig(LinkProperties linkProperties,
|
||||
private void addIpSettingsFromConfig(LinkProperties linkProperties,
|
||||
WifiConfiguration config) {
|
||||
for (LinkAddress linkAddr : config.linkProperties.getLinkAddresses()) {
|
||||
linkProperties.addLinkAddress(linkAddr);
|
||||
@@ -1235,7 +1244,7 @@ class WifiConfigStore {
|
||||
*
|
||||
* @param config the {@link WifiConfiguration} object to be filled in.
|
||||
*/
|
||||
private static void readNetworkVariables(WifiConfiguration config) {
|
||||
private void readNetworkVariables(WifiConfiguration config) {
|
||||
|
||||
int netId = config.networkId;
|
||||
if (netId < 0)
|
||||
@@ -1248,21 +1257,21 @@ class WifiConfigStore {
|
||||
*/
|
||||
String value;
|
||||
|
||||
value = WifiNative.getNetworkVariable(netId, WifiConfiguration.ssidVarName);
|
||||
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.ssidVarName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
config.SSID = value;
|
||||
} else {
|
||||
config.SSID = null;
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(netId, WifiConfiguration.bssidVarName);
|
||||
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.bssidVarName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
config.BSSID = value;
|
||||
} else {
|
||||
config.BSSID = null;
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(netId, WifiConfiguration.priorityVarName);
|
||||
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.priorityVarName);
|
||||
config.priority = -1;
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
try {
|
||||
@@ -1271,7 +1280,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(netId, WifiConfiguration.hiddenSSIDVarName);
|
||||
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.hiddenSSIDVarName);
|
||||
config.hiddenSSID = false;
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
try {
|
||||
@@ -1280,7 +1289,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(netId, WifiConfiguration.wepTxKeyIdxVarName);
|
||||
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.wepTxKeyIdxVarName);
|
||||
config.wepTxKeyIndex = -1;
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
try {
|
||||
@@ -1290,7 +1299,7 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
value = WifiNative.getNetworkVariable(netId,
|
||||
value = mWifiNative.getNetworkVariable(netId,
|
||||
WifiConfiguration.wepKeyVarNames[i]);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
config.wepKeys[i] = value;
|
||||
@@ -1299,14 +1308,14 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(netId, WifiConfiguration.pskVarName);
|
||||
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.pskVarName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
config.preSharedKey = value;
|
||||
} else {
|
||||
config.preSharedKey = null;
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(config.networkId,
|
||||
value = mWifiNative.getNetworkVariable(config.networkId,
|
||||
WifiConfiguration.Protocol.varName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
String vals[] = value.split(" ");
|
||||
@@ -1319,7 +1328,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(config.networkId,
|
||||
value = mWifiNative.getNetworkVariable(config.networkId,
|
||||
WifiConfiguration.KeyMgmt.varName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
String vals[] = value.split(" ");
|
||||
@@ -1332,7 +1341,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(config.networkId,
|
||||
value = mWifiNative.getNetworkVariable(config.networkId,
|
||||
WifiConfiguration.AuthAlgorithm.varName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
String vals[] = value.split(" ");
|
||||
@@ -1345,7 +1354,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(config.networkId,
|
||||
value = mWifiNative.getNetworkVariable(config.networkId,
|
||||
WifiConfiguration.PairwiseCipher.varName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
String vals[] = value.split(" ");
|
||||
@@ -1358,7 +1367,7 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
value = WifiNative.getNetworkVariable(config.networkId,
|
||||
value = mWifiNative.getNetworkVariable(config.networkId,
|
||||
WifiConfiguration.GroupCipher.varName);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
String vals[] = value.split(" ");
|
||||
@@ -1373,7 +1382,7 @@ class WifiConfigStore {
|
||||
|
||||
for (WifiConfiguration.EnterpriseField field :
|
||||
config.enterpriseFields) {
|
||||
value = WifiNative.getNetworkVariable(netId,
|
||||
value = mWifiNative.getNetworkVariable(netId,
|
||||
field.varName());
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
if (field != config.eap) value = removeDoubleQuotes(value);
|
||||
@@ -1382,16 +1391,16 @@ class WifiConfigStore {
|
||||
}
|
||||
}
|
||||
|
||||
private static String removeDoubleQuotes(String string) {
|
||||
private String removeDoubleQuotes(String string) {
|
||||
if (string.length() <= 2) return "";
|
||||
return string.substring(1, string.length() - 1);
|
||||
}
|
||||
|
||||
private static String convertToQuotedString(String string) {
|
||||
private String convertToQuotedString(String string) {
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
|
||||
private static String makeString(BitSet set, String[] strings) {
|
||||
private String makeString(BitSet set, String[] strings) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int nextSetBit = -1;
|
||||
|
||||
@@ -1411,7 +1420,7 @@ class WifiConfigStore {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static int lookupString(String string, String[] strings) {
|
||||
private int lookupString(String string, String[] strings) {
|
||||
int size = strings.length;
|
||||
|
||||
string = string.replace('-', '_');
|
||||
@@ -1446,10 +1455,10 @@ class WifiConfigStore {
|
||||
return key.hashCode();
|
||||
}
|
||||
|
||||
static String dump() {
|
||||
String dump() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String LS = System.getProperty("line.separator");
|
||||
sb.append("sLastPriority ").append(sLastPriority).append(LS);
|
||||
sb.append("mLastPriority ").append(mLastPriority).append(LS);
|
||||
sb.append("Configured networks ").append(LS);
|
||||
for (WifiConfiguration conf : getConfiguredNetworks()) {
|
||||
sb.append(conf).append(LS);
|
||||
@@ -1457,15 +1466,15 @@ class WifiConfigStore {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getConfigFile() {
|
||||
public String getConfigFile() {
|
||||
return ipConfigFile;
|
||||
}
|
||||
|
||||
private static void loge(String s) {
|
||||
private void loge(String s) {
|
||||
Log.e(TAG, s);
|
||||
}
|
||||
|
||||
private static void log(String s) {
|
||||
private void log(String s) {
|
||||
Log.d(TAG, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +202,7 @@ public class WifiMonitor {
|
||||
private static final String AP_STA_DISCONNECTED_STR = "AP-STA-DISCONNECTED";
|
||||
|
||||
private final StateMachine mStateMachine;
|
||||
private final WifiNative mWifiNative;
|
||||
|
||||
/* Supplicant events reported to a state machine */
|
||||
private static final int BASE = Protocol.BASE_WIFI_MONITOR;
|
||||
@@ -266,8 +267,9 @@ public class WifiMonitor {
|
||||
*/
|
||||
private static final int MAX_RECV_ERRORS = 10;
|
||||
|
||||
public WifiMonitor(StateMachine wifiStateMachine) {
|
||||
public WifiMonitor(StateMachine wifiStateMachine, WifiNative wifiNative) {
|
||||
mStateMachine = wifiStateMachine;
|
||||
mWifiNative = wifiNative;
|
||||
}
|
||||
|
||||
public void startMonitoring() {
|
||||
@@ -292,7 +294,7 @@ public class WifiMonitor {
|
||||
|
||||
//noinspection InfiniteLoopStatement
|
||||
for (;;) {
|
||||
String eventStr = WifiNative.waitForEvent();
|
||||
String eventStr = mWifiNative.waitForEvent();
|
||||
|
||||
// Skip logging the common but mostly uninteresting scan-results event
|
||||
if (false && eventStr.indexOf(SCAN_RESULTS_STR) == -1) {
|
||||
@@ -406,7 +408,7 @@ public class WifiMonitor {
|
||||
int connectTries = 0;
|
||||
|
||||
while (true) {
|
||||
if (WifiNative.connectToSupplicant()) {
|
||||
if (mWifiNative.connectToSupplicant()) {
|
||||
return true;
|
||||
}
|
||||
if (connectTries++ < 5) {
|
||||
|
||||
@@ -39,11 +39,13 @@ import java.util.List;
|
||||
*/
|
||||
public class WifiNative {
|
||||
|
||||
private static final int DEFAULT_GROUP_OWNER_INTENT = 7;
|
||||
|
||||
static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0;
|
||||
static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1;
|
||||
static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2;
|
||||
|
||||
static String sDefaultInterface;
|
||||
String mInterface = "";
|
||||
|
||||
public native static boolean loadDriver();
|
||||
|
||||
@@ -59,60 +61,60 @@ public class WifiNative {
|
||||
or when the supplicant is hung */
|
||||
public native static boolean killSupplicant();
|
||||
|
||||
public native static boolean connectToSupplicant(String iface);
|
||||
private native boolean connectToSupplicant(String iface);
|
||||
|
||||
public native static void closeSupplicantConnection(String iface);
|
||||
private native void closeSupplicantConnection(String iface);
|
||||
|
||||
/**
|
||||
* Wait for the supplicant to send an event, returning the event string.
|
||||
* @return the event string sent by the supplicant.
|
||||
*/
|
||||
public native static String waitForEvent(String iface);
|
||||
private native String waitForEvent(String iface);
|
||||
|
||||
private native static boolean doBooleanCommand(String iface, String command);
|
||||
private native boolean doBooleanCommand(String iface, String command);
|
||||
|
||||
private native static int doIntCommand(String iface, String command);
|
||||
private native int doIntCommand(String iface, String command);
|
||||
|
||||
private native static String doStringCommand(String iface, String command);
|
||||
private native String doStringCommand(String iface, String command);
|
||||
|
||||
public static void setDefaultInterface(String iface) {
|
||||
sDefaultInterface = iface;
|
||||
public WifiNative(String iface) {
|
||||
mInterface = iface;
|
||||
}
|
||||
|
||||
public static boolean connectToSupplicant() {
|
||||
return connectToSupplicant(sDefaultInterface);
|
||||
public boolean connectToSupplicant() {
|
||||
return connectToSupplicant(mInterface);
|
||||
}
|
||||
|
||||
public static void closeSupplicantConnection() {
|
||||
closeSupplicantConnection(sDefaultInterface);
|
||||
public void closeSupplicantConnection() {
|
||||
closeSupplicantConnection(mInterface);
|
||||
}
|
||||
|
||||
public static String waitForEvent() {
|
||||
return waitForEvent(sDefaultInterface);
|
||||
public String waitForEvent() {
|
||||
return waitForEvent(mInterface);
|
||||
}
|
||||
|
||||
private static boolean doBooleanCommand(String command) {
|
||||
return doBooleanCommand(sDefaultInterface, command);
|
||||
private boolean doBooleanCommand(String command) {
|
||||
return doBooleanCommand(mInterface, command);
|
||||
}
|
||||
|
||||
private static int doIntCommand(String command) {
|
||||
return doIntCommand(sDefaultInterface, command);
|
||||
private int doIntCommand(String command) {
|
||||
return doIntCommand(mInterface, command);
|
||||
}
|
||||
|
||||
private static String doStringCommand(String command) {
|
||||
return doStringCommand(sDefaultInterface, command);
|
||||
private String doStringCommand(String command) {
|
||||
return doStringCommand(mInterface, command);
|
||||
}
|
||||
|
||||
public static boolean ping() {
|
||||
public boolean ping() {
|
||||
String pong = doStringCommand("PING");
|
||||
return (pong != null && pong.equals("PONG"));
|
||||
}
|
||||
|
||||
public static boolean scan() {
|
||||
public boolean scan() {
|
||||
return doBooleanCommand("SCAN");
|
||||
}
|
||||
|
||||
public static boolean setScanMode(boolean setActive) {
|
||||
public boolean setScanMode(boolean setActive) {
|
||||
if (setActive) {
|
||||
return doBooleanCommand("DRIVER SCAN-ACTIVE");
|
||||
} else {
|
||||
@@ -126,33 +128,33 @@ public class WifiNative {
|
||||
* for a graceful stop and a mild-sounding "stop" interface
|
||||
* to kill the process
|
||||
*/
|
||||
public static boolean stopSupplicant() {
|
||||
public boolean stopSupplicant() {
|
||||
return doBooleanCommand("TERMINATE");
|
||||
}
|
||||
|
||||
public static String listNetworks() {
|
||||
public String listNetworks() {
|
||||
return doStringCommand("LIST_NETWORKS");
|
||||
}
|
||||
|
||||
public static int addNetwork() {
|
||||
public int addNetwork() {
|
||||
return doIntCommand("ADD_NETWORK");
|
||||
}
|
||||
|
||||
public static boolean setNetworkVariable(int netId, String name, String value) {
|
||||
public boolean setNetworkVariable(int netId, String name, String value) {
|
||||
if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false;
|
||||
return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value);
|
||||
}
|
||||
|
||||
public static String getNetworkVariable(int netId, String name) {
|
||||
public String getNetworkVariable(int netId, String name) {
|
||||
if (TextUtils.isEmpty(name)) return null;
|
||||
return doStringCommand("GET_NETWORK " + netId + " " + name);
|
||||
}
|
||||
|
||||
public static boolean removeNetwork(int netId) {
|
||||
public boolean removeNetwork(int netId) {
|
||||
return doBooleanCommand("REMOVE_NETWORK " + netId);
|
||||
}
|
||||
|
||||
public static boolean enableNetwork(int netId, boolean disableOthers) {
|
||||
public boolean enableNetwork(int netId, boolean disableOthers) {
|
||||
if (disableOthers) {
|
||||
return doBooleanCommand("SELECT_NETWORK " + netId);
|
||||
} else {
|
||||
@@ -160,27 +162,27 @@ public class WifiNative {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean disableNetwork(int netId) {
|
||||
public boolean disableNetwork(int netId) {
|
||||
return doBooleanCommand("DISABLE_NETWORK " + netId);
|
||||
}
|
||||
|
||||
public static boolean reconnect() {
|
||||
public boolean reconnect() {
|
||||
return doBooleanCommand("RECONNECT");
|
||||
}
|
||||
|
||||
public static boolean reassociate() {
|
||||
public boolean reassociate() {
|
||||
return doBooleanCommand("REASSOCIATE");
|
||||
}
|
||||
|
||||
public static boolean disconnect() {
|
||||
public boolean disconnect() {
|
||||
return doBooleanCommand("DISCONNECT");
|
||||
}
|
||||
|
||||
public static String status() {
|
||||
public String status() {
|
||||
return doStringCommand("STATUS");
|
||||
}
|
||||
|
||||
public static String getMacAddress() {
|
||||
public String getMacAddress() {
|
||||
//Macaddr = XX.XX.XX.XX.XX.XX
|
||||
String ret = doStringCommand("DRIVER MACADDR");
|
||||
if (!TextUtils.isEmpty(ret)) {
|
||||
@@ -190,15 +192,15 @@ public class WifiNative {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String scanResults() {
|
||||
public String scanResults() {
|
||||
return doStringCommand("SCAN_RESULTS");
|
||||
}
|
||||
|
||||
public static boolean startDriver() {
|
||||
public boolean startDriver() {
|
||||
return doBooleanCommand("DRIVER START");
|
||||
}
|
||||
|
||||
public static boolean stopDriver() {
|
||||
public boolean stopDriver() {
|
||||
return doBooleanCommand("DRIVER STOP");
|
||||
}
|
||||
|
||||
@@ -227,7 +229,7 @@ public class WifiNative {
|
||||
*
|
||||
* The SETSUSPENDOPT driver command overrides the filtering rules
|
||||
*/
|
||||
public static boolean startFilteringMulticastV4Packets() {
|
||||
public boolean startFilteringMulticastV4Packets() {
|
||||
return doBooleanCommand("DRIVER RXFILTER-STOP")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-REMOVE 2")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-START");
|
||||
@@ -237,7 +239,7 @@ public class WifiNative {
|
||||
* Stop filtering out Multicast V4 packets.
|
||||
* @return {@code true} if the operation succeeded, {@code false} otherwise
|
||||
*/
|
||||
public static boolean stopFilteringMulticastV4Packets() {
|
||||
public boolean stopFilteringMulticastV4Packets() {
|
||||
return doBooleanCommand("DRIVER RXFILTER-STOP")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-ADD 2")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-START");
|
||||
@@ -247,7 +249,7 @@ public class WifiNative {
|
||||
* Start filtering out Multicast V6 packets
|
||||
* @return {@code true} if the operation succeeded, {@code false} otherwise
|
||||
*/
|
||||
public static boolean startFilteringMulticastV6Packets() {
|
||||
public boolean startFilteringMulticastV6Packets() {
|
||||
return doBooleanCommand("DRIVER RXFILTER-STOP")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-REMOVE 3")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-START");
|
||||
@@ -257,13 +259,13 @@ public class WifiNative {
|
||||
* Stop filtering out Multicast V6 packets.
|
||||
* @return {@code true} if the operation succeeded, {@code false} otherwise
|
||||
*/
|
||||
public static boolean stopFilteringMulticastV6Packets() {
|
||||
public boolean stopFilteringMulticastV6Packets() {
|
||||
return doBooleanCommand("DRIVER RXFILTER-STOP")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-ADD 3")
|
||||
&& doBooleanCommand("DRIVER RXFILTER-START");
|
||||
}
|
||||
|
||||
public static int getPowerMode() {
|
||||
public int getPowerMode() {
|
||||
String ret = doStringCommand("DRIVER GETPOWER");
|
||||
if (!TextUtils.isEmpty(ret)) {
|
||||
// reply comes back in the form "powermode = XX" where XX is the
|
||||
@@ -278,11 +280,11 @@ public class WifiNative {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean setPowerMode(int mode) {
|
||||
public boolean setPowerMode(int mode) {
|
||||
return doBooleanCommand("DRIVER POWERMODE " + mode);
|
||||
}
|
||||
|
||||
public static int getBand() {
|
||||
public int getBand() {
|
||||
String ret = doStringCommand("DRIVER GETBAND");
|
||||
if (!TextUtils.isEmpty(ret)) {
|
||||
//reply is "BAND X" where X is the band
|
||||
@@ -296,7 +298,7 @@ public class WifiNative {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean setBand(int band) {
|
||||
public boolean setBand(int band) {
|
||||
return doBooleanCommand("DRIVER SETBAND " + band);
|
||||
}
|
||||
|
||||
@@ -308,7 +310,7 @@ public class WifiNative {
|
||||
* {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}.
|
||||
* @return Whether the mode was successfully set.
|
||||
*/
|
||||
public static boolean setBluetoothCoexistenceMode(int mode) {
|
||||
public boolean setBluetoothCoexistenceMode(int mode) {
|
||||
return doBooleanCommand("DRIVER BTCOEXMODE " + mode);
|
||||
}
|
||||
|
||||
@@ -320,7 +322,7 @@ public class WifiNative {
|
||||
* @param isSet whether to enable or disable this mode
|
||||
* @return {@code true} if the command succeeded, {@code false} otherwise.
|
||||
*/
|
||||
public static boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) {
|
||||
public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) {
|
||||
if (setCoexScanMode) {
|
||||
return doBooleanCommand("DRIVER BTCOEXSCAN-START");
|
||||
} else {
|
||||
@@ -328,25 +330,25 @@ public class WifiNative {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean saveConfig() {
|
||||
public boolean saveConfig() {
|
||||
// Make sure we never write out a value for AP_SCAN other than 1
|
||||
return doBooleanCommand("AP_SCAN 1") && doBooleanCommand("SAVE_CONFIG");
|
||||
}
|
||||
|
||||
public static boolean setScanResultHandling(int mode) {
|
||||
public boolean setScanResultHandling(int mode) {
|
||||
return doBooleanCommand("AP_SCAN " + mode);
|
||||
}
|
||||
|
||||
public static boolean addToBlacklist(String bssid) {
|
||||
public boolean addToBlacklist(String bssid) {
|
||||
if (TextUtils.isEmpty(bssid)) return false;
|
||||
return doBooleanCommand("BLACKLIST " + bssid);
|
||||
}
|
||||
|
||||
public static boolean clearBlacklist() {
|
||||
public boolean clearBlacklist() {
|
||||
return doBooleanCommand("BLACKLIST clear");
|
||||
}
|
||||
|
||||
public static boolean setSuspendOptimizations(boolean enabled) {
|
||||
public boolean setSuspendOptimizations(boolean enabled) {
|
||||
if (enabled) {
|
||||
return doBooleanCommand("DRIVER SETSUSPENDOPT 0");
|
||||
} else {
|
||||
@@ -354,11 +356,11 @@ public class WifiNative {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean setCountryCode(String countryCode) {
|
||||
public boolean setCountryCode(String countryCode) {
|
||||
return doBooleanCommand("DRIVER COUNTRY " + countryCode);
|
||||
}
|
||||
|
||||
public static void enableBackgroundScan(boolean enable) {
|
||||
public void enableBackgroundScan(boolean enable) {
|
||||
//Note: BGSCAN-START and BGSCAN-STOP are documented in core/res/res/values/config.xml
|
||||
//and will need an update if the names are changed
|
||||
if (enable) {
|
||||
@@ -368,7 +370,7 @@ public class WifiNative {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setScanInterval(int scanInterval) {
|
||||
public void setScanInterval(int scanInterval) {
|
||||
doBooleanCommand("SCAN_INTERVAL " + scanInterval);
|
||||
}
|
||||
|
||||
@@ -378,81 +380,81 @@ public class WifiNative {
|
||||
* NOISE=9999
|
||||
* FREQUENCY=0
|
||||
*/
|
||||
public static String signalPoll() {
|
||||
public String signalPoll() {
|
||||
return doStringCommand("SIGNAL_POLL");
|
||||
}
|
||||
|
||||
public static boolean startWpsPbc() {
|
||||
public boolean startWpsPbc() {
|
||||
return doBooleanCommand("WPS_PBC");
|
||||
}
|
||||
|
||||
public static boolean startWpsPbc(String bssid) {
|
||||
public boolean startWpsPbc(String bssid) {
|
||||
return doBooleanCommand("WPS_PBC " + bssid);
|
||||
}
|
||||
|
||||
public static boolean startWpsPinKeypad(String pin) {
|
||||
public boolean startWpsPinKeypad(String pin) {
|
||||
return doBooleanCommand("WPS_PIN any " + pin);
|
||||
}
|
||||
|
||||
public static String startWpsPinDisplay(String bssid) {
|
||||
public String startWpsPinDisplay(String bssid) {
|
||||
return doStringCommand("WPS_PIN " + bssid);
|
||||
}
|
||||
|
||||
/* Configures an access point connection */
|
||||
public static boolean startWpsRegistrar(String bssid, String pin) {
|
||||
public boolean startWpsRegistrar(String bssid, String pin) {
|
||||
return doBooleanCommand("WPS_REG " + bssid + " " + pin);
|
||||
}
|
||||
|
||||
public static boolean setPersistentReconnect(boolean enabled) {
|
||||
public boolean setPersistentReconnect(boolean enabled) {
|
||||
int value = (enabled == true) ? 1 : 0;
|
||||
return doBooleanCommand("SET persistent_reconnect " + value);
|
||||
}
|
||||
|
||||
public static boolean setDeviceName(String name) {
|
||||
public boolean setDeviceName(String name) {
|
||||
return doBooleanCommand("SET device_name " + name);
|
||||
}
|
||||
|
||||
public static boolean setDeviceType(String type) {
|
||||
public boolean setDeviceType(String type) {
|
||||
return doBooleanCommand("SET device_type " + type);
|
||||
}
|
||||
|
||||
public static boolean setConfigMethods(String cfg) {
|
||||
public boolean setConfigMethods(String cfg) {
|
||||
return doBooleanCommand("SET config_methods " + cfg);
|
||||
}
|
||||
|
||||
public static boolean setP2pSsidPostfix(String postfix) {
|
||||
public boolean setP2pSsidPostfix(String postfix) {
|
||||
return doBooleanCommand("SET p2p_ssid_postfix " + postfix);
|
||||
}
|
||||
|
||||
public static boolean p2pFind() {
|
||||
public boolean p2pFind() {
|
||||
return doBooleanCommand("P2P_FIND");
|
||||
}
|
||||
|
||||
public static boolean p2pFind(int timeout) {
|
||||
public boolean p2pFind(int timeout) {
|
||||
if (timeout <= 0) {
|
||||
return p2pFind();
|
||||
}
|
||||
return doBooleanCommand("P2P_FIND " + timeout);
|
||||
}
|
||||
|
||||
public static boolean p2pListen() {
|
||||
public boolean p2pListen() {
|
||||
return doBooleanCommand("P2P_LISTEN");
|
||||
}
|
||||
|
||||
public static boolean p2pListen(int timeout) {
|
||||
public boolean p2pListen(int timeout) {
|
||||
if (timeout <= 0) {
|
||||
return p2pListen();
|
||||
}
|
||||
return doBooleanCommand("P2P_LISTEN " + timeout);
|
||||
}
|
||||
|
||||
public static boolean p2pFlush() {
|
||||
public boolean p2pFlush() {
|
||||
return doBooleanCommand("P2P_FLUSH");
|
||||
}
|
||||
|
||||
/* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad]
|
||||
[persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */
|
||||
public static String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) {
|
||||
public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) {
|
||||
if (config == null) return null;
|
||||
List<String> args = new ArrayList<String>();
|
||||
WpsInfo wps = config.wps;
|
||||
@@ -492,7 +494,7 @@ public class WifiNative {
|
||||
//device battery state
|
||||
int groupOwnerIntent = config.groupOwnerIntent;
|
||||
if (groupOwnerIntent < 0 || groupOwnerIntent > 15) {
|
||||
groupOwnerIntent = 7; //default value
|
||||
groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT;
|
||||
}
|
||||
args.add("go_intent=" + groupOwnerIntent);
|
||||
|
||||
@@ -502,11 +504,11 @@ public class WifiNative {
|
||||
return doStringCommand(command);
|
||||
}
|
||||
|
||||
public static boolean p2pCancelConnect() {
|
||||
public boolean p2pCancelConnect() {
|
||||
return doBooleanCommand("P2P_CANCEL");
|
||||
}
|
||||
|
||||
public static boolean p2pProvisionDiscovery(WifiP2pConfig config) {
|
||||
public boolean p2pProvisionDiscovery(WifiP2pConfig config) {
|
||||
if (config == null) return false;
|
||||
|
||||
switch (config.wps.setup) {
|
||||
@@ -524,21 +526,21 @@ public class WifiNative {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean p2pGroupAdd() {
|
||||
public boolean p2pGroupAdd() {
|
||||
return doBooleanCommand("P2P_GROUP_ADD");
|
||||
}
|
||||
|
||||
public static boolean p2pGroupRemove(String iface) {
|
||||
public boolean p2pGroupRemove(String iface) {
|
||||
if (iface == null) return false;
|
||||
return doBooleanCommand("P2P_GROUP_REMOVE " + iface);
|
||||
}
|
||||
|
||||
public static boolean p2pReject(String deviceAddress) {
|
||||
public boolean p2pReject(String deviceAddress) {
|
||||
return doBooleanCommand("P2P_REJECT " + deviceAddress);
|
||||
}
|
||||
|
||||
/* Invite a peer to a group */
|
||||
public static boolean p2pInvite(WifiP2pGroup group, String deviceAddress) {
|
||||
public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) {
|
||||
if (deviceAddress == null) return false;
|
||||
|
||||
if (group == null) {
|
||||
@@ -550,14 +552,14 @@ public class WifiNative {
|
||||
}
|
||||
|
||||
/* Reinvoke a persistent connection */
|
||||
public static boolean p2pReinvoke(int netId, String deviceAddress) {
|
||||
public boolean p2pReinvoke(int netId, String deviceAddress) {
|
||||
if (deviceAddress == null || netId < 0) return false;
|
||||
|
||||
return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress);
|
||||
}
|
||||
|
||||
|
||||
public static String p2pGetInterfaceAddress(String deviceAddress) {
|
||||
public String p2pGetInterfaceAddress(String deviceAddress) {
|
||||
if (deviceAddress == null) return null;
|
||||
|
||||
// "p2p_peer deviceAddress" returns a multi-line result containing
|
||||
@@ -577,7 +579,7 @@ public class WifiNative {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String p2pGetDeviceAddress() {
|
||||
public String p2pGetDeviceAddress() {
|
||||
String status = status();
|
||||
if (status == null) return "";
|
||||
|
||||
@@ -592,7 +594,7 @@ public class WifiNative {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String p2pPeer(String deviceAddress) {
|
||||
public String p2pPeer(String deviceAddress) {
|
||||
return doStringCommand("P2P_PEER " + deviceAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ public class WifiStateMachine extends StateMachine {
|
||||
private static final String SOFTAP_IFACE = "wl0.1";
|
||||
|
||||
private WifiMonitor mWifiMonitor;
|
||||
private WifiNative mWifiNative;
|
||||
private WifiConfigStore mWifiConfigStore;
|
||||
private INetworkManagementService mNwService;
|
||||
private ConnectivityManager mCm;
|
||||
|
||||
@@ -554,11 +556,14 @@ public class WifiStateMachine extends StateMachine {
|
||||
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
|
||||
mNwService = INetworkManagementService.Stub.asInterface(b);
|
||||
|
||||
mWifiMonitor = new WifiMonitor(this);
|
||||
mWifiNative = new WifiNative(mInterfaceName);
|
||||
mWifiConfigStore = new WifiConfigStore(context, mWifiNative);
|
||||
mWifiMonitor = new WifiMonitor(this, mWifiNative);
|
||||
mDhcpInfoInternal = new DhcpInfoInternal();
|
||||
mWifiInfo = new WifiInfo();
|
||||
mSupplicantStateTracker = new SupplicantStateTracker(context, this, getHandler());
|
||||
mWpsStateMachine = new WpsStateMachine(context, this, getHandler());
|
||||
mSupplicantStateTracker = new SupplicantStateTracker(context, this, mWifiConfigStore,
|
||||
getHandler());
|
||||
mWpsStateMachine = new WpsStateMachine(context, this, mWifiConfigStore, getHandler());
|
||||
mLinkProperties = new LinkProperties();
|
||||
|
||||
WifiApConfigStore wifiApConfigStore = WifiApConfigStore.makeWifiApConfigStore(
|
||||
@@ -572,9 +577,6 @@ public class WifiStateMachine extends StateMachine {
|
||||
mLastNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
mLastSignalLevel = -1;
|
||||
|
||||
/* Set default interface for all primary socket communication */
|
||||
WifiNative.setDefaultInterface(mInterfaceName);
|
||||
|
||||
mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
|
||||
Intent scanIntent = new Intent(ACTION_START_SCAN, null);
|
||||
mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0);
|
||||
@@ -1044,7 +1046,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
* Returns the wifi configuration file
|
||||
*/
|
||||
public String getConfigFile() {
|
||||
return WifiConfigStore.getConfigFile();
|
||||
return mWifiConfigStore.getConfigFile();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1118,9 +1120,9 @@ public class WifiStateMachine extends StateMachine {
|
||||
sb.append("mReconnectCount ").append(mReconnectCount).append(LS);
|
||||
sb.append("mIsScanMode ").append(mIsScanMode).append(LS);
|
||||
sb.append("Supplicant status").append(LS)
|
||||
.append(WifiNative.status()).append(LS).append(LS);
|
||||
.append(mWifiNative.status()).append(LS).append(LS);
|
||||
|
||||
sb.append(WifiConfigStore.dump());
|
||||
sb.append(mWifiConfigStore.dump());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -1413,7 +1415,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
}
|
||||
|
||||
private String fetchSSID() {
|
||||
String status = WifiNative.status();
|
||||
String status = mWifiNative.status();
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -1436,7 +1438,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
int newRssi = -1;
|
||||
int newLinkSpeed = -1;
|
||||
|
||||
String signalPoll = WifiNative.signalPoll();
|
||||
String signalPoll = mWifiNative.signalPoll();
|
||||
|
||||
if (signalPoll != null) {
|
||||
String[] lines = signalPoll.split("\n");
|
||||
@@ -1486,28 +1488,28 @@ public class WifiStateMachine extends StateMachine {
|
||||
}
|
||||
|
||||
private void setHighPerfModeEnabledNative(boolean enable) {
|
||||
if(!WifiNative.setSuspendOptimizations(!enable)) {
|
||||
if(!mWifiNative.setSuspendOptimizations(!enable)) {
|
||||
loge("set suspend optimizations failed!");
|
||||
}
|
||||
if (enable) {
|
||||
if (!WifiNative.setPowerMode(POWER_MODE_ACTIVE)) {
|
||||
if (!mWifiNative.setPowerMode(POWER_MODE_ACTIVE)) {
|
||||
loge("set power mode active failed!");
|
||||
}
|
||||
} else {
|
||||
if (!WifiNative.setPowerMode(POWER_MODE_AUTO)) {
|
||||
if (!mWifiNative.setPowerMode(POWER_MODE_AUTO)) {
|
||||
loge("set power mode auto failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configureLinkProperties() {
|
||||
if (WifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
|
||||
mLinkProperties = WifiConfigStore.getLinkProperties(mLastNetworkId);
|
||||
if (mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
|
||||
mLinkProperties = mWifiConfigStore.getLinkProperties(mLastNetworkId);
|
||||
} else {
|
||||
synchronized (mDhcpInfoInternal) {
|
||||
mLinkProperties = mDhcpInfoInternal.makeLinkProperties();
|
||||
}
|
||||
mLinkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId));
|
||||
mLinkProperties.setHttpProxy(mWifiConfigStore.getProxyProperties(mLastNetworkId));
|
||||
}
|
||||
mLinkProperties.setInterfaceName(mInterfaceName);
|
||||
if (DBG) {
|
||||
@@ -1648,7 +1650,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
mWifiInfo.setLinkSpeed(-1);
|
||||
|
||||
setNetworkDetailedState(DetailedState.DISCONNECTED);
|
||||
WifiConfigStore.updateStatus(mLastNetworkId, DetailedState.DISCONNECTED);
|
||||
mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.DISCONNECTED);
|
||||
|
||||
/* send event to CM & network change broadcast */
|
||||
sendNetworkStateChangeBroadcast(mLastBssid);
|
||||
@@ -1656,8 +1658,8 @@ public class WifiStateMachine extends StateMachine {
|
||||
/* Clear network properties */
|
||||
mLinkProperties.clear();
|
||||
/* Clear IP settings if the network used DHCP */
|
||||
if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
|
||||
WifiConfigStore.clearIpConfiguration(mLastNetworkId);
|
||||
if (!mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
|
||||
mWifiConfigStore.clearIpConfiguration(mLastNetworkId);
|
||||
}
|
||||
|
||||
mLastBssid= null;
|
||||
@@ -1683,29 +1685,29 @@ public class WifiStateMachine extends StateMachine {
|
||||
* coexistence would interrupt that connection.
|
||||
*/
|
||||
// Disable the coexistence mode
|
||||
WifiNative.setBluetoothCoexistenceMode(
|
||||
WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
|
||||
mWifiNative.setBluetoothCoexistenceMode(
|
||||
mWifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
|
||||
}
|
||||
|
||||
mPowerMode = WifiNative.getPowerMode();
|
||||
mPowerMode = mWifiNative.getPowerMode();
|
||||
if (mPowerMode < 0) {
|
||||
// Handle the case where supplicant driver does not support
|
||||
// getPowerModeCommand.
|
||||
mPowerMode = WifiStateMachine.POWER_MODE_AUTO;
|
||||
}
|
||||
if (mPowerMode != WifiStateMachine.POWER_MODE_ACTIVE) {
|
||||
WifiNative.setPowerMode(WifiStateMachine.POWER_MODE_ACTIVE);
|
||||
mWifiNative.setPowerMode(WifiStateMachine.POWER_MODE_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handlePostDhcpSetup() {
|
||||
/* restore power mode */
|
||||
WifiNative.setPowerMode(mPowerMode);
|
||||
mWifiNative.setPowerMode(mPowerMode);
|
||||
|
||||
// Set the coexistence mode back to its default value
|
||||
WifiNative.setBluetoothCoexistenceMode(
|
||||
WifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE);
|
||||
mWifiNative.setBluetoothCoexistenceMode(
|
||||
mWifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE);
|
||||
}
|
||||
|
||||
private void handleSuccessfulIpConfiguration(DhcpInfoInternal dhcpInfoInternal) {
|
||||
@@ -1714,13 +1716,13 @@ public class WifiStateMachine extends StateMachine {
|
||||
}
|
||||
mLastSignalLevel = -1; // force update of signal strength
|
||||
mReconnectCount = 0; //Reset IP failure tracking
|
||||
WifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal);
|
||||
mWifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal);
|
||||
InetAddress addr = NetworkUtils.numericToInetAddress(dhcpInfoInternal.ipAddress);
|
||||
mWifiInfo.setInetAddress(addr);
|
||||
if (getNetworkDetailedState() == DetailedState.CONNECTED) {
|
||||
//DHCP renewal in connected state
|
||||
LinkProperties linkProperties = dhcpInfoInternal.makeLinkProperties();
|
||||
linkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId));
|
||||
linkProperties.setHttpProxy(mWifiConfigStore.getProxyProperties(mLastNetworkId));
|
||||
linkProperties.setInterfaceName(mInterfaceName);
|
||||
if (!linkProperties.equals(mLinkProperties)) {
|
||||
if (DBG) {
|
||||
@@ -1733,7 +1735,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
} else {
|
||||
configureLinkProperties();
|
||||
setNetworkDetailedState(DetailedState.CONNECTED);
|
||||
WifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CONNECTED);
|
||||
mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CONNECTED);
|
||||
sendNetworkStateChangeBroadcast(mLastBssid);
|
||||
}
|
||||
}
|
||||
@@ -1749,7 +1751,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
if (++mReconnectCount > getMaxDhcpRetries()) {
|
||||
loge("Failed " +
|
||||
mReconnectCount + " times, Disabling " + mLastNetworkId);
|
||||
WifiConfigStore.disableNetwork(mLastNetworkId,
|
||||
mWifiConfigStore.disableNetwork(mLastNetworkId,
|
||||
WifiConfiguration.DISABLED_DHCP_FAILURE);
|
||||
mReconnectCount = 0;
|
||||
}
|
||||
@@ -1757,8 +1759,8 @@ public class WifiStateMachine extends StateMachine {
|
||||
/* DHCP times out after about 30 seconds, we do a
|
||||
* disconnect and an immediate reconnect to try again
|
||||
*/
|
||||
WifiNative.disconnect();
|
||||
WifiNative.reconnect();
|
||||
mWifiNative.disconnect();
|
||||
mWifiNative.reconnect();
|
||||
}
|
||||
|
||||
/* Current design is to not set the config on a running hostapd but instead
|
||||
@@ -1826,7 +1828,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
case CMD_GET_CONFIGURED_NETWORKS:
|
||||
mReplyChannel.replyToMessage(message, message.what,
|
||||
WifiConfigStore.getConfiguredNetworks());
|
||||
mWifiConfigStore.getConfiguredNetworks());
|
||||
break;
|
||||
case CMD_ENABLE_RSSI_POLL:
|
||||
mEnableRssiPolling = (message.arg1 == 1);
|
||||
@@ -1913,7 +1915,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
// 50021 wifi_state_changed (custom|1|5)
|
||||
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
|
||||
|
||||
if (WifiNative.isDriverLoaded()) {
|
||||
if (mWifiNative.isDriverLoaded()) {
|
||||
transitionTo(mDriverLoadedState);
|
||||
}
|
||||
else {
|
||||
@@ -1966,7 +1968,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
}
|
||||
|
||||
if(WifiNative.loadDriver()) {
|
||||
if(mWifiNative.loadDriver()) {
|
||||
if (DBG) log("Driver load successful");
|
||||
sendMessage(CMD_LOAD_DRIVER_SUCCESS);
|
||||
} else {
|
||||
@@ -2054,7 +2056,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
loge("Unable to change interface settings: " + ie);
|
||||
}
|
||||
|
||||
if(WifiNative.startSupplicant()) {
|
||||
if(mWifiNative.startSupplicant()) {
|
||||
if (DBG) log("Supplicant start successful");
|
||||
mWifiMonitor.startMonitoring();
|
||||
transitionTo(mSupplicantStartingState);
|
||||
@@ -2086,7 +2088,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
public void run() {
|
||||
if (DBG) log(getName() + message.toString() + "\n");
|
||||
mWakeLock.acquire();
|
||||
if(WifiNative.unloadDriver()) {
|
||||
if(mWifiNative.unloadDriver()) {
|
||||
if (DBG) log("Driver unload successful");
|
||||
sendMessage(CMD_UNLOAD_DRIVER_SUCCESS);
|
||||
|
||||
@@ -2217,9 +2219,9 @@ public class WifiStateMachine extends StateMachine {
|
||||
mLastNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
mLastSignalLevel = -1;
|
||||
|
||||
mWifiInfo.setMacAddress(WifiNative.getMacAddress());
|
||||
mWifiInfo.setMacAddress(mWifiNative.getMacAddress());
|
||||
|
||||
WifiConfigStore.initialize(mContext);
|
||||
mWifiConfigStore.initialize();
|
||||
|
||||
sendSupplicantConnectionChangedBroadcast(true);
|
||||
transitionTo(mDriverStartedState);
|
||||
@@ -2227,7 +2229,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
case WifiMonitor.SUP_DISCONNECTION_EVENT:
|
||||
if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) {
|
||||
loge("Failed to setup control channel, restart supplicant");
|
||||
WifiNative.killSupplicant();
|
||||
mWifiNative.killSupplicant();
|
||||
transitionTo(mDriverLoadedState);
|
||||
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
|
||||
} else {
|
||||
@@ -2276,7 +2278,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
long supplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
|
||||
Settings.Secure.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
|
||||
mDefaultSupplicantScanIntervalMs);
|
||||
WifiNative.setScanInterval((int)supplicantScanIntervalMs / 1000);
|
||||
mWifiNative.setScanInterval((int)supplicantScanIntervalMs / 1000);
|
||||
}
|
||||
@Override
|
||||
public boolean processMessage(Message message) {
|
||||
@@ -2289,8 +2291,8 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
|
||||
loge("Connection lost, restart supplicant");
|
||||
WifiNative.killSupplicant();
|
||||
WifiNative.closeSupplicantConnection();
|
||||
mWifiNative.killSupplicant();
|
||||
mWifiNative.closeSupplicantConnection();
|
||||
mNetworkInfo.setIsAvailable(false);
|
||||
handleNetworkDisconnect();
|
||||
sendSupplicantConnectionChangedBroadcast(false);
|
||||
@@ -2301,46 +2303,46 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
case WifiMonitor.SCAN_RESULTS_EVENT:
|
||||
eventLoggingEnabled = false;
|
||||
setScanResults(WifiNative.scanResults());
|
||||
setScanResults(mWifiNative.scanResults());
|
||||
sendScanResultsAvailableBroadcast();
|
||||
mScanResultIsPending = false;
|
||||
break;
|
||||
case CMD_PING_SUPPLICANT:
|
||||
boolean ok = WifiNative.ping();
|
||||
boolean ok = mWifiNative.ping();
|
||||
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
|
||||
break;
|
||||
case CMD_ADD_OR_UPDATE_NETWORK:
|
||||
config = (WifiConfiguration) message.obj;
|
||||
mReplyChannel.replyToMessage(message, CMD_ADD_OR_UPDATE_NETWORK,
|
||||
WifiConfigStore.addOrUpdateNetwork(config));
|
||||
mWifiConfigStore.addOrUpdateNetwork(config));
|
||||
break;
|
||||
case CMD_REMOVE_NETWORK:
|
||||
ok = WifiConfigStore.removeNetwork(message.arg1);
|
||||
ok = mWifiConfigStore.removeNetwork(message.arg1);
|
||||
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
|
||||
break;
|
||||
case CMD_ENABLE_NETWORK:
|
||||
ok = WifiConfigStore.enableNetwork(message.arg1, message.arg2 == 1);
|
||||
ok = mWifiConfigStore.enableNetwork(message.arg1, message.arg2 == 1);
|
||||
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
|
||||
break;
|
||||
case CMD_ENABLE_ALL_NETWORKS:
|
||||
long time = android.os.SystemClock.elapsedRealtime();
|
||||
if (time - mLastEnableAllNetworksTime > MIN_INTERVAL_ENABLE_ALL_NETWORKS_MS) {
|
||||
WifiConfigStore.enableAllNetworks();
|
||||
mWifiConfigStore.enableAllNetworks();
|
||||
mLastEnableAllNetworksTime = time;
|
||||
}
|
||||
break;
|
||||
case CMD_DISABLE_NETWORK:
|
||||
ok = WifiConfigStore.disableNetwork(message.arg1, message.arg2);
|
||||
ok = mWifiConfigStore.disableNetwork(message.arg1, message.arg2);
|
||||
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
|
||||
break;
|
||||
case CMD_BLACKLIST_NETWORK:
|
||||
WifiNative.addToBlacklist((String)message.obj);
|
||||
mWifiNative.addToBlacklist((String)message.obj);
|
||||
break;
|
||||
case CMD_CLEAR_BLACKLIST:
|
||||
WifiNative.clearBlacklist();
|
||||
mWifiNative.clearBlacklist();
|
||||
break;
|
||||
case CMD_SAVE_CONFIG:
|
||||
ok = WifiConfigStore.saveConfig();
|
||||
ok = mWifiConfigStore.saveConfig();
|
||||
mReplyChannel.replyToMessage(message, CMD_SAVE_CONFIG, ok ? SUCCESS : FAILURE);
|
||||
|
||||
// Inform the backup manager about a data change
|
||||
@@ -2364,10 +2366,10 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
case CMD_SAVE_NETWORK:
|
||||
config = (WifiConfiguration) message.obj;
|
||||
WifiConfigStore.saveNetwork(config);
|
||||
mWifiConfigStore.saveNetwork(config);
|
||||
break;
|
||||
case CMD_FORGET_NETWORK:
|
||||
WifiConfigStore.forgetNetwork(message.arg1);
|
||||
mWifiConfigStore.forgetNetwork(message.arg1);
|
||||
break;
|
||||
default:
|
||||
return NOT_HANDLED;
|
||||
@@ -2390,7 +2392,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
if (DBG) log(getName() + "\n");
|
||||
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
|
||||
if (DBG) log("stopping supplicant");
|
||||
if (!WifiNative.stopSupplicant()) {
|
||||
if (!mWifiNative.stopSupplicant()) {
|
||||
loge("Failed to stop supplicant");
|
||||
}
|
||||
|
||||
@@ -2417,15 +2419,15 @@ public class WifiStateMachine extends StateMachine {
|
||||
/* Socket connection can be lost when we do a graceful shutdown
|
||||
* or when the driver is hung. Ensure supplicant is stopped here.
|
||||
*/
|
||||
WifiNative.killSupplicant();
|
||||
WifiNative.closeSupplicantConnection();
|
||||
mWifiNative.killSupplicant();
|
||||
mWifiNative.closeSupplicantConnection();
|
||||
transitionTo(mDriverLoadedState);
|
||||
break;
|
||||
case CMD_STOP_SUPPLICANT_FAILED:
|
||||
if (message.arg1 == mSupplicantStopFailureToken) {
|
||||
loge("Timed out on a supplicant stop, kill and proceed");
|
||||
WifiNative.killSupplicant();
|
||||
WifiNative.closeSupplicantConnection();
|
||||
mWifiNative.killSupplicant();
|
||||
mWifiNative.closeSupplicantConnection();
|
||||
transitionTo(mDriverLoadedState);
|
||||
}
|
||||
break;
|
||||
@@ -2516,7 +2518,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
* When this mode is on, some of the low-level scan parameters used by the
|
||||
* driver are changed to reduce interference with bluetooth
|
||||
*/
|
||||
WifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
|
||||
mWifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
|
||||
/* set country code */
|
||||
setCountryCode();
|
||||
/* set frequency band of operation */
|
||||
@@ -2525,26 +2527,26 @@ public class WifiStateMachine extends StateMachine {
|
||||
setNetworkDetailedState(DetailedState.DISCONNECTED);
|
||||
|
||||
/* Remove any filtering on Multicast v6 at start */
|
||||
WifiNative.stopFilteringMulticastV6Packets();
|
||||
mWifiNative.stopFilteringMulticastV6Packets();
|
||||
|
||||
/* Reset Multicast v4 filtering state */
|
||||
if (mFilteringMulticastV4Packets.get()) {
|
||||
WifiNative.startFilteringMulticastV4Packets();
|
||||
mWifiNative.startFilteringMulticastV4Packets();
|
||||
} else {
|
||||
WifiNative.stopFilteringMulticastV4Packets();
|
||||
mWifiNative.stopFilteringMulticastV4Packets();
|
||||
}
|
||||
|
||||
if (mIsScanMode) {
|
||||
WifiNative.setScanResultHandling(SCAN_ONLY_MODE);
|
||||
WifiNative.disconnect();
|
||||
mWifiNative.setScanResultHandling(SCAN_ONLY_MODE);
|
||||
mWifiNative.disconnect();
|
||||
transitionTo(mScanModeState);
|
||||
} else {
|
||||
WifiNative.setScanResultHandling(CONNECT_MODE);
|
||||
WifiNative.reconnect();
|
||||
mWifiNative.setScanResultHandling(CONNECT_MODE);
|
||||
mWifiNative.reconnect();
|
||||
// Status pulls in the current supplicant state and network connection state
|
||||
// events over the monitor connection. This helps framework sync up with
|
||||
// current supplicant state
|
||||
WifiNative.status();
|
||||
mWifiNative.status();
|
||||
transitionTo(mDisconnectedState);
|
||||
}
|
||||
}
|
||||
@@ -2555,17 +2557,17 @@ public class WifiStateMachine extends StateMachine {
|
||||
switch(message.what) {
|
||||
case CMD_SET_SCAN_TYPE:
|
||||
mSetScanActive = (message.arg1 == SCAN_ACTIVE);
|
||||
WifiNative.setScanMode(mSetScanActive);
|
||||
mWifiNative.setScanMode(mSetScanActive);
|
||||
break;
|
||||
case CMD_START_SCAN:
|
||||
eventLoggingEnabled = false;
|
||||
boolean forceActive = (message.arg1 == SCAN_ACTIVE);
|
||||
if (forceActive && !mSetScanActive) {
|
||||
WifiNative.setScanMode(forceActive);
|
||||
mWifiNative.setScanMode(forceActive);
|
||||
}
|
||||
WifiNative.scan();
|
||||
mWifiNative.scan();
|
||||
if (forceActive && !mSetScanActive) {
|
||||
WifiNative.setScanMode(mSetScanActive);
|
||||
mWifiNative.setScanMode(mSetScanActive);
|
||||
}
|
||||
mScanResultIsPending = true;
|
||||
break;
|
||||
@@ -2575,14 +2577,14 @@ public class WifiStateMachine extends StateMachine {
|
||||
case CMD_SET_COUNTRY_CODE:
|
||||
String country = (String) message.obj;
|
||||
if (DBG) log("set country code " + country);
|
||||
if (!WifiNative.setCountryCode(country.toUpperCase())) {
|
||||
if (!mWifiNative.setCountryCode(country.toUpperCase())) {
|
||||
loge("Failed to set country code " + country);
|
||||
}
|
||||
break;
|
||||
case CMD_SET_FREQUENCY_BAND:
|
||||
int band = message.arg1;
|
||||
if (DBG) log("set frequency band " + band);
|
||||
if (WifiNative.setBand(band)) {
|
||||
if (mWifiNative.setBand(band)) {
|
||||
mFrequencyBand.set(band);
|
||||
//Fetch the latest scan results when frequency band is set
|
||||
startScan(true);
|
||||
@@ -2593,7 +2595,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE:
|
||||
mBluetoothConnectionActive = (message.arg1 !=
|
||||
BluetoothAdapter.STATE_DISCONNECTED);
|
||||
WifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
|
||||
mWifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
|
||||
break;
|
||||
case CMD_STOP_DRIVER:
|
||||
int mode = message.arg1;
|
||||
@@ -2626,28 +2628,28 @@ public class WifiStateMachine extends StateMachine {
|
||||
case CMD_DELAYED_STOP_DRIVER:
|
||||
if (message.arg1 != mDelayedStopCounter) break;
|
||||
if (getCurrentState() != mDisconnectedState) {
|
||||
WifiNative.disconnect();
|
||||
mWifiNative.disconnect();
|
||||
handleNetworkDisconnect();
|
||||
}
|
||||
mWakeLock.acquire();
|
||||
WifiNative.stopDriver();
|
||||
mWifiNative.stopDriver();
|
||||
transitionTo(mDriverStoppingState);
|
||||
mWakeLock.release();
|
||||
break;
|
||||
case CMD_START_PACKET_FILTERING:
|
||||
if (message.arg1 == MULTICAST_V6) {
|
||||
WifiNative.startFilteringMulticastV6Packets();
|
||||
mWifiNative.startFilteringMulticastV6Packets();
|
||||
} else if (message.arg1 == MULTICAST_V4) {
|
||||
WifiNative.startFilteringMulticastV4Packets();
|
||||
mWifiNative.startFilteringMulticastV4Packets();
|
||||
} else {
|
||||
loge("Illegal arugments to CMD_START_PACKET_FILTERING");
|
||||
}
|
||||
break;
|
||||
case CMD_STOP_PACKET_FILTERING:
|
||||
if (message.arg1 == MULTICAST_V6) {
|
||||
WifiNative.stopFilteringMulticastV6Packets();
|
||||
mWifiNative.stopFilteringMulticastV6Packets();
|
||||
} else if (message.arg1 == MULTICAST_V4) {
|
||||
WifiNative.stopFilteringMulticastV4Packets();
|
||||
mWifiNative.stopFilteringMulticastV4Packets();
|
||||
} else {
|
||||
loge("Illegal arugments to CMD_STOP_PACKET_FILTERING");
|
||||
}
|
||||
@@ -2729,7 +2731,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
case CMD_START_DRIVER:
|
||||
mWakeLock.acquire();
|
||||
WifiNative.startDriver();
|
||||
mWifiNative.startDriver();
|
||||
mWakeLock.release();
|
||||
transitionTo(mDriverStartingState);
|
||||
break;
|
||||
@@ -2756,8 +2758,8 @@ public class WifiStateMachine extends StateMachine {
|
||||
/* Ignore */
|
||||
return HANDLED;
|
||||
} else {
|
||||
WifiNative.setScanResultHandling(message.arg1);
|
||||
WifiNative.reconnect();
|
||||
mWifiNative.setScanResultHandling(message.arg1);
|
||||
mWifiNative.reconnect();
|
||||
mIsScanMode = false;
|
||||
transitionTo(mDisconnectedState);
|
||||
}
|
||||
@@ -2824,13 +2826,13 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
/* Do a redundant disconnect without transition */
|
||||
case CMD_DISCONNECT:
|
||||
WifiNative.disconnect();
|
||||
mWifiNative.disconnect();
|
||||
break;
|
||||
case CMD_RECONNECT:
|
||||
WifiNative.reconnect();
|
||||
mWifiNative.reconnect();
|
||||
break;
|
||||
case CMD_REASSOCIATE:
|
||||
WifiNative.reassociate();
|
||||
mWifiNative.reassociate();
|
||||
break;
|
||||
case CMD_CONNECT_NETWORK:
|
||||
int netId = message.arg1;
|
||||
@@ -2844,15 +2846,15 @@ public class WifiStateMachine extends StateMachine {
|
||||
* a connection to the enabled network.
|
||||
*/
|
||||
if (config != null) {
|
||||
netId = WifiConfigStore.selectNetwork(config);
|
||||
netId = mWifiConfigStore.selectNetwork(config);
|
||||
} else {
|
||||
WifiConfigStore.selectNetwork(netId);
|
||||
mWifiConfigStore.selectNetwork(netId);
|
||||
}
|
||||
|
||||
/* The state tracker handles enabling networks upon completion/failure */
|
||||
mSupplicantStateTracker.sendMessage(CMD_CONNECT_NETWORK);
|
||||
|
||||
WifiNative.reconnect();
|
||||
mWifiNative.reconnect();
|
||||
/* Expect a disconnection from the old connection */
|
||||
transitionTo(mDisconnectingState);
|
||||
break;
|
||||
@@ -2862,7 +2864,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
break;
|
||||
case WifiMonitor.SCAN_RESULTS_EVENT:
|
||||
/* Set the scan setting back to "connect" mode */
|
||||
WifiNative.setScanResultHandling(CONNECT_MODE);
|
||||
mWifiNative.setScanResultHandling(CONNECT_MODE);
|
||||
/* Handle scan results */
|
||||
return NOT_HANDLED;
|
||||
case WifiMonitor.NETWORK_CONNECTION_EVENT:
|
||||
@@ -2907,14 +2909,14 @@ public class WifiStateMachine extends StateMachine {
|
||||
loge("Failed to enable IPv6: " + e);
|
||||
}
|
||||
|
||||
if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
|
||||
if (!mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
|
||||
//start DHCP
|
||||
mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(
|
||||
mContext, WifiStateMachine.this, mInterfaceName);
|
||||
mDhcpStateMachine.registerForPreDhcpNotification();
|
||||
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
|
||||
} else {
|
||||
DhcpInfoInternal dhcpInfoInternal = WifiConfigStore.getIpConfiguration(
|
||||
DhcpInfoInternal dhcpInfoInternal = mWifiConfigStore.getIpConfiguration(
|
||||
mLastNetworkId);
|
||||
InterfaceConfiguration ifcg = new InterfaceConfiguration();
|
||||
ifcg.setLinkAddress(dhcpInfoInternal.makeLinkAddress());
|
||||
@@ -2960,7 +2962,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
transitionTo(mDisconnectingState);
|
||||
break;
|
||||
case CMD_DISCONNECT:
|
||||
WifiNative.disconnect();
|
||||
mWifiNative.disconnect();
|
||||
transitionTo(mDisconnectingState);
|
||||
break;
|
||||
/* Ignore connection to same network */
|
||||
@@ -3027,7 +3029,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
}
|
||||
break;
|
||||
case CMD_DISCONNECT:
|
||||
WifiNative.disconnect();
|
||||
mWifiNative.disconnect();
|
||||
transitionTo(mDisconnectingState);
|
||||
break;
|
||||
case CMD_SET_SCAN_MODE:
|
||||
@@ -3043,7 +3045,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
* When scan results are received, the mode is switched
|
||||
* back to CONNECT_MODE.
|
||||
*/
|
||||
WifiNative.setScanResultHandling(SCAN_ONLY_MODE);
|
||||
mWifiNative.setScanResultHandling(SCAN_ONLY_MODE);
|
||||
/* Have the parent state handle the rest */
|
||||
return NOT_HANDLED;
|
||||
/* Ignore connection to same network */
|
||||
@@ -3055,7 +3057,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
return NOT_HANDLED;
|
||||
case CMD_SAVE_NETWORK:
|
||||
WifiConfiguration config = (WifiConfiguration) message.obj;
|
||||
NetworkUpdateResult result = WifiConfigStore.saveNetwork(config);
|
||||
NetworkUpdateResult result = mWifiConfigStore.saveNetwork(config);
|
||||
if (mWifiInfo.getNetworkId() == result.getNetworkId()) {
|
||||
if (result.hasIpChanged()) {
|
||||
log("Reconfiguring IP on connection");
|
||||
@@ -3111,7 +3113,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
* is in SCAN_ONLY_MODE. Restore CONNECT_MODE on exit
|
||||
*/
|
||||
if (mScanResultIsPending) {
|
||||
WifiNative.setScanResultHandling(CONNECT_MODE);
|
||||
mWifiNative.setScanResultHandling(CONNECT_MODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3192,7 +3194,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
* cleared
|
||||
*/
|
||||
if (!mScanResultIsPending) {
|
||||
WifiNative.enableBackgroundScan(true);
|
||||
mWifiNative.enableBackgroundScan(true);
|
||||
}
|
||||
} else {
|
||||
setScanAlarm(true);
|
||||
@@ -3204,9 +3206,9 @@ public class WifiStateMachine extends StateMachine {
|
||||
switch (message.what) {
|
||||
case CMD_SET_SCAN_MODE:
|
||||
if (message.arg1 == SCAN_ONLY_MODE) {
|
||||
WifiNative.setScanResultHandling(message.arg1);
|
||||
mWifiNative.setScanResultHandling(message.arg1);
|
||||
//Supplicant disconnect to prevent further connects
|
||||
WifiNative.disconnect();
|
||||
mWifiNative.disconnect();
|
||||
mIsScanMode = true;
|
||||
transitionTo(mScanModeState);
|
||||
}
|
||||
@@ -3214,10 +3216,10 @@ public class WifiStateMachine extends StateMachine {
|
||||
case CMD_ENABLE_BACKGROUND_SCAN:
|
||||
mEnableBackgroundScan = (message.arg1 == 1);
|
||||
if (mEnableBackgroundScan) {
|
||||
WifiNative.enableBackgroundScan(true);
|
||||
mWifiNative.enableBackgroundScan(true);
|
||||
setScanAlarm(false);
|
||||
} else {
|
||||
WifiNative.enableBackgroundScan(false);
|
||||
mWifiNative.enableBackgroundScan(false);
|
||||
setScanAlarm(true);
|
||||
}
|
||||
break;
|
||||
@@ -3232,14 +3234,14 @@ public class WifiStateMachine extends StateMachine {
|
||||
case CMD_START_SCAN:
|
||||
/* Disable background scan temporarily during a regular scan */
|
||||
if (mEnableBackgroundScan) {
|
||||
WifiNative.enableBackgroundScan(false);
|
||||
mWifiNative.enableBackgroundScan(false);
|
||||
}
|
||||
/* Handled in parent state */
|
||||
return NOT_HANDLED;
|
||||
case WifiMonitor.SCAN_RESULTS_EVENT:
|
||||
/* Re-enable background scan when a pending scan result is received */
|
||||
if (mEnableBackgroundScan && mScanResultIsPending) {
|
||||
WifiNative.enableBackgroundScan(true);
|
||||
mWifiNative.enableBackgroundScan(true);
|
||||
}
|
||||
/* Handled in parent state */
|
||||
return NOT_HANDLED;
|
||||
@@ -3254,7 +3256,7 @@ public class WifiStateMachine extends StateMachine {
|
||||
public void exit() {
|
||||
/* No need for a background scan upon exit from a disconnected state */
|
||||
if (mEnableBackgroundScan) {
|
||||
WifiNative.enableBackgroundScan(false);
|
||||
mWifiNative.enableBackgroundScan(false);
|
||||
}
|
||||
setScanAlarm(false);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class WpsStateMachine extends StateMachine {
|
||||
private static final boolean DBG = false;
|
||||
|
||||
private WifiStateMachine mWifiStateMachine;
|
||||
private WifiConfigStore mWifiConfigStore;
|
||||
|
||||
private WpsInfo mWpsInfo;
|
||||
|
||||
@@ -62,11 +63,12 @@ class WpsStateMachine extends StateMachine {
|
||||
private State mInactiveState = new InactiveState();
|
||||
private State mActiveState = new ActiveState();
|
||||
|
||||
public WpsStateMachine(Context context, WifiStateMachine wsm, Handler target) {
|
||||
super(TAG, target.getLooper());
|
||||
public WpsStateMachine(Context context, WifiStateMachine wsm, WifiConfigStore wcs, Handler t) {
|
||||
super(TAG, t.getLooper());
|
||||
|
||||
mContext = context;
|
||||
mWifiStateMachine = wsm;
|
||||
mWifiConfigStore = wcs;
|
||||
addState(mDefaultState);
|
||||
addState(mInactiveState, mDefaultState);
|
||||
addState(mActiveState, mDefaultState);
|
||||
@@ -97,13 +99,13 @@ class WpsStateMachine extends StateMachine {
|
||||
WpsResult result;
|
||||
switch (mWpsInfo.setup) {
|
||||
case WpsInfo.PBC:
|
||||
result = WifiConfigStore.startWpsPbc(mWpsInfo);
|
||||
result = mWifiConfigStore.startWpsPbc(mWpsInfo);
|
||||
break;
|
||||
case WpsInfo.KEYPAD:
|
||||
result = WifiConfigStore.startWpsWithPinFromAccessPoint(mWpsInfo);
|
||||
result = mWifiConfigStore.startWpsWithPinFromAccessPoint(mWpsInfo);
|
||||
break;
|
||||
case WpsInfo.DISPLAY:
|
||||
result = WifiConfigStore.startWpsWithPinFromDevice(mWpsInfo);
|
||||
result = mWifiConfigStore.startWpsWithPinFromDevice(mWpsInfo);
|
||||
break;
|
||||
default:
|
||||
result = new WpsResult(Status.FAILURE);
|
||||
@@ -151,9 +153,9 @@ class WpsStateMachine extends StateMachine {
|
||||
* and the configuration list needs to be reloaded from the supplicant.
|
||||
*/
|
||||
Log.d(TAG, "WPS set up successful");
|
||||
WifiConfigStore.enableAllNetworks();
|
||||
WifiConfigStore.loadConfiguredNetworks();
|
||||
WifiConfigStore.updateIpAndProxyFromWpsConfig(
|
||||
mWifiConfigStore.enableAllNetworks();
|
||||
mWifiConfigStore.loadConfiguredNetworks();
|
||||
mWifiConfigStore.updateIpAndProxyFromWpsConfig(
|
||||
stateChangeResult.networkId, mWpsInfo);
|
||||
mWifiStateMachine.sendMessage(WifiStateMachine.WPS_COMPLETED_EVENT);
|
||||
transitionTo(mInactiveState);
|
||||
@@ -161,7 +163,7 @@ class WpsStateMachine extends StateMachine {
|
||||
case INACTIVE:
|
||||
/* A failed WPS connection */
|
||||
Log.d(TAG, "WPS set up failed, enabling other networks");
|
||||
WifiConfigStore.enableAllNetworks();
|
||||
mWifiConfigStore.enableAllNetworks();
|
||||
mWifiStateMachine.sendMessage(WifiStateMachine.WPS_COMPLETED_EVENT);
|
||||
transitionTo(mInactiveState);
|
||||
break;
|
||||
|
||||
@@ -166,7 +166,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
public WifiP2pService(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mInterface = SystemProperties.get("wifi.interface", "wlan0");
|
||||
//STOPSHIP: fix this
|
||||
mInterface = "p2p0";
|
||||
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI_P2P, 0, NETWORKTYPE, "");
|
||||
|
||||
mP2pSupported = mContext.getPackageManager().hasSystemFeature(
|
||||
@@ -278,7 +279,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
private GroupCreatedState mGroupCreatedState = new GroupCreatedState();
|
||||
private UserAuthorizingJoinState mUserAuthorizingJoinState = new UserAuthorizingJoinState();
|
||||
|
||||
private WifiMonitor mWifiMonitor = new WifiMonitor(this);
|
||||
private WifiNative mWifiNative = new WifiNative(mInterface);
|
||||
private WifiMonitor mWifiMonitor = new WifiMonitor(this, mWifiNative);
|
||||
|
||||
private WifiP2pDeviceList mPeers = new WifiP2pDeviceList();
|
||||
private WifiP2pInfo mWifiP2pInfo = new WifiP2pInfo();
|
||||
@@ -456,9 +458,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
public void enter() {
|
||||
if (DBG) logd(getName());
|
||||
logd("stopping supplicant");
|
||||
if (!WifiNative.stopSupplicant()) {
|
||||
if (!mWifiNative.stopSupplicant()) {
|
||||
loge("Failed to stop supplicant, issue kill");
|
||||
WifiNative.killSupplicant();
|
||||
mWifiNative.killSupplicant();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +470,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
switch (message.what) {
|
||||
case WifiMonitor.SUP_DISCONNECTION_EVENT:
|
||||
logd("Supplicant connection lost");
|
||||
WifiNative.closeSupplicantConnection();
|
||||
mWifiNative.closeSupplicantConnection();
|
||||
transitionTo(mP2pDisabledState);
|
||||
break;
|
||||
case WifiP2pManager.ENABLE_P2P:
|
||||
@@ -594,7 +596,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
if (DBG) Slog.w(TAG, "Unable to bring down wlan interface: " + e);
|
||||
}
|
||||
|
||||
if (WifiNative.startP2pSupplicant()) {
|
||||
if (mWifiNative.startP2pSupplicant()) {
|
||||
mWifiMonitor.startMonitoring();
|
||||
transitionTo(mP2pEnablingState);
|
||||
} else {
|
||||
@@ -630,7 +632,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
case WifiMonitor.SUP_DISCONNECTION_EVENT:
|
||||
if (++mP2pRestartCount <= P2P_RESTART_TRIES) {
|
||||
loge("Failed to start p2p, retry");
|
||||
WifiNative.killSupplicant();
|
||||
mWifiNative.killSupplicant();
|
||||
sendMessageDelayed(WifiP2pManager.ENABLE_P2P, P2P_RESTART_INTERVAL_MSECS);
|
||||
} else {
|
||||
loge("Failed " + mP2pRestartCount + " times to start p2p, quit ");
|
||||
@@ -673,7 +675,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
break;
|
||||
case WifiP2pManager.DISCOVER_PEERS:
|
||||
int timeout = message.arg1;
|
||||
if (WifiNative.p2pFind(timeout)) {
|
||||
if (mWifiNative.p2pFind(timeout)) {
|
||||
replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_SUCCEEDED);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED,
|
||||
@@ -692,8 +694,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
break;
|
||||
case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant died */
|
||||
loge("Connection lost, restart p2p");
|
||||
WifiNative.killSupplicant();
|
||||
WifiNative.closeSupplicantConnection();
|
||||
mWifiNative.killSupplicant();
|
||||
mWifiNative.closeSupplicantConnection();
|
||||
if (mPeers.clear()) sendP2pPeersChangedBroadcast();
|
||||
transitionTo(mP2pDisabledState);
|
||||
sendMessageDelayed(WifiP2pManager.ENABLE_P2P, P2P_RESTART_INTERVAL_MSECS);
|
||||
@@ -717,7 +719,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
public void enter() {
|
||||
if (DBG) logd(getName());
|
||||
//Start listening every time we get inactive
|
||||
WifiNative.p2pListen();
|
||||
mWifiNative.p2pListen();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -727,13 +729,13 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
case WifiP2pManager.CONNECT:
|
||||
if (DBG) logd(getName() + " sending connect");
|
||||
mSavedPeerConfig = (WifiP2pConfig) message.obj;
|
||||
String updatedPeerDetails = WifiNative.p2pPeer(mSavedPeerConfig.deviceAddress);
|
||||
String updatedPeerDetails = mWifiNative.p2pPeer(mSavedPeerConfig.deviceAddress);
|
||||
mPeers.update(new WifiP2pDevice(updatedPeerDetails));
|
||||
mPersistGroup = false;
|
||||
int netId = configuredNetworkId(mSavedPeerConfig.deviceAddress);
|
||||
if (netId >= 0) {
|
||||
//TODO: if failure, remove config and do a regular p2pConnect()
|
||||
WifiNative.p2pReinvoke(netId, mSavedPeerConfig.deviceAddress);
|
||||
mWifiNative.p2pReinvoke(netId, mSavedPeerConfig.deviceAddress);
|
||||
} else {
|
||||
//If peer is a GO, we do not need to send provisional discovery,
|
||||
//the supplicant takes care of it.
|
||||
@@ -798,7 +800,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
break;
|
||||
case WifiP2pManager.CREATE_GROUP:
|
||||
mPersistGroup = true;
|
||||
if (WifiNative.p2pGroupAdd()) {
|
||||
if (mWifiNative.p2pGroupAdd()) {
|
||||
replyToMessage(message, WifiP2pManager.CREATE_GROUP_SUCCEEDED);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
|
||||
@@ -840,7 +842,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
WifiP2pManager.BUSY);
|
||||
break;
|
||||
case WifiP2pManager.CANCEL_CONNECT:
|
||||
if (WifiNative.p2pCancelConnect()) {
|
||||
if (mWifiNative.p2pCancelConnect()) {
|
||||
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
|
||||
@@ -897,7 +899,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
@Override
|
||||
public void enter() {
|
||||
if (DBG) logd(getName());
|
||||
WifiNative.p2pProvisionDiscovery(mSavedPeerConfig);
|
||||
mWifiNative.p2pProvisionDiscovery(mSavedPeerConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -913,7 +915,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
|
||||
if (mSavedPeerConfig.wps.setup == WpsInfo.PBC) {
|
||||
if (DBG) logd("Found a match " + mSavedPeerConfig);
|
||||
WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
|
||||
mWifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
|
||||
transitionTo(mGroupNegotiationState);
|
||||
}
|
||||
break;
|
||||
@@ -926,7 +928,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
if (DBG) logd("Found a match " + mSavedPeerConfig);
|
||||
/* we already have the pin */
|
||||
if (!TextUtils.isEmpty(mSavedPeerConfig.wps.pin)) {
|
||||
WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
|
||||
mWifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
|
||||
transitionTo(mGroupNegotiationState);
|
||||
} else {
|
||||
transitionTo(mUserAuthorizingInvitationState);
|
||||
@@ -941,7 +943,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
if (mSavedPeerConfig.wps.setup == WpsInfo.DISPLAY) {
|
||||
if (DBG) logd("Found a match " + mSavedPeerConfig);
|
||||
mSavedPeerConfig.wps.pin = provDisc.pin;
|
||||
WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
|
||||
mWifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
|
||||
notifyInvitationSent(provDisc.pin, device.deviceAddress);
|
||||
transitionTo(mGroupNegotiationState);
|
||||
}
|
||||
@@ -1045,7 +1047,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
if (DBG) logd("Removed client " + deviceAddress);
|
||||
if (!mPersistGroup && mGroup.isClientListEmpty()) {
|
||||
Slog.d(TAG, "Client list empty, remove non-persistent p2p group");
|
||||
WifiNative.p2pGroupRemove(mGroup.getInterface());
|
||||
mWifiNative.p2pGroupRemove(mGroup.getInterface());
|
||||
}
|
||||
} else {
|
||||
if (DBG) logd("Failed to remove client " + deviceAddress);
|
||||
@@ -1067,12 +1069,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
setWifiP2pInfoOnGroupFormation(dhcpInfo.serverAddress);
|
||||
sendP2pConnectionChangedBroadcast();
|
||||
} else {
|
||||
WifiNative.p2pGroupRemove(mGroup.getInterface());
|
||||
mWifiNative.p2pGroupRemove(mGroup.getInterface());
|
||||
}
|
||||
break;
|
||||
case WifiP2pManager.REMOVE_GROUP:
|
||||
if (DBG) loge(getName() + " remove group");
|
||||
if (WifiNative.p2pGroupRemove(mGroup.getInterface())) {
|
||||
if (mWifiNative.p2pGroupRemove(mGroup.getInterface())) {
|
||||
replyToMessage(message, WifiP2pManager.REMOVE_GROUP_SUCCEEDED);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.REMOVE_GROUP_FAILED,
|
||||
@@ -1119,7 +1121,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
case WifiP2pManager.CONNECT:
|
||||
WifiP2pConfig config = (WifiP2pConfig) message.obj;
|
||||
logd("Inviting device : " + config.deviceAddress);
|
||||
if (WifiNative.p2pInvite(mGroup, config.deviceAddress)) {
|
||||
if (mWifiNative.p2pInvite(mGroup, config.deviceAddress)) {
|
||||
updateDeviceStatus(config.deviceAddress, WifiP2pDevice.INVITED);
|
||||
sendP2pPeersChangedBroadcast();
|
||||
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
|
||||
@@ -1180,9 +1182,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
break;
|
||||
case PEER_CONNECTION_USER_ACCEPT:
|
||||
if (mSavedPeerConfig.wps.setup == WpsInfo.PBC) {
|
||||
WifiNative.startWpsPbc();
|
||||
mWifiNative.startWpsPbc();
|
||||
} else {
|
||||
WifiNative.startWpsPinKeypad(mSavedPeerConfig.wps.pin);
|
||||
mWifiNative.startWpsPinKeypad(mSavedPeerConfig.wps.pin);
|
||||
}
|
||||
mSavedPeerConfig = null;
|
||||
transitionTo(mGroupCreatedState);
|
||||
@@ -1422,7 +1424,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
}
|
||||
|
||||
private void p2pConnectWithPinDisplay(WifiP2pConfig config, boolean join) {
|
||||
String pin = WifiNative.p2pConnect(config, join);
|
||||
String pin = mWifiNative.p2pConnect(config, join);
|
||||
try {
|
||||
Integer.parseInt(pin);
|
||||
notifyInvitationSent(pin, config.deviceAddress);
|
||||
@@ -1432,16 +1434,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
}
|
||||
|
||||
private void initializeP2pSettings() {
|
||||
WifiNative.setPersistentReconnect(true);
|
||||
WifiNative.setDeviceName(mThisDevice.deviceName);
|
||||
mWifiNative.setPersistentReconnect(true);
|
||||
mWifiNative.setDeviceName(mThisDevice.deviceName);
|
||||
//DIRECT-XY-DEVICENAME (XY is randomly generated)
|
||||
WifiNative.setP2pSsidPostfix("-" + mThisDevice.deviceName);
|
||||
WifiNative.setDeviceType(mThisDevice.primaryDeviceType);
|
||||
mWifiNative.setP2pSsidPostfix("-" + mThisDevice.deviceName);
|
||||
mWifiNative.setDeviceType(mThisDevice.primaryDeviceType);
|
||||
//The supplicant default is to support everything, but a bug necessitates
|
||||
//the framework to specify this explicitly
|
||||
WifiNative.setConfigMethods("keypad display push_button");
|
||||
mWifiNative.setConfigMethods("keypad display push_button");
|
||||
|
||||
mThisDevice.deviceAddress = WifiNative.p2pGetDeviceAddress();
|
||||
mThisDevice.deviceAddress = mWifiNative.p2pGetDeviceAddress();
|
||||
updateThisDevice(WifiP2pDevice.AVAILABLE);
|
||||
if (DBG) Slog.d(TAG, "DeviceAddress: " + mThisDevice.deviceAddress);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user