use installreferrer libray instead of broadcast listener
This commit is contained in:
parent
04595db099
commit
a6dd8e45fa
8 changed files with 86 additions and 86 deletions
|
@ -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'
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
Reference in a new issue