Skip to content

device.geo.country is being sent in iso alpha-2 format #872

@justadreamer

Description

@justadreamer

Describe the bug
We noticed that device.geo.country is populated from carrier data and is sent in alpha-2 format, while OpenRTB spec demands it to be in alpha-3 format, see [here].(https://github.com/InteractiveAdvertisingBureau/openrtb2.x/blob/main/2.6.md#:~:text=ISO%2D3166%2D1-,%2Dalpha%2D3,-.)

To Reproduce
Intercept a request from a demo app running on a physical device using Charles and check device.geo.country.
It is in alpha-2 format.

Expected behavior
device.geo.country should not be populated by the SDK from the carrier data as it is expected to be populated from reverse-geocoding the coordinates if they are sent on the server. iOS does not populate this field. However if we choose to populate it then it should be in alpha-3 format as OpenRTB spec requires.

Additional context
Additionally @takenorim has pointed out the following details:

I found the Prebid Mobile Android SDK uses Android's native API getSimCountryIso or getNetworkCountryIso.
And, the API doc said it will return ISO-3166-1 alpha-2 country code (e.g. US)

In prebid-mobile-android/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/GeoLocationParameterBuilder.java:

    private String getTelephonyCountry(Context ctx){
        TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);


        if(tm != null) {
            String simCountry = tm.getSimCountryIso().toUpperCase();
            String networkCountry = tm.getNetworkCountryIso().toUpperCase();

The first one returns the ISO-3166-1 alpha-2 country code equivalent for the SIM provider's country code.
The second one returns the ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) of the current registered operator or the cell nearby, if available. Note: Result may be unreliable on CDMA networks (use getPhoneType() to determine if on a CDMA network)

The following changes may fix it:

In prebid-mobile-android/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/GeoLocationParameterBuilder.java:

            String simCountry = tm.getSimCountryIso().toUpperCase();
            String networkCountry = tm.getNetworkCountryIso().toUpperCase();

=>

            String simCountry = (new Locale("en", tm.getSimCountryIso()).getISO3Country()).toUpperCase();
            String networkCountry = (new Locale("en", tm.getNetworkCountryIso()).getISO3Country()).toUpperCase();

However it is debatable whether we should even send this as this data is expected to be obtained from the coordinates via reverse-geocoding rather than carrier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions