googleads / googleads-mobile-unity

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

[Android] Application Preferences Returns the wrong shared preferences instance for User Messaging Platform #3180

Closed KarahanOnarlar closed 1 week ago

KarahanOnarlar commented 4 months ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

I don't understand why it is documented this way in the Google documents, but the shared preferences example where the User Messaging Platform SDK writes the data is not PreferenceManager.getDefaultSharedPreferences(activity).

After much effort, I was able to find the real preference example. This needs to be fixed because we need to be able to read our consent statuses in order to set up our own front disclosure panels and comply with GDPR & Apple etc policies. For example, in our case, we are using the pre-Att description panel, so we want ATT ourselves. And we need to apply ATT permission only if the necessary permissions have been granted. Otherwise, Apple rejects the update because another permission is requested even though the user does not give permission.

Since I am currently writing my own plugin, this is not a problem for me, but it is a problem for those who are not aware of it.

Relevant Code:

Here is the correct code. Apart from Unity, this also needs to be fixed in the Google documents for Android.

  public UnityApplicationPreferences(final Activity activity)
{
    defaultSharedPreferences = activity.getSharedPreferences(activity.getPackageName().concat("_preferences");
}
NVentimiglia commented 3 months ago

Hi @KarahanOnarlar

I was not able to replicate this on Unity 2023 and plugin version 8.7.0.

I changed the hello world sample like this :

image

And was able to retrieve the IABTCF_PurposeConsents value:

image
KarahanOnarlar commented 3 months ago

Hi @NVentimiglia

Are we sure this test for the android platform and not ios because I tested it maybe dozens of times and the results were always empty. There is no problem on iOS side, only Android.

The data is always saved in "packagename_preferences" unless it is passed with a special key in the form of "key/value". If passed as "key/value", the value is saved in sharedPreferences(key).

Let me also send you the screenshot of the shared pref code where the actual values I found by scraping the ump v2.2.0 SDK are set. Ekran görüntüsü 2024-03-06 030658

This is the code that I detected and reached while watching logcat, thanks to the logs saying that the data was not found. The zzco.zza code I chose is the code in the screenshot above. Ekran görüntüsü 2024-03-06 032051

NVentimiglia commented 3 months ago

@KarahanOnarlar

I just retested this on Unity 2021 and 2023 to rule out a difference in engines.

High level here is my understanding :

The decompiled code is interesting, but to get this fixed I need clear replication steps.

I will have a colleague take a look at this as well to make sure I am not missing anything.

KarahanOnarlar commented 3 months ago

@NVentimiglia This is really weird because I tried dozens of times with the exact same code contained in ApplicationPreferences and the results were all empty. Otherwise I wouldn't have spent so much time dealing with minified source code.

Although there are things I said before, all I know to reproduce is to build on the android device using ump sdk v2.2.0 and query the tcf string or isGdpr value. It works smoothly on iOS device, but the data is empty on Android.

NVentimiglia commented 3 months ago

@KarahanOnarlar

Can you modify the helloworld sample app and link me to the fork / zip ?