use installreferrer libray instead of broadcast listener
This commit is contained in:
parent
388c656bb9
commit
8e0c02f3cc
26
build.gradle
26
build.gradle
|
@ -22,6 +22,8 @@ configurations {
|
||||||
playstoreImplementation
|
playstoreImplementation
|
||||||
compatImplementation
|
compatImplementation
|
||||||
conversationsFreeCompatImplementation
|
conversationsFreeCompatImplementation
|
||||||
|
conversationsPlaystoreCompatImplementation
|
||||||
|
conversationsPlaystoreSystemImplementation
|
||||||
quicksyFreeCompatImplementation
|
quicksyFreeCompatImplementation
|
||||||
quicksyImplementation
|
quicksyImplementation
|
||||||
}
|
}
|
||||||
|
@ -36,6 +38,8 @@ dependencies {
|
||||||
exclude group: 'com.google.firebase', module: 'firebase-analytics'
|
exclude group: 'com.google.firebase', module: 'firebase-analytics'
|
||||||
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
|
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
|
||||||
}
|
}
|
||||||
|
conversationsPlaystoreCompatImplementation("com.android.installreferrer:installreferrer:1.1")
|
||||||
|
conversationsPlaystoreSystemImplementation("com.android.installreferrer:installreferrer:1.1")
|
||||||
implementation 'org.sufficientlysecure:openpgp-api:10.0'
|
implementation 'org.sufficientlysecure:openpgp-api:10.0'
|
||||||
implementation('com.theartofdev.edmodo:android-image-cropper:2.7.+') {
|
implementation('com.theartofdev.edmodo:android-image-cropper:2.7.+') {
|
||||||
exclude group: 'com.android.support', module: 'appcompat-v7'
|
exclude group: 'com.android.support', module: 'appcompat-v7'
|
||||||
|
@ -86,8 +90,8 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 353
|
versionCode 359
|
||||||
versionName "2.6.2"
|
versionName "2.6.3-alpha.6"
|
||||||
archivesBaseName += "-$versionName"
|
archivesBaseName += "-$versionName"
|
||||||
applicationId "eu.siacs.conversations"
|
applicationId "eu.siacs.conversations"
|
||||||
resValue "string", "applicationId", applicationId
|
resValue "string", "applicationId", applicationId
|
||||||
|
@ -147,12 +151,12 @@ android {
|
||||||
sourceSets {
|
sourceSets {
|
||||||
quicksyFreeCompat {
|
quicksyFreeCompat {
|
||||||
java {
|
java {
|
||||||
srcDirs 'src/freeCompat/java'
|
srcDir 'src/freeCompat/java'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
quicksyPlaystoreCompat {
|
quicksyPlaystoreCompat {
|
||||||
java {
|
java {
|
||||||
srcDirs 'src/playstoreCompat/java'
|
srcDir 'src/playstoreCompat/java'
|
||||||
}
|
}
|
||||||
res {
|
res {
|
||||||
srcDir 'src/playstoreCompat/res'
|
srcDir 'src/playstoreCompat/res'
|
||||||
|
@ -166,12 +170,19 @@ android {
|
||||||
}
|
}
|
||||||
conversationsFreeCompat {
|
conversationsFreeCompat {
|
||||||
java {
|
java {
|
||||||
srcDirs 'src/freeCompat/java'
|
srcDir 'src/freeCompat/java'
|
||||||
|
srcDir 'src/conversationsFree/java'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
conversationsFreeSystem {
|
||||||
|
java {
|
||||||
|
srcDir 'src/conversationsFree/java'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conversationsPlaystoreCompat {
|
conversationsPlaystoreCompat {
|
||||||
java {
|
java {
|
||||||
srcDirs 'src/playstoreCompat/java'
|
srcDir 'src/playstoreCompat/java'
|
||||||
|
srcDir 'src/conversationsPlaystore/java'
|
||||||
}
|
}
|
||||||
res {
|
res {
|
||||||
srcDir 'src/playstoreCompat/res'
|
srcDir 'src/playstoreCompat/res'
|
||||||
|
@ -179,6 +190,9 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conversationsPlaystoreSystem {
|
conversationsPlaystoreSystem {
|
||||||
|
java {
|
||||||
|
srcDir 'src/conversationsPlaystore/java'
|
||||||
|
}
|
||||||
res {
|
res {
|
||||||
srcDir 'src/conversationsPlaystore/res'
|
srcDir 'src/conversationsPlaystore/res'
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,14 +39,5 @@
|
||||||
<data android:scheme="file" />
|
<data android:scheme="file" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<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>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
package eu.siacs.conversations.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 eu.siacs.conversations.Config;
|
|
||||||
import eu.siacs.conversations.ui.StartConversationActivity;
|
|
||||||
import eu.siacs.conversations.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +1,12 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -20,7 +17,7 @@ import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.databinding.MagicCreateBinding;
|
import eu.siacs.conversations.databinding.MagicCreateBinding;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
import eu.siacs.conversations.utils.SignupUtils;
|
import eu.siacs.conversations.utils.InstallReferrerUtils;
|
||||||
import rocks.xmpp.addr.Jid;
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
|
@ -127,9 +124,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Log.d(Config.LOGTAG,"purge install referrer");
|
InstallReferrerUtils.markInstallReferrerExecuted(this);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
preferences.edit().remove(SignupUtils.INSTALL_REFERRER).apply();
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
@ -23,7 +18,7 @@ import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.databinding.ActivityWelcomeBinding;
|
import eu.siacs.conversations.databinding.ActivityWelcomeBinding;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.services.InstallReferrerService;
|
import eu.siacs.conversations.utils.InstallReferrerUtils;
|
||||||
import eu.siacs.conversations.utils.SignupUtils;
|
import eu.siacs.conversations.utils.SignupUtils;
|
||||||
import eu.siacs.conversations.utils.XmppUri;
|
import eu.siacs.conversations.utils.XmppUri;
|
||||||
import rocks.xmpp.addr.Jid;
|
import rocks.xmpp.addr.Jid;
|
||||||
|
@ -37,18 +32,13 @@ public class WelcomeActivity extends XmppActivity {
|
||||||
|
|
||||||
private XmppUri inviteUri;
|
private XmppUri inviteUri;
|
||||||
|
|
||||||
private BroadcastReceiver installReferrerBroadcastReceiver = new BroadcastReceiver() {
|
public void onInstallReferrerDiscovered(final String referrer) {
|
||||||
@Override
|
Log.d(Config.LOGTAG,"welcome activity: on install referrer discovered "+referrer);
|
||||||
public void onReceive(Context context, Intent data) {
|
if (referrer != null) {
|
||||||
final String invite = data.getStringExtra(StartConversationActivity.EXTRA_INVITE_URI);
|
final XmppUri xmppUri = new XmppUri(referrer);
|
||||||
if (invite == null) {
|
runOnUiThread(() -> processXmppUri(xmppUri));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG, "welcome activity received install referrer uri: " + invite);
|
|
||||||
final XmppUri xmppUri = new XmppUri(invite);
|
|
||||||
processXmppUri(xmppUri);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private boolean processXmppUri(final XmppUri xmppUri) {
|
private boolean processXmppUri(final XmppUri xmppUri) {
|
||||||
if (xmppUri.isValidJid()) {
|
if (xmppUri.isValidJid()) {
|
||||||
|
@ -90,14 +80,11 @@ public class WelcomeActivity extends XmppActivity {
|
||||||
if (this.mTheme != theme) {
|
if (this.mTheme != theme) {
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
final IntentFilter intentFilter = new IntentFilter();
|
new InstallReferrerUtils(this);
|
||||||
intentFilter.addAction(InstallReferrerService.INSTALL_REFERRER_BROADCAST_ACTION);
|
|
||||||
registerReceiver(installReferrerBroadcastReceiver, intentFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
unregisterReceiver(installReferrerBroadcastReceiver);
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +101,6 @@ public class WelcomeActivity extends XmppActivity {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState);
|
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;
|
|
||||||
}
|
|
||||||
ActivityWelcomeBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_welcome);
|
ActivityWelcomeBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_welcome);
|
||||||
setSupportActionBar((Toolbar) binding.toolbar);
|
setSupportActionBar((Toolbar) binding.toolbar);
|
||||||
configureActionBar(getSupportActionBar(), false);
|
configureActionBar(getSupportActionBar(), false);
|
||||||
|
|
|
@ -17,8 +17,6 @@ import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class SignupUtils {
|
public class SignupUtils {
|
||||||
|
|
||||||
public static final String INSTALL_REFERRER = "install_referrer";
|
|
||||||
|
|
||||||
public static boolean isSupportTokenRegistry() {
|
public static boolean isSupportTokenRegistry() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.siacs.conversations.utils;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.ui.MagicCreateActivity;
|
||||||
|
import eu.siacs.conversations.ui.WelcomeActivity;
|
||||||
|
|
||||||
|
public class InstallReferrerUtils {
|
||||||
|
|
||||||
|
public InstallReferrerUtils(WelcomeActivity welcomeActivity) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void markInstallReferrerExecuted(MagicCreateActivity magicCreateActivity) {
|
||||||
|
//stub
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package eu.siacs.conversations.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 eu.siacs.conversations.Config;
|
||||||
|
import eu.siacs.conversations.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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue