Android 8 (Oreo) WifiManager reconnect method times out - android

I am having an issue. The app I am busy with has a strange issue at the moment. I use the following library: WiseFly which is a simple wifi manager wrapper
My app manages WiFi networks. It will add to saved networks and connects to it depending on users interaction with my app. It works perfectly on all versions of android, except for Android Oreo on my Pixel.
It times out on the following line internally on the wrapper:
getWifiManager().disconnect();
getWifiManager().enableNetwork(wifiConfiguration.networkId, true);
getWifiManager().reconnect();
The last line is the issue. And if I go into the network settings on android, I see the saved network, but will also not connect from within android. Any ideas what I could look for to fix this issue?
This is the code used to add the network:
/**
* To generate a configuration for a WPA2 network
*
* #param ssid The ssid for the WPA2 network's configuration
* #param password The password for the WPA2 network's configuration
*
* #return WifiConfiguration - The WPA2 network configuration
*/
public WifiConfiguration generateWPA2NetworkConfiguration(String ssid, String password) {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = mSSIDUtil.convertSSIDForConfig(ssid);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
return wifiConfiguration;
}
Any help would be greatly appreciated.
Thanks

Try this
// Allow a previously configured network to be associated with.
getWifiManager().enableNetwork(wifiConfiguration.networkId, true);
// Reconnect to the currently active access point, if we are currently disconnected.
getWifiManager().reconnect();
// wait until reconnect process is completed
Thread.sleep(3000);

Related

How to open Android hotspot using flutter

I want to set ssid and password of wifi hotspot in android using flutter.
I used wifi_iot but most of it's functions are deprecated.
is there any other way to do so?
I think using method channels would be better but I need code to open hotspot from kotlin/
give me full example of kotlin code please to open hotspot and set ssid, password
val wifiManager =
applicationContext.getSystemService(Context.WIFI_SERVICE) as
WifiManager val method =
wifiManager.javaClass.getMethod("setWifiApEnabled",
WifiConfiguration::class.java, Boolean::class.javaPrimitiveType) val
wifiConfig = WifiConfiguration() wifiConfig.SSID = "MyHotSpot"
wifiConfig.preSharedKey = "mypassword"
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK)
method.invoke(wifiManager, wifiConfig, true)

android 10 how to disable Randomized Mac Address in source code

Currently, I am working on connecting specific WiFi in the source code.
But the problem is, since Android 10, the default setting is to set a random macArress.
Yeah i forcibly set the mac adrress to wifi info or I want to turn off random mac adrress option
this is my code
if(BasicInfo.wifiEncryption == BasicInfo.WPA_PSK){
BasicInfo.debug(TAG,"setWiFiConfigForJellyBean :BasicInfo.WPA_PSK");
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.preSharedKey = "\"".concat(BasicInfo.WIFI_PASSWORD).concat("\"");
BasicInfo.debug(TAG,"BasicInfo.WPA_PSK Password :" + BasicInfo.WIFI_PASSWORD);
}

PJSIP VOIP call not connected using SIP2SIP.info server

i am using PJSIP for voice calling. When i used our server, everything fine i.e. call connected, communicate. But when i am using SIP2SIP.INFO server. Registration is OK But Call is not connected. i saw log in SIP2SIP.info there wasn't log of outgoing or incoming call.
so call is not initiate.
char cfg_reg_uri[] = "sip:sip2sip.info";
char cfg_cred_realm[] = "sip2sip.info";
char cfg_cred_scheme[]="digest";
pjsua_acc_config cfg;
pjsua_acc_config_default(&cfg);
cfg.id = pj_str(cfg_id);
cfg.reg_uri = pj_str(cfg_reg_uri);
cfg.cred_count = 1;
cfg.cred_info[0].realm = pj_str(cfg_cred_realm);
cfg.cred_info[0].scheme = pj_str(cfg_cred_scheme);
cfg.cred_info[0].username = pj_str(cfg_cred_username);
cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
cfg.cred_info[0].data = pj_str(cfg_cred_password);
status = pjsua_acc_add(&cfg, PJ_TRUE, &_acc_id);
I noted that we need to use outbound proxy in sip2sip called "proxy.sipthor.net".
but confused how can i used in pjsip code.
please help expert.
If you read the Sip2Sip device configuration page it states that:
" the SIP device must always perform DNS lookups as defined in SIP standard RFC3263 (NAPTR + SRV + A DNS lookups)"
PJSIP supports DNS SRV lookups.
In PJSUA it will only do DNS SRV lookup if you don't provide the port number in the SIP URL.
"sip:xxx#sip2sip.info" will try to do a DNS SRV record lookup first then fail over to DNS A/C name lookup.
and
"sip:xxx#sip2sip.info:5060" will only do DNS A/C name lookup.
What PJSUA will not support automatically is failover support, they say:
"What we've been suggesting is to implement the failover mechanism in the application layer."
If you want a "quick and easy" setup, what you want to do is set the outbound_proxy to "proxy.sipthor.net". e.g.
cfg.outbound_proxy_cnt = 1;
cfg.outbound_proxy[0] = pj_str("sip:proxy.sipthor.net:5060");
If you want a more robust solution, you need to use pjsip's SRV resolution functions to resolve sip2sip.info srv record e.g: "_sip._udp.sip2sip.info" and then set the outbound_proxy records with the result.
The code is a little bit involved.
pjsip_resolver_t* resolver_;
...
status = pjsip_resolver_create( pool, &resolver_ );
...
pjsip_host_info host;
host.flag = PJSIP_TRANSPORT_DATAGRAM; // is using UDP, see pjsip_transport_flags_e
host.type = PJSIP_TRANSPORT_UDP; // if using UDP, see pjsip_transport_type_e
host.addr.host = pj_str("sip2sip.info");
host.addr.port = 5060;
pjsip_resolve(resolver_, pool, &host, token, resolver_cb_func);
...
static void resolver_cb_func( pj_status_t status, void *token, const struct pjsip_server_addresses *addr)
{
...
// use results to fill in the outbound_proxy
}
You could also take it further to support failover, but it looks like sip2sip doesn't have multiple sip servers in there DNS SRV record so it will not be used currently. If they ever add more then it would become more useful.
_sip._udp.sip2sip.info
Server: fritz.box Address: fd00::2665:11ff:fef9:ec51
Non-authoritative answer:
_sip._udp.sip2sip.info SRV service location:
priority = 100
weight = 100
port = 5060
svr hostname = proxy.sipthor.net
sip2sip.info nameserver = ns2.dns-hosting.info
sip2sip.info nameserver = ns1.dns-hosting.info
sip2sip.info nameserver = ns7.dns-hosting.info
Sip2Sip also support STUN setup, so I would also setup the STUN settings on the account as well:
cfg.stun_srv_cnt = 1;
cfg.stun_srv[0] = pj_str("sip2sip.info");
Since your example seems to not provide the port information it should work. To diagnose this further would require see the pjsip log output.

Android Connect to wifi with programmatic WifiConfiguration

I have a problem when I want to connect my device to an existing network wifi.
That is the situation:
I am looking to an existing configured network, if there is not the one I am looking for I build it and then I try to connect the phone.
When the wifi configuration is built manually using the phone interface, I can find it and then connect to it.
But when I tried to build the configuration programmaticly Android cannot connect the phone to the network.
I have got the following message : "Association request to the driver failed".
I am wondering if the association that failed is the association between the scanned network and the configurated network. BUt I don't know why and so I don't know how to manage this problem.
EDIT: And I forget to say, that my WifiConfiguration is exactly the same as the one is created manually because I get the info from the conf with some logs.
EDIT2 : Here is my wificonf (network is protected by a wep key) :
WifiConfiguration wifiConf = new WifiConfiguration();
wifiConf.SSID = "\"ssid\"";
wifiConf.wepKeys[0] = "\"password\"";
wifiConf.wepTxKeyIndex = 0;
wifiConf.hiddenSSID = false;
wifiConf.status = WifiConfiguration.Status.DISABLED;
wifiConf.priority = 40;
wifiConf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wifiConf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wifiConf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wifiConf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wifiConf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);//+
wifiConf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);//+
wifiConf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
EDIT3 : I already add the permission in AndroidManifest :
uses-permission android:name="android.permission.ACCESS_WIFI_STATE"
uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"
uses-permission android:name="android.permission.CHANGE_WIFI_STATE"
I hope my problem is clear and hope too that someone could help me.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
This is the correct form of this setting:
wifiConfiguration.SSID = "\"" + networkSSID + "\"";

Unable to configure the wifi open network programmatically android?

I have written code for adding open network to wifi configured list.It adds the open network to configured lists and displays the same SSID's in Wifi Settings.but it adds the same network with same name extra but it doesn't shows any open network When i press on the second on alert shows with Security WEP the following text i observed with those same networks
1) Open network
2) remembered , not in range
But i want to add open network into my list, why this extra one is added and if i connect the same network it is trying to connect to the (2) one programmatically.Actually I changed secured network to open network for this trial.It displays with open network text and when i press on that one it obtains the address and connects succesfully manually.Why this extra one is adding how can i add the open network to my list.For reference plz see the link for image.
http://www.freeimagehosting.net/uploads/3dbccfc2bd.png
Code snippet :
String hotSpotSsid = hotSpot.SSID;
String hotSpotBssid = hotSpot.BSSID;
Log.i(TAG,"in RSSI Changed Acion SSID: "+hotSpotSsid+" BSSID: "+hotSpotBssid);
StringBuffer sBuf = new StringBuffer("\"");
sBuf.append(hotSpotSsid+"\"");
hotSpotSsid = sBuf.toString();
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = hotSpotSsid;
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
wifiConfiguration.BSSID = hotSpotBssid;
wifiConfiguration.hiddenSSID = false;
// wifiConfiguration.priority = 1;
// add this to the configured networks
int inetId = wifiManager.addNetwork(wifiConfiguration);
Log.i(TAG,"INetId :"+inetId);
configs = wifiManager.getConfiguredNetworks();
Log.e(TAG,"After adding config :"+configs);
if(inetId < 0) {
Log.i(TAG,"Unable to add network configuration for SSID: "+hotSpotSsid);
return;
}else {
message="\t Successfully added to configured Networks";
Log.i(TAG,message);
}
regards,
Rajendar
Try removing SSID and seeing if it works. I was having a similar issue and that worked for me.
Appending and prepending quotes to the SSID, as you did, should work though. Not sure why it doesn't.
Give SSID as wifiConfiguration.SSID = "\"".concat(SSID_NAME).concat("\"");

Categories

Resources