How to avoid WiFi disconnection if Google cannot be pinged? Say I have blocked google and the sorts with my router. Now Android thinks that the wifi has no connection because it can't ping google and uses my mobile data instead although the WiFi is perfectly fine.

How can I tell my phone to ping some other server in order to check the connection? (root is an option).
You can either disable captive portal detection:

adb shell 'settings put global captive_portal_detection_enabled 0'
adb shell 'settings put global captive_portal_mode 0'


(set to 1 to re-enable), or set a different server. I use e.g.:

adb shell 'settings put global captive_portal_http_url "http://captiveportal.kuketz.de"'
adb shell 'settings put global captive_portal_https_url "https://captiveportal.kuketz.de"'
adb shell 'settings put global captive_portal_fallback_url "http://captiveportal.kuketz.de"'
adb shell 'settings put global captive_portal_other_fallback_urls "http://captiveportal.kuketz.de"'


This works fine for me on Android 8 (Oreo). For more details (and other Android versions), you can e.g. refer to Captive Portal parameters.

(As for the URLs I use: Mike Kuketz is a security expert in Germany, with focus on privacy. I know him personally and fully trust him. You could also setup your own captive portal server – it's not that hard, but goes a bit beyond our site. See above linked Wikipedia article for details on that if you're interested.)