package io.particle.android.sdk;

import android.app.Application;

import com.crashlytics.android.Crashlytics;
import com.segment.analytics.Analytics;
import com.segment.analytics.android.integrations.firebase.FirebaseIntegration;
import com.segment.analytics.android.integrations.intercom.IntercomIntegration;
import io.fabric.sdk.android.Fabric;
import org.jetbrains.annotations.NotNull;
import android.util.Log;

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

import io.particle.mesh.common.QATool;
import io.particle.mesh.common.QAToolImpl;


public class ReleaseBuildAppInitializer {

    public static void onApplicationCreated(Application app) {
	boolean coveredByGDPR = GDPRKt.isUserCoveredByGDPR()

        if (!coveredByGDPR) {
             "MVP" level GDPR support: only enable crash reporting if the user is NOT in the EU.
            Fabric.with(app, new Crashlytics());
        }

        QATool.INSTANCE.setImplementation(new QAToolImpl() {

            @Override
            public void doReport(@NotNull Throwable exception) {
		if (coveredByGDPR) {
		    return
		}
                Log.e("ParticleApp", "Sending error to Crashlytics:", exception);
                Crashlytics.logException(exception);
            }

            @Override
            public void doLog(@NotNull String msg) {
		if (coveredByGDPR) {
		    return
		}
                Crashlytics.log(msg);
            }
        });

//        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()
//        );
    }

}

@@ -300,24 +300,25 @@
 ntegration;%0A
+%0A
 import io.fa
@@ -342,16 +342,17 @@
 Fabric;%0A
+%0A
 import o
@@ -385,16 +385,17 @@
 otNull;%0A
+%0A
 import a
@@ -648,17 +648,24 @@
  app) %7B%0A
-%09
+        
 boolean 
@@ -708,16 +708,17 @@
 ByGDPR()
+;
 %0A%0A      
@@ -753,17 +753,18 @@
         
- 
+//
 %22MVP%22 le
@@ -1044,26 +1044,40 @@
 xception) %7B%0A
-%09%09
+                
 if (coveredB
@@ -1081,39 +1081,67 @@
 edByGDPR) %7B%0A
-%09%09    return%0A%09%09
+                    return%0A                
 %7D%0A          
@@ -1355,18 +1355,32 @@
  msg) %7B%0A
-%09%09
+                
 if (cove
@@ -1396,23 +1396,51 @@
 ) %7B%0A
-%09%09    return%0A%09%09
+                    return%0A                
 %7D%0A  

Fix build problem that only showed up with release builds