aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2020-01-24 19:55:58 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2020-01-24 19:55:58 +0100
commita6dd8e45fa2c1c3b0a3473361ddd9f21d604fab8 (patch)
treed7a2e0d5438c14ae8e451fa60d91267caa429351
parent04595db099f2c1107fc58420a1e8fa5ef207195d (diff)
use installreferrer libray instead of broadcast listener
-rw-r--r--build.gradle1
-rw-r--r--src/git/java/de/pixart/messenger/utils/InstallReferrerUtils.java13
-rw-r--r--src/main/java/de/pixart/messenger/services/InstallReferrerService.java39
-rw-r--r--src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java9
-rw-r--r--src/main/java/de/pixart/messenger/ui/WelcomeActivity.java37
-rw-r--r--src/main/java/de/pixart/messenger/utils/SignupUtils.java2
-rw-r--r--src/playstore/AndroidManifest.xml9
-rw-r--r--src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java62
8 files changed, 86 insertions, 86 deletions
diff --git a/build.gradle b/build.gradle
index 06e2d8275..8149b249b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,6 +44,7 @@ dependencies {
exclude group: 'com.google.firebase', module: 'firebase-analytics'
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
}
+ playstoreImplementation 'com.android.installreferrer:installreferrer:1.1.1'
implementation 'org.sufficientlysecure:openpgp-api:10.0'
implementation('com.theartofdev.edmodo:android-image-cropper:2.7.+') {
exclude group: 'com.android.support', module: 'appcompat-v7'
diff --git a/src/git/java/de/pixart/messenger/utils/InstallReferrerUtils.java b/src/git/java/de/pixart/messenger/utils/InstallReferrerUtils.java
new file mode 100644
index 000000000..cd0378828
--- /dev/null
+++ b/src/git/java/de/pixart/messenger/utils/InstallReferrerUtils.java
@@ -0,0 +1,13 @@
+package de.pixart.messenger.utils;
+
+import de.pixart.messenger.ui.MagicCreateActivity;
+import de.pixart.messenger.ui.WelcomeActivity;
+
+public class InstallReferrerUtils {
+
+ public InstallReferrerUtils(WelcomeActivity welcomeActivity) {
+ }
+
+ public static void markInstallReferrerExecuted(MagicCreateActivity magicCreateActivity) {
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/services/InstallReferrerService.java b/src/main/java/de/pixart/messenger/services/InstallReferrerService.java
deleted file mode 100644
index d6e267820..000000000
--- a/src/main/java/de/pixart/messenger/services/InstallReferrerService.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package de.pixart.messenger.services;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-import android.util.Log;
-
-import java.net.URLDecoder;
-
-import de.pixart.messenger.Config;
-import de.pixart.messenger.ui.StartConversationActivity;
-import de.pixart.messenger.utils.SignupUtils;
-
-public class InstallReferrerService extends BroadcastReceiver {
-
- public static final String INSTALL_REFERRER_BROADCAST_ACTION = "eu.siacs.conversations.install_referrer";
-
- @Override
- public void onReceive(final Context context, final Intent intent) {
- final String referrer = intent == null ? null : intent.getStringExtra("referrer");
- if (referrer == null) {
- Log.d(Config.LOGTAG, "received empty referrer");
- return;
- }
- try {
- final String decoded = URLDecoder.decode(referrer, "UTF-8");
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- preferences.edit().putString(SignupUtils.INSTALL_REFERRER, decoded).apply();
- Log.d(Config.LOGTAG, "stored referrer: " + decoded);
- final Intent broadcastIntent = new Intent(INSTALL_REFERRER_BROADCAST_ACTION);
- broadcastIntent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, decoded);
- context.sendBroadcast(broadcastIntent);
- } catch (final Exception e) {
- Log.d(Config.LOGTAG, "unable to process referrer", e);
- }
- }
-} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java
index 096b7527e..683db3929 100644
--- a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java
@@ -1,13 +1,10 @@
package de.pixart.messenger.ui;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
-import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@@ -27,7 +24,7 @@ import de.pixart.messenger.R;
import de.pixart.messenger.databinding.ActivityMagicCreateBinding;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.utils.CryptoHelper;
-import de.pixart.messenger.utils.SignupUtils;
+import de.pixart.messenger.utils.InstallReferrerUtils;
import rocks.xmpp.addr.Jid;
public class MagicCreateActivity extends XmppActivity implements TextWatcher, AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener {
@@ -216,9 +213,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher, Ad
@Override
public void onDestroy() {
- Log.d(Config.LOGTAG, "purge install referrer");
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
- preferences.edit().remove(SignupUtils.INSTALL_REFERRER).apply();
+ InstallReferrerUtils.markInstallReferrerExecuted(this);
super.onDestroy();
}
diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
index 95b269cf5..d396c8723 100644
--- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
@@ -1,17 +1,10 @@
package de.pixart.messenger.ui;
-import android.content.BroadcastReceiver;
-import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -22,8 +15,8 @@ import androidx.databinding.DataBindingUtil;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.databinding.WelcomeBinding;
-import de.pixart.messenger.services.InstallReferrerService;
import de.pixart.messenger.ui.util.IntroHelper;
+import de.pixart.messenger.utils.InstallReferrerUtils;
import de.pixart.messenger.utils.SignupUtils;
import de.pixart.messenger.utils.XmppUri;
import rocks.xmpp.addr.Jid;
@@ -39,18 +32,13 @@ public class WelcomeActivity extends XmppActivity {
private XmppUri inviteUri;
- private BroadcastReceiver installReferrerBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent data) {
- final String invite = data.getStringExtra(StartConversationActivity.EXTRA_INVITE_URI);
- if (invite == null) {
- return;
- }
- Log.d(Config.LOGTAG, "welcome activity received install referrer uri: " + invite);
- final XmppUri xmppUri = new XmppUri(invite);
- processXmppUri(xmppUri);
+ public void onInstallReferrerDiscovered(final String referrer) {
+ Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer);
+ if (referrer != null) {
+ final XmppUri xmppUri = new XmppUri(referrer);
+ runOnUiThread(() -> processXmppUri(xmppUri));
}
- };
+ }
private boolean processXmppUri(final XmppUri xmppUri) {
if (xmppUri.isValidJid()) {
@@ -90,14 +78,11 @@ public class WelcomeActivity extends XmppActivity {
if (this.mTheme != theme) {
recreate();
}
- final IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(InstallReferrerService.INSTALL_REFERRER_BROADCAST_ACTION);
- registerReceiver(installReferrerBroadcastReceiver, intentFilter);
+ new InstallReferrerUtils(this);
}
@Override
public void onStop() {
- unregisterReceiver(installReferrerBroadcastReceiver);
super.onStop();
}
@@ -114,12 +99,6 @@ public class WelcomeActivity extends XmppActivity {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onCreate(savedInstanceState);
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
- final String referrer = preferences.getString(SignupUtils.INSTALL_REFERRER, null);
- final XmppUri referrerUri = referrer == null ? null : new XmppUri(referrer);
- if (referrerUri != null && processXmppUri(referrerUri)) {
- return;
- }
WelcomeBinding binding = DataBindingUtil.setContentView(this, R.layout.welcome);
setSupportActionBar(findViewById(R.id.toolbar));
final ActionBar ab = getSupportActionBar();
diff --git a/src/main/java/de/pixart/messenger/utils/SignupUtils.java b/src/main/java/de/pixart/messenger/utils/SignupUtils.java
index a97c1b85b..52534b89d 100644
--- a/src/main/java/de/pixart/messenger/utils/SignupUtils.java
+++ b/src/main/java/de/pixart/messenger/utils/SignupUtils.java
@@ -16,8 +16,6 @@ import rocks.xmpp.addr.Jid;
public class SignupUtils {
- public static final String INSTALL_REFERRER = "install_referrer";
-
public static boolean isSupportTokenRegistry() {
return true;
}
diff --git a/src/playstore/AndroidManifest.xml b/src/playstore/AndroidManifest.xml
index 767fb4581..a54f8bee1 100644
--- a/src/playstore/AndroidManifest.xml
+++ b/src/playstore/AndroidManifest.xml
@@ -28,14 +28,5 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
-
- <receiver
- android:name=".services.InstallReferrerService"
- android:enabled="true"
- android:exported="true">
- <intent-filter>
- <action android:name="com.android.vending.INSTALL_REFERRER" />
- </intent-filter>
- </receiver>
</application>
</manifest>
diff --git a/src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java b/src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java
new file mode 100644
index 000000000..05824b9b2
--- /dev/null
+++ b/src/playstore/java/de/pixart/messenger/utils/InstallReferrerUtils.java
@@ -0,0 +1,62 @@
+package de.pixart.messenger.utils;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.RemoteException;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+import com.android.installreferrer.api.InstallReferrerClient;
+import com.android.installreferrer.api.InstallReferrerStateListener;
+import com.android.installreferrer.api.ReferrerDetails;
+
+import de.pixart.messenger.Config;
+import de.pixart.messenger.ui.WelcomeActivity;
+
+public class InstallReferrerUtils implements InstallReferrerStateListener {
+
+ private static final String PROCESSED_INSTALL_REFERRER = "processed_install_referrer";
+
+
+ private final WelcomeActivity welcomeActivity;
+ private final InstallReferrerClient installReferrerClient;
+
+
+ public InstallReferrerUtils(WelcomeActivity welcomeActivity) {
+ this.welcomeActivity = welcomeActivity;
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(welcomeActivity);
+ if (preferences.getBoolean(PROCESSED_INSTALL_REFERRER, false)) {
+ Log.d(Config.LOGTAG, "install referrer already processed");
+ this.installReferrerClient = null;
+ return;
+ }
+ this.installReferrerClient = InstallReferrerClient.newBuilder(welcomeActivity).build();
+ this.installReferrerClient.startConnection(this);
+ }
+
+ public static void markInstallReferrerExecuted(final Activity context) {
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ preferences.edit().putBoolean(PROCESSED_INSTALL_REFERRER, true).apply();
+ }
+
+ @Override
+ public void onInstallReferrerSetupFinished(int responseCode) {
+ switch (responseCode) {
+ case InstallReferrerClient.InstallReferrerResponse.OK:
+ try {
+ final ReferrerDetails referrerDetails = installReferrerClient.getInstallReferrer();
+ final String referrer = referrerDetails.getInstallReferrer();
+ welcomeActivity.onInstallReferrerDiscovered(referrer);
+ } catch (RemoteException e) {
+ Log.d(Config.LOGTAG, "unable to get install referrer", e);
+ }
+ break;
+ default:
+ Log.d(Config.LOGTAG, "unable to setup install referrer client. code=" + responseCode);
+ }
+ }
+
+ @Override
+ public void onInstallReferrerServiceDisconnected() {
+ }
+} \ No newline at end of file