Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - EU Cookie Law

The upcoming Google policy changes, compel us to implement a dialog to notify EU users about cookie/device identifier usage for advertising and analytics. I'd like to show this dialog only to EU users. I don't want to use additional permissions (e.g. android.permission.ACCESS_COARSE_LOCATION). Therefore I have created a function to test for EU users:

Android

boolean showCookieHint()
{
    final SharedPreferences settings = getSharedPreferences("localPreferences", Context.MODE_PRIVATE);
    if (settings.getBoolean("termsAccepted", true)  == false) return false;

    List<String> list = new ArrayList<String>();
    list.add("AT"); //Austria
    list.add("BE"); //Belgium
    list.add("BG"); //Bulgaria
    list.add("HR"); //Croatia
    list.add("CY"); //Cyprus
    list.add("CZ"); //Czech Republic
    list.add("DK"); //Denmark
    list.add("EE"); //Estonia
    list.add("FI"); //Finland
    list.add("FR"); //France
    list.add("GF"); //French Guiana
    list.add("PF"); //French Polynesia
    list.add("TF"); //French Southern Territories
    list.add("DE"); //Germany
    list.add("GR"); //Greece
    list.add("HU"); //Hungary
    list.add("IE"); //Ireland
    list.add("IT"); //Italy
    list.add("LV"); //Latvia
    list.add("LT"); //Lithuania
    list.add("LU"); //Luxembourg
    list.add("MT"); //Malta
    list.add("NL"); //Netherlands
    list.add("PL"); //Poland
    list.add("PT"); //Portugal
    list.add("RO"); //Romania
    list.add("SK"); //Slovakia
    list.add("SI"); //Slovenia
    list.add("ES"); //Spain
    list.add("SE"); //Sweden
    list.add("ES"); //Spain
    list.add("GB"); //United Kingdom of Great Britain and Northern Ireland

    boolean error = false;

    /* is eu sim ? */
    try {
        final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String simCountry = tm.getSimCountryIso();
        if (simCountry != null && simCountry.length() == 2) { 
            simCountry = simCountry.toUpperCase();
            for (int i = 0; i < list.size(); ++i) {
                if (list.get(i).equalsIgnoreCase(simCountry) == true) {
                    ASCore.log(TAG, "is EU User (sim)");
                    return true;
                }
            }
        }
    }
    catch (Exception e) { error = true; }


    /* is eu network */
    try {  
        final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
            String networkCountry = tm.getNetworkCountryIso();
            if (networkCountry != null && networkCountry.length() == 2) {
                networkCountry = networkCountry.toUpperCase();
                for (int i = 0; i < list.size(); ++i) {
                    if (list.get(i).equalsIgnoreCase(networkCountry) == true) {
                        ASCore.log(TAG, "is EU User (net)");
                        return true;
                    }
                }
            }
        }
    }
    catch (Exception e) { error = true; }

    /* is eu time zone id */
    try {
        String tz = TimeZone.getDefault().getID().toLowerCase();
        if (tz.length() < 10) {
            error = true;
        } else if (tz.contains("euro") == true) {
            ASCore.log(TAG, "is EU User (time)");
            return true;
        }
    } catch (Exception e) {
        error = true;
    }

    /* is eu time zone id */
    try {
        String tz = TimeZone.getDefault().getID().toLowerCase();
        if (tz.length() < 10) {
            error = true;
        } else if (tz.contains("europe") == true) {
            ASCore.log(TAG, "is EU User (time) ");
            return true;
        }
    } catch (Exception e) {
        error = true;
    }


    if (error == true) {
        ASCore.log(TAG, "is EU User (err)");
        return true;
    }

    return false;
}

iOS

-(bool) showCookieHint {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:@"termsAccepted"]) return false;

CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = network_Info.subscriberCellularProvider;


std::vector<NSString*> list;
list.push_back(@"AT"); //Austria
list.push_back(@"BE"); //Belgium
list.push_back(@"BG"); //Bulgaria
list.push_back(@"HR"); //Croatia
list.push_back(@"CY"); //Cyprus
list.push_back(@"CZ"); //Czech Republic
list.push_back(@"DK"); //Denmark
list.push_back(@"EE"); //Estonia
list.push_back(@"FI"); //Finland
list.push_back(@"FR"); //France
list.push_back(@"GF"); //French Guiana
list.push_back(@"PF"); //French Polynesia
list.push_back(@"TF"); //French Southern Territories
list.push_back(@"DE"); //Germany
list.push_back(@"GR"); //Greece
list.push_back(@"HU"); //Hungary
list.push_back(@"IE"); //Ireland
list.push_back(@"IT"); //Italy
list.push_back(@"LV"); //Latvia
list.push_back(@"LT"); //Lithuania
list.push_back(@"LU"); //Luxembourg
list.push_back(@"MT"); //Malta
list.push_back(@"NL"); //Netherlands
list.push_back(@"PL"); //Poland
list.push_back(@"PT"); //Portugal
list.push_back(@"RO"); //Romania
list.push_back(@"SK"); //Slovakia
list.push_back(@"SI"); //Slovenia
list.push_back(@"ES"); //Spain
list.push_back(@"SE"); //Sweden
list.push_back(@"ES"); //Spain
list.push_back(@"GB"); //United Kingdom of Great Britain and Northern Ireland

/* is eu sim ? */
NSString* sim = carrier.isoCountryCode;
if (sim != nil) {
    if ([sim length] == 2) {
        NSString* simU = [sim uppercaseString];
        for (int i = 0; i < list.size(); ++i) {
            if ([list[i] compare:simU] == 0) {
                ASCore::log("Core", "is EU User (sim)");
                return true;
            }
        }
    }
}

/* is eu network */
NSString* net = carrier.mobileCountryCode;
if (net != nil) {
    if ([net length] == 2) {
        NSString* netU = [net uppercaseString];
        for (int i = 0; i < list.size(); ++i) {
            if ([list[i] compare:netU] == 0) {
                ASCore::log("Core", "is EU User (net)");
                return true;
            }
        }
    }
}


bool error = false;
/* is local eu time zone id */
NSTimeZone* timeZoneLocal = [NSTimeZone localTimeZone];
NSString* time1 = [[timeZoneLocal name] lowercaseString];
if ([time1 length] > 10) {
    if ([time1 containsString:@"europe"]) {
        ASCore::log("Core", "is EU User (local time)");
        return true;
    }
} else error = true;


/* is default eu time zone id */
NSTimeZone *timeZoneDefault = [NSTimeZone defaultTimeZone];
NSString *time2 = [[timeZoneDefault name] lowercaseString];
if ([time2 length] > 10) {
    if ([time2 containsString:@"europe"]) {
        ASCore::log("Core", "is EU User (default time)");
        return true;
    }
} else error = true;


if (error == true) {
    ASCore::log("Core", "is EU User (err)");
    return true;
}

return false;
}

Is my function enough to detect EU-Users?

Thanks

Ronald

like image 750
Mr.Betatester Avatar asked Jul 31 '15 06:07

Mr.Betatester


People also ask

Do you need a cookie policy on a mobile app?

Mobile apps are no exception: they're required to provide a privacy policy (and, if they make use of cookies and similar tracking technologies, a cookie policy).

What are the requirements of the European Union cookie law?

The EU cookie law requires you to: Refrain from placing trackers and cookies on users' browsers until they've given their consent for you to do so. Ask users for consent to all trackers and cookies on your site. Give users detailed information about all trackers and cookies on your site.

Does GDPR allow cookies?

The EU's GDPR on cookiesYes – under GDPR, cookie IDs are considered personal data. A cookie ID is the identifier that is included within most cookies when set on a user's browser.

Is it a legal requirement to have a cookie policy?

In other words, there is no legal requirement to have a cookie policy, whether on a separate webpage or included within your privacy policy.

How is the EU Cookie Law’s cookie consent requirements interpreted and enforced?

How the EU cookie law’s cookie consent requirements (and the GDPR’s) is interpreted and enforced is defined by the European Data Protection Board (EDPB), and subsequently each EU member state’s data protection authorities (often known as “DPAs”).

Can a cookie be used without consent of the user?

However, cookies are not allowed to be activated and used without such consent from the end-user (except cookies that are strictly necessary for the most basic functions of your website). Does the EU cookie law apply to US websites?

Is your cookie policy GDPR-compliant?

The rules regulating cookies are still being set, and cookies themselves are continually evolving, which means maintaining a current cookie policy will be a continuous job. However, properly informing your users about the cookies your site is using and, when necessary, receiving their consent will keep your users happy and keep you GDPR-compliant.

Which countries have data privacy laws similar to the EU’s?

Many newer data privacy laws, like Brazil’s LGPD and South Africa’s POPIA, are heavily inspired by the EU’s data privacy regime, particularly the ePrivacy Directive’s cookie requirements.


1 Answers

Below is somewhat improved Android code based on Mr. Betatester's answer using enum. I noted that Finland was missing and Spain was mistakenly entered twice. I also removed duplication of the code under /* is eu time zone id */.

private enum EUCountry {
    AT,BE,BG,HR,CY,CZ,DK,EE,FI,FR,DE,GR,HU,IE,IT,LV,LT,LU,MT,NL,PL,PT,RO,SK,SI,ES,SE,GB, //28 member states
    GF,PF,TF, //French territories French Guiana,Polynesia,Southern Territories
    EL,UK,  //alternative EU names for GR and GB
    ME,IS,AL,RS,TR,MK; //candidate countries

    public static boolean contains(String s)
    {
        for (EUCountry eucountry:values())
            if (eucountry.name().equalsIgnoreCase(s))
                return true;
        return false;
    }

};

public static boolean isEU(Activity activity)
{
    boolean error = false;

/* is eu sim */

    try {
        final TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        String simCountry = tm.getSimCountryIso();
        if (simCountry != null && simCountry.length() == 2) {
            simCountry = simCountry.toUpperCase();

            if (EUCountry.contains(simCountry)) {
                Log.v(TAG, "is EU User (sim)");
                return true;
            }
        }
    }
    catch (Exception e) { error = true; }


/* is eu network */
    try {
        final TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA && tm.getPhoneType()!=TelephonyManager.PHONE_TYPE_NONE) {
            String networkCountry = tm.getNetworkCountryIso();
            if (networkCountry != null && networkCountry.length() == 2) {
                networkCountry = networkCountry.toUpperCase();

                if (EUCountry.contains(networkCountry)) {
                    Log.v(TAG, "is EU User (network)");
                    return true;
                }
            }
        }
    }
    catch (Exception e) { error = true; }

/* is eu time zone id */
    try {
        String tz = TimeZone.getDefault().getID().toLowerCase();
        if (tz.length() < 10) {
            error = true;
        } else if (tz.contains("euro")) {
            Log.v(TAG, "is EU User (time)");
            return true;
        }
    } catch (Exception e) {
        error = true;
    }


    if (error == true) {
        Log.v(TAG, "is EU User (err)");
        return true;
    }

    return false;
}
like image 68
Ruyo Avatar answered Oct 24 '22 08:10

Ruyo