Search Unity

Windows UWP -> Application.internetReachability Broken?

Discussion in 'Windows' started by PeachyPixels, Feb 25, 2021.

  1. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Hello!

    I'm running some tests on the final build of my game and just noticed that Application.internetReachability is not working as it used to.

    When running the UWP build, turning off Wi-Fi or turning on Airplane Mode would always return NotReachable but now it's returning ReachableViaLocalAreaNetwork

    When running in the editor, the correct behaviour is observed.

    Tested on the following setup...

    Windows 10 (19042.844)
    Unity 2019.4.21f1
    Master x64
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Did it work in a previous Unity version? Or just at some point in time before? I've looked at the source code and the implementation for UWP hasn't been touched since 2014.

    Internally, we call Windows::Networking::Connectivity::NetworkInformation::GetHostNames(), and if any are found, we return ReachableViaLocalAreaNetwork. We also distinguish between carrier network and local area network depending on the interface type.

    However, if it doesn't match what you see in the editor, could you file a bug report? We want to potentially fix it.
     
  3. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    It did yes, 100% sure of that.

    I've protected any code that requires online access (i.e. IAP) with an online check. I used to test it by enabling airplane mode.

    To be honest, it's been months since I last tested that particular feature and I've installed many Unity & Windows updates since then. It could very well be anyone one of those. I'm assuming the editor & runtime make the same internal WinAPI calls?
     
  4. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Running a UWP build...

    Image1 = Online
    Image2 = Airplane Mode

    But as you can see, the debug log shows the same result.
     

    Attached Files:

  5. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Running in the editor...

    Image3 = Airplane Mode

    So I'm seeing the correct behaviour.
     

    Attached Files:

  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    No, the editor uses INetworkListManager, which isn't available on UWP.

    Anyway, the way we check for it in UWP isn't great. A better way to do this, would be ConnectionProfile::GetNetworkConnectivityLevel. Can you report a bug on this so we could fix it?

    To workaround, you can call that API from script directly:

    Code (csharp):
    1. static bool IsInternetAvailable()
    2. {
    3. #if !UNITY_WSA || UNITY_EDITOR
    4.     return Application.internetReachability != NetworkReachability.NotReachable;
    5. #else
    6.     var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
    7.     if (connectionProfile == null)
    8.         return false;
    9.  
    10.     returm connectionProfile == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess;
    11. #endif
    12. }
    13.  
     
    unity_xQiX8UkXp6xfzg likes this.
  7. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Thanks for feedback, it's much appreciated.

    Spotted a few typos in the code, but fixed them and can confirm this is working well in a UWP build.

    The revised code is...
    Code (CSharp):
    1. static bool IsInternetAvailable()
    2. {
    3. #if !UNITY_WSA || UNITY_EDITOR
    4.     return Application.internetReachability != NetworkReachability.NotReachable;
    5. #else
    6.     var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
    7.     if (connectionProfile == null)
    8.       return false;
    9.     return connectionProfile.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess;
    10. #endif
    11. }
    I'll look into reporting it, but no promises as literally have a list of a hundred things to-do leading up-to launch.

    Thanks again.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Sorry for the typos, typed it directly into the forum post without trying to build it :D.
     
    PeachyPixels likes this.
  9. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    No need to apologise. Impressed you typed it by hand and it was pretty much spot on.

    I haven't touched UWP in about 5 years, so am rusty and grateful for the workaround :)
     
  10. marck_ozz

    marck_ozz

    Joined:
    Nov 30, 2018
    Posts:
    107
    Hello!!

    Any update on this?

    I have the same result using:

    Windows 10 19041.1052
    Unity 2020.3.3f1
    Release x64

    The workaround works as it should be, Thanks!!
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    I think this fell out of our radar. I don't think we ever received a bug report.
     
  12. marck_ozz

    marck_ozz

    Joined:
    Nov 30, 2018
    Posts:
    107
    Does it worths it to do a bug report? most (or all) of the functionalities for UWP can be called directly from the WinRT APIs, but I thing a bug report can make you guys have a look on this kind of things.

    Most of the info related with Unity/UWP seems out of date (on windows docs side too) and with the intro of Windows 11 this feels like we (unity users) are out of the race. I think UWP is a really good platform for games and apps.

    Saludos.
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Yes, bug reports are definitely very useful. They make sure that the issue is logged, can be searched for on issuetracker.unity3d.com. Also, we cannot really forget about things that are logged as bugs.

    I'm not quite sure what you mean by this? Windows 11 shouldn't really change anything for developers AFAIK.
     
  14. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Apologies @Tautvydas-Zilys

    I was side-tracked at the time then completely forgot :rolleyes:

    I'll try and submit one before the weekend.
     
  15. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Hi @Tautvydas-Zilys,

    This has been reported as case 1351079

    Apologies for taking so long.
     
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Thanks for the report!
     
    PeachyPixels likes this.
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    The fix landed to 2021.2.6f1 and 2020.3.25f1.
     
    PeachyPixels likes this.
  18. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Many thanks @Tautvydas-Zilys :)

    I'll test it with 2020.3.25f1 as soon as it's released and will report back if there are any issues.
     
  19. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    Tautvydas-Zilys likes this.