Skip to content

Commit

Permalink
Merge pull request #44 from particle-iot/jk/prevent_eu_analytics
Browse files Browse the repository at this point in the history
MVP GDPR
  • Loading branch information
CityVibes authored Jun 30, 2018
2 parents 958d379 + 810a49e commit f03eb68
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
Binary file removed .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dependencies {

releaseImplementation 'com.google.firebase:firebase-core:16.0.1'
releaseImplementation 'com.google.firebase:firebase-perf:16.0.0'
releaseImplementation 'com.google.firebase:firebase-crash:16.0.1'
releaseImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'

// Segment
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />


<application
android:name="io.particle.android.sdk.tinker.TinkerApplication"
android:allowBackup="true"
Expand All @@ -26,6 +25,10 @@
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />

<!-- Disable data collection by default for GDPR, re-enable at runtime -->
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
<meta-data android:name="firebase_crash_collection_enabled" android:value="false" />

<activity
android:name="io.particle.android.sdk.ui.SplashActivity"
android:screenOrientation="portrait"
Expand Down
45 changes: 45 additions & 0 deletions app/src/main/java/io/particle/android/sdk/utils/GDPR.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.particle.android.sdk.utils

import android.content.res.Resources


fun isUserCoveredByGDPR(): Boolean {
val locale = Resources.getSystem().configuration.locale
return gdprCountryCodes.contains(locale.country)
}


private val gdprCountryCodes: Set<String> = setOf(
"AT",
"BE",
"BG",
"CY",
"CZ",
"DE",
"DK",
"EE",
"EL",
"ES",
"FI",
"FR",
"HR",
"HU",
"IE",
"IT",
"LT",
"LU",
"LV",
"MT",
"NL",
"PL",
"PT",
"RO",
"SE",
"SI",
"SK",
"UK",
// plus 3 non-EU countries using GDPR
"IS",
"LI",
"NO"
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@
import com.segment.analytics.android.integrations.firebase.FirebaseIntegration;
import com.segment.analytics.android.integrations.intercom.IntercomIntegration;

import io.particle.android.sdk.utils.GDPRKt;

import com.google.firebase.crash.FirebaseCrash;

public class ReleaseBuildAppInitializer {

public static void onApplicationCreated(Application app) {
String fakeKey = "lolnope12345"; // FIXME: use real key
Analytics.setSingletonInstance(new Analytics.Builder(app, fakeKey)
.use(FirebaseIntegration.FACTORY)
.use(IntercomIntegration.FACTORY)
.build()
);
// String fakeKey = "lolnope12345"; // FIXME: use real key
// Disable, even in prod, until we have the key
// Analytics.setSingletonInstance(new Analytics.Builder(app, fakeKey)
// .use(FirebaseIntegration.FACTORY)
// .use(IntercomIntegration.FACTORY)
// .build()
// );

if (!GDPRKt.isUserCoveredByGDPR()) {
// "MVP" level GDPR support: only enable crash reporting if the user is NOT in the EU.
FirebaseCrash.setCrashCollectionEnabled(true);
}
}

}

0 comments on commit f03eb68

Please sign in to comment.