4

I am trying to port application that connects to specific WiFi network with WPA passphrase from Android 9 to 10 (API 29). I am using code/suggestions from the documentation :

final WifiNetworkSpecifier specifier = new WifiNetworkSpecifier.Builder().setSsid("test").setWpa2Passphrase("password").build() 
final NetworkRequest request = new NetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
    .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).setNetworkSpecifier(specifier).build(); 
final ConnectivityManager connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE); 
final NetworkCallback networkCallback = new NetworkCallback() { 
    Override void onAvailable(Network network) {Log.d(TAG, "onAvailable");}
    Override void onLinkPropertiesChanged(Network network) {Log.d(TAG, "onLinkPropertiesChanged");}
    Override void onBlockedStatusChanged(Network network) {Log.d(TAG, "onBlockedStatusChanged");}
    Override void onLost(Network network) {Log.d(TAG, "onLost");}
}; 
connectivityManager.requestNetwork(request, networkCallback);

However I can not get anything useful as I am constantly getting window with my network. After trying to connect I am getting small pop-up that connection is established, but window is not disappearing and I am not connected. From the logs I can tell that something is happening

12-18 22:24:29.529 24063 24095 D com.example.org: onAvailable

12-18 22:24:29.532 24063 24095 D com.example.org: onLinkPropertiesChanged

12-18 22:24:29.532 24063 24095 D com.example.org: onBlockedStatusChanged false

12-18 22:24:29.596 24063 24095 D com.example.org: onLost

There is even log that suggests that for very short period of time network is connected

12-18 22:46:43.401  1498  2004 D ConnectivityService: NetworkAgentInfo [WIFI () - 234] validation passed
12-18 22:46:43.402  1498  1498 D OpSlaManager: Received broadcast:android.net.network.CONNECTION_CHANGE
12-18 22:46:43.402  1498  1498 D OpSlaManager: ifaceUp:true ni:[type: WIFI[], state: CONNECTED/CONNECTED, reason: 
    (unspecified), extra: (none), failover: false, available: true, roaming: false]
12-18 22:46:43.403  1498  1498 D OpSlaManager:  lp:{InterfaceName: wlan0 LinkAddresses: [ fe80::7854:b0ff:fec2:5995/64,192.168.150.160/24 ] 
    DnsAddresses: [ /192.168.150.4,/8.8.8.8 ] Domains: null MTU: 1500 TcpBufferSizes: 524288,1048576,4194304,524288,1048576,4194304 
    Routes: [ fe80::/64 -> :: wlan0,192.168.150.0/24 -> 0.0.0.0 wlan0,0.0.0.0/0 -> 192.168.150.1 wlan0 ]} nc:[ Transports: WIFI Capabilities: 
    NOT_METERED&NOT_RESTRICTED&TRUSTED&NOT_VPN&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED LinkUpBandwidth>=1048576Kbps 
    LinkDnBandwidth>=1048576Kbps Specifier: <WifiNetworkAgentSpecifier [WifiConfiguration=, SSID="NetworkSSID", 
    BSSID=ff:ff:ff:aa:aa:aa, mOriginalRequestorUid=10336, mOriginalRequestorPackageName=com.example.org]> SignalStrength: -45 SSID: "NetworkSSID"]

Unfortunatelly somewhere in the log there is wpa_supplicant info telling that it could not last.

wpa_supplicant: wlan0: CTRL-EVENT-DISCONNECTED bssid=ff:ff:ff:aa:aa:aa reason=3 locally_generated=1

I tried with both 2.4/5GHz networks, but this did not make a difference. Can someone point me in the right direction or maybe have a code that is able to connect to a WiFi network on Android 10.

Community
  • 1
  • 1
bialy
  • 193
  • 2
  • 14
  • Same Problem here, any Idea? https://stackoverflow.com/questions/59984518/android-q-wifinetworkspecifier-loosing-wifi-immediately-after-connection-is-est – Johannes Jan 30 '20 at 11:12
  • Were you able to find a solution? We found the same problem with OnePlus phones. – E Rullmann Feb 05 '20 at 03:30
  • check my answer here https://stackoverflow.com/questions/59984518/android-q-wifinetworkspecifier-loosing-wifi-immediately-after-connection-is-est?answertab=active#tab-top – hacker Mar 05 '20 at 05:18
  • Fixed for me with OTA update 10.0.11.HD65BA Oneplus 7T – Aristide13 Jun 18 '20 at 07:16

0 Answers0