googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.37k stars 1.08k forks source link

InterstitialAd.IsLoaded() returning TRUE despite no network permissions and java.net.SocketException: Permission denied on Android #805

Closed ecv80 closed 5 years ago

ecv80 commented 5 years ago

Hi,

I'm trying to show in-house ads (more on that later) instead of Admob ones when the network isn't available in my Unity game. I have tried it with the phone flight mode and so far so good. The problem arises when I purposefully deny WIFI/data permissions in my phone (Xiaomi Redmi Note 5A) for my game. Somewhere on the Java side, I'm getting a "java.net.SocketException: Permission denied" which I guess is expected, but apparently the Admob SDK isn't dealing with the issue appropriately (IMO) and the plugin is making InterstitialAd.IsLoaded() return true. After checking for IsLoaded() I proceed to show the interstitial, and a black screen with the typical close button is shown, but that's all that's shown.

My problem is not so much wanting to load an interstitial (because it would never load under this circumstance) as it is to properly figure out when there is a network problem (even if purposefully caused by the user by blocking WIFI/data permissions) to instead show my in-house ads.

I registered all ad events (as shown here) to try and get a better insight of what's going on, but OnAdFailedToLoad is never called under this circumstance. Strangely enough I am getting an OnAdLoaded despite the fact that the ad couldn't possibly load in this circumstance. So I'm really confused. Since I think it's not possible to handle the java.net.SocketException from the C# side, I'm clueless as to how to proceed from here to fix the issue. While this might not be a bug in itself, it's certainly a feature preventing the proper handling of the aforementioned situation.

BTW, I'm using only the test ads IDs and my device is not included as a test device (for showing real ads) yet. Under normal circumstances the test ads show just fine.

Here's the filtered log (I'm also loading a rewarded video):

11-13 08:53:31.465 9931 9931 I Ads : Updating ad debug logging enablement. 11-13 08:53:31.581 9931 9931 I Ads : Starting ad request. 11-13 08:53:31.582 9931 9931 I Ads : SDK version: afma-sdk-a-v14574020.12451000.1 11-13 08:53:31.583 9931 9931 I Ads : Use AdRequest.Builder.addTestDevice("CENSORED") to get test ads on this device. 11-13 08:53:31.596 9931 9931 W Ads : Not retrying to fetch app settings 11-13 08:53:31.640 9931 10202 W Ads : Invoke Firebase method getInstance error. 11-13 08:53:31.641 9931 10202 W Ads : The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date 11-13 08:53:31.686 9931 9931 I Ads : Updating ad debug logging enablement. 11-13 08:53:31.698 9931 9931 I Ads : Starting ad request. 11-13 08:53:31.698 9931 9931 I Ads : SDK version: afma-sdk-a-v14574020.12451000.1 11-13 08:53:31.699 9931 9931 I Ads : Use AdRequest.Builder.addTestDevice("CENSORED") to get test ads on this device. 11-13 08:53:31.707 9931 9931 W Ads : Not retrying to fetch app settings 11-13 08:53:31.753 9931 10139 W Ads : Update ad debug logging enablement as false 11-13 08:53:31.764 9931 10213 W Ads : Update ad debug logging enablement as false 11-13 08:53:32.136 15833 25818 W Ads : App does not have the required permissions to get location 11-13 08:53:32.144 15833 10243 W Ads : App does not have the required permissions to get location

11-13 08:53:33.299 9931 9931 I Ads : Starting ad request. 11-13 08:53:33.299 9931 9931 I Ads : SDK version: afma-sdk-a-v14574020.14574000.1 11-13 08:53:33.300 9931 9931 I Ads : Use AdRequest.Builder.addTestDevice("CENSORED") to get test ads on this device. 11-13 08:53:33.307 9931 9931 W Ads : Not retrying to fetch app settings 11-13 08:53:33.324 9931 9931 E Ads : JS: Uncaught ReferenceError: renderAd is not defined (https://googleads.g.doubleclick.net/mads/gma?_activity_context=true&android_num_video_cache_tasks=0&caps=inlineVideo_interactiveVideo_mraid1_mraid2_sdkVideo_th_autoplay_mediation_av_transparentBackground_sdkAdmobApiForAds_di_aso_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_gcache_xSeconds&eid=CENSORED&format=interstitial_mb&heap_free=3988936&heap_max=201326592&heap_total=16930600&js=afma-sdk-a-v14574020.12451000.1&mr=512650596500802534%2C611496526858695445%2C-438303185308675417%2C-817861071498010165%2C-976981249673186934%2C2504653959160252441%2C4867349097048287186%2C5051757249200318413%2C5705181604988988735%2C6163540814278103738%2C6197572481830883842%2C6234159758225894597%2C6382848672116010643%2C7403133549427062145%2C7941544447394751756%2C8322877094104751041%2C8744318498482049952%2C-1900680577090094200%2C-3581963402627207784%2C-3868972836784826320%2C-4692607428994946862%2C-9022116523718885931&msid=CENSORED&preqs=1&request_pkg=com.google.unity.ads.Interstitial%242&scroll_index=-1&seq_num=2&target_api=26:1)

11-13 08:53:33.339 9931 9931 E Ads : JS: Uncaught ReferenceError: onLoad is not defined (https://googleads.g.doubleclick.net/mads/gma?_activity_context=true&android_num_video_cache_tasks=0&caps=inlineVideo_interactiveVideo_mraid1_mraid2_sdkVideo_th_autoplay_mediation_av_transparentBackground_sdkAdmobApiForAds_di_aso_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_gcache_xSeconds&eid=CENSORED&format=interstitial_mb&heap_free=3988936&heap_max=201326592&heap_total=16930600&js=afma-sdk-a-v14574020.12451000.1&mr=512650596500802534%2C611496526858695445%2C-438303185308675417%2C-817861071498010165%2C-976981249673186934%2C2504653959160252441%2C4867349097048287186%2C5051757249200318413%2C5705181604988988735%2C6163540814278103738%2C6197572481830883842%2C6234159758225894597%2C6382848672116010643%2C7403133549427062145%2C7941544447394751756%2C8322877094104751041%2C8744318498482049952%2C-1900680577090094200%2C-3581963402627207784%2C-3868972836784826320%2C-4692607428994946862%2C-9022116523718885931&msid=CENSORED&preqs=1&request_pkg=com.google.unity.ads.Interstitial%242&scroll_index=-1&seq_num=2&target_api=26#_activity_context=true&android_num_video_cache_tasks=0&caps=inlineVideo_interactiveVideo_mraid1_mraid2_sdkVideo_th_autoplay_mediation_av_transparentBackground_sdkAdmobApiForAds_di_aso_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_gcache_xSeconds&eid=CENSORED&format=interstitial_mb&heap_free=3988936&heap_max=201326592&heap_total=16930600&js=afma-sdk-a-v14574020.12451000.1&mr=512650596500802534%252C611496526858695445%252C-438303185308675417%252C-817861071498010165%252C-976981249673186934%252C2504653959160252441%252C4867349097048287186%252C5051757249200318413%252C5705181604988988735%252C6163540814278103738%252C6197572481830883842%252C6234159758225894597%252C6382848672116010643%252C7403133549427062145%252C7941544447394751756%252C8322877094104751041%252C8744318498482049952%252C-1900680577090094200%252C-3581963402627207784%252C-3868972836784826320%252C-4692607428994946862%252C-9022116523718885931&msid=CENSORED&preqs=1&request_pkg=com.google.unity.ads.Interstitial%25242&scroll_index=-1&seq_num=2&target_api=26:1)

11-13 08:53:53.196 9931 9931 W Ads : Failed to load ad: 3

11-13 08:54:33.430 9931 9931 E Ads : Timed out waiting for WebView to finish loading.

11-13 08:56:28.430 9931 10202 W Ads : Error while pinging URL: https://pagead2.googleadservices.com/pagead/adview?ai=CKDil_ILqW6KYM8yP1gbN4L1I7LHsulOWxtbm3Qfkq-nluAEQASDC7NwgYNXl2oKwCYgBAaAB-9TS1wOpAtd5piO9Mqg-qAMBqgTHAU_QrPxqJMSXlfSayJeo3RTVMz8_bA3xS1Gcxu5mjwQSqhVq6sv0ewZ51ky1xBQNRH5EPfNBXBMhdU2nLO-AxQQ_hFNxXKj75KL5sLgtjZiG4YyV6Evdx4AS4YNvbt4HLxf_Ibr5obet_DrtCf6jNcjwVScrNCELJpV3EJDiCDSFeQfn9OOxn1j0kzJ_pmjAFFjCZfvAZwECxNiYJN7ZQzdn2Gpl_h1-ESKAszqTkHxBPhBGDKOVGEavCjRga5mKh6MUilZAfHLABM-LtobnAYgFqK-16gWQBgGgBjnABguAB-2qrSiIBwGQBwKYBwGoB6a-G6gH1ckbqAehAagH2csbqAfPzBvYBwGgCOuvPbAIAtIICQiAgIAQEAIYArEJHcgvLrH0UP-CFCYaJG1vYmlsZWFwcDo6Mi1jb20uZWN2YXJ0cy5hYWEuc3dlZXBlcg&sigh=SC2kSL04ZZ4&cid=CENSORED&gvr=1. Permission denied

And here's the filtered log when using flight mode and no network permission restrictions, for comparison:

11-13 09:11:49.476 11653 11653 I Ads : Updating ad debug logging enablement. 11-13 09:11:49.562 11653 11653 I Ads : Starting ad request. 11-13 09:11:49.562 11653 11653 I Ads : SDK version: afma-sdk-a-v14574020.12451000.1 11-13 09:11:49.564 11653 11653 I Ads : Use AdRequest.Builder.addTestDevice("CENSORED") to get test ads on this device. 11-13 09:11:49.578 11653 11653 W Ads : Not retrying to fetch app settings 11-13 09:11:49.628 11653 11883 W Ads : Invoke Firebase method getInstance error. 11-13 09:11:49.628 11653 11883 W Ads : The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date 11-13 09:11:49.687 11653 11653 I Ads : Updating ad debug logging enablement. 11-13 09:11:49.700 11653 11653 I Ads : Starting ad request. 11-13 09:11:49.700 11653 11653 I Ads : SDK version: afma-sdk-a-v14574020.12451000.1 11-13 09:11:49.701 11653 11653 I Ads : Use AdRequest.Builder.addTestDevice("CENSORED") to get test ads on this device. 11-13 09:11:49.711 11653 11653 W Ads : Not retrying to fetch app settings 11-13 09:11:49.752 11653 11845 W Ads : Update ad debug logging enablement as false 11-13 09:11:49.762 11653 11888 W Ads : Update ad debug logging enablement as false 11-13 09:11:50.229 15833 10243 W Ads : App does not have the required permissions to get location 11-13 09:11:50.230 15833 25818 W Ads : App does not have the required permissions to get location 11-13 09:11:50.419 15833 10243 W Ads : Error while connecting to ad server: Unable to resolve host "googleads.g.doubleclick.net": No address associated with hostname 11-13 09:11:50.452 11653 11667 W Ads : There was a problem getting an ad response. ErrorCode: 2 11-13 09:11:50.455 11653 11653 W Ads : Failed to load ad: 2 11-13 09:11:50.505 15833 25818 W Ads : Error while connecting to ad server: Unable to resolve host "googleads.g.doubleclick.net": No address associated with hostname 11-13 09:11:50.507 11653 11667 W Ads : There was a problem getting an ad response. ErrorCode: 2 11-13 09:11:50.507 11653 11653 W Ads : Failed to load ad: 2

Please do ask me to attach the Unity log if you need it too and/or add a minimal reproduction project.

As for the reason for showing in-house ads when no network is available, it's simple: Even if users may not be able to reach in-house ads links because the network is down, there are still two benefits to it: 1. It discourages users from blocking network from the app as they will still get in-house ads with a same annoying net effect. 2. Despite being unable to navigate to in-house ads links, users still get a memory imprint as it is the case with non-interactive ads/commercials such as those on TV, radio, newspapers, etc. I'm not willing to discuss the morality or efficacy of showing in-house ads. Thanks for your understanding.

I hope we can come up with a work-around for this issue. Thanks in advance.

ecv80 commented 5 years ago

So I used Dns.GetHostEntry and Ping on googleads.g.doubleclick.net to check every minute if there's true access to the server, but it's one ugly hack that isn't working probably because the DNS may be cached and Unity might be spawning a new process to run the ping which I guess will effectively overcome the app-specific network restrictions.

I'm giving up for the moment.

rampara commented 5 years ago

@ecv80 how are you denying internet permissions to an app when the internet permission is granted by default to all Android apps? Are you using the latest version of the Google Mobile Ads SDK?

rampara commented 5 years ago

Closing due to non-response.

ecv80 commented 5 years ago

Sorry for the delay. I was pretty sure I had answered the question. Turns out I had not.

Data usage restriction is a feature present in MIUI 9.6 (Xiaomi's customized Android OS), accessible through Settings->Installed Apps->[App Name]->Restrict data usage->[Wi-Fi / Mobile data]

I don't know how the data restriction is carried out internally, but as per the OP it seems to work fundamentally different than flight mode.

I don't know how to check the Google Mobile Ads SDK version. I've found I have a file named GoogleMobileAdsDependencies under my project Assets/GoogleMobileAds/Editor referring to this library: com.google.android.gms:play-services-ads:15.0.1

I'd like to remark that while this might not be a standard feature of Android OS, as per this article as of 2018 Q1 Xiaomi is ranked 4th in European Android market share with a growth of over 1,000%. So a fix or workaround might be desirable.