When casting via Wifi to a Chromecast, I have users who have complained about losing connection on Android 6 devices. When looking through the logs I see this:
12-09 19:18:56.473 I/Router ( 5337): Connectivity change detected...
12-09 19:18:56.473 I/Router ( 5337): EXTRA_NO_CONNECTIVITY: true
12-09 19:18:56.473 I/Router ( 5337): EXTRA_REASON: null
12-09 19:18:56.473 I/Router ( 5337): EXTRA_IS_FAILOVER: false
12-09 19:18:56.473 I/Router ( 5337): EXTRA_NETWORK_INFO: [type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: <unknown ssid>, roaming: false, failover: false, isAvailable: true]
12-09 19:18:56.473 I/Router ( 5337): EXTRA_OTHER_NETWORK_INFO: none
12-09 19:18:56.473 I/Router ( 5337): EXTRA_EXTRA_INFO: <unknown ssid>
12-09 19:18:56.475 I/NetworkUtils( 5337): Could not find any connected network...
12-09 19:18:57.475 W/Router ( 5337): WIFI => NONE network transition, waiting for new network... retry #1
12-09 19:18:57.476 I/Router ( 5337): Network type changed WIFI => MOBILE
12-09 19:18:57.477 I/Router ( 5337): WiFi multicast lock released
12-09 19:18:57.478 I/Router ( 5337): WiFi lock released
12-09 19:18:57.521 I/Router ( 5337): Disabled router on network type change (old network: WIFI)```
As you can probably guess, turning of Wifi in the middle of casting causes issues. This only appears to be a issue with devices running Android 6, so I assume it has something to do with the new doze mode. I see Doze mode and foreground service has established that foreground services will not get dozed (and I can confirm this), but it doesn't seem to have stopped the doze from removing necessary network access. While I haven't received any complaints about DLNA casting yet, I imagine it would have the same issues there. This would also cause issues if an app was actively streaming music and was forced to use the mobile network for no compelling reason. Is there a way to prevent Doze from shutting down Wifi access when it is being used by a foreground app?