package com.growthbeat.link.handler;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import android.content.Context;
import android.content.Intent;

import com.growthbeat.link.GrowthLink;

public class DefaultInstallReferrerReceiveHandler implements InstallReferrerReceiveHandler {

	@Override
	public void onReceive(Context context, Intent intent) {

		String referrer = intent.getStringExtra("referrer");
		if (referrer != null) {
			String decoded = "";
			try {
				decoded = URLDecoder.decode(referrer, "utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			if (decoded.length() > 0) {
				GrowthLink.getInstance().setInstallReferrer(decoded);
			}
		}

	}

}

@@ -381,17 +381,31 @@
 %09String 
-r
+encodedInstallR
 eferrer 
@@ -447,21 +447,31 @@
 ;%0A%09%09
-if (r
+String installR
 eferrer 
 != n
@@ -470,63 +470,85 @@
 rer 
-!
 = null
-) %7B%0A%09%09%09String decoded = %22%22;%0A%09%09%09try %7B%0A%09%09%09%09decoded
+;%0A%0A%09%09if (encodedInstallReferrer != null) %7B%0A%09%09%09try %7B%0A%09%09%09%09installReferrer
  = U
@@ -564,17 +564,31 @@
 .decode(
-r
+encodedInstallR
 eferrer,
@@ -652,67 +652,118 @@
 %09%09%09%09
-e.printStackTrace();%0A%09%09%09%7D%0A%09%09%09if (decoded.length() %3E 0) %7B%0A%09%09
+GrowthLink.getInstance().getLogger().error(%22Failed to decode install referrer: %22 + e.getMessage());%0A%09%09%09%7D%0A%09%09%7D%0A%0A
 %09%09Gr
@@ -808,26 +808,25 @@
 rer(
-decoded);%0A%09%09%09%7D%0A%09%09%7D
+installReferrer);
 %0A%0A%09%7D

Set null instead of empty string when install referrer is blank