validate install referrer beforing accepting it as xmpp uri
This commit is contained in:
parent
7bcb29c482
commit
fe68aff23c
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.security.KeyChain;
|
||||
import android.security.KeyChainAliasCallback;
|
||||
|
@ -46,35 +47,37 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
|
|||
activity.overridePendingTransition(0, 0);
|
||||
}
|
||||
|
||||
public void onInstallReferrerDiscovered(final String referrer) {
|
||||
public void onInstallReferrerDiscovered(final Uri referrer) {
|
||||
Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer);
|
||||
if (referrer != null) {
|
||||
if ("xmpp".equalsIgnoreCase(referrer.getScheme())) {
|
||||
final XmppUri xmppUri = new XmppUri(referrer);
|
||||
runOnUiThread(() -> processXmppUri(xmppUri));
|
||||
} else {
|
||||
Log.i(Config.LOGTAG, "install referrer was not an XMPP uri");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean processXmppUri(final XmppUri xmppUri) {
|
||||
if (xmppUri.isValidJid()) {
|
||||
final String preauth = xmppUri.getParameter("preauth");
|
||||
final Jid jid = xmppUri.getJid();
|
||||
final Intent intent;
|
||||
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
|
||||
intent = SignupUtils.getTokenRegistrationIntent(this, jid, preauth);
|
||||
} else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) {
|
||||
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preauth);
|
||||
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
|
||||
} else {
|
||||
intent = null;
|
||||
}
|
||||
if (intent != null) {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
this.inviteUri = xmppUri;
|
||||
private void processXmppUri(final XmppUri xmppUri) {
|
||||
if (!xmppUri.isValidJid()) {
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
final String preAuth = xmppUri.getParameter("preauth");
|
||||
final Jid jid = xmppUri.getJid();
|
||||
final Intent intent;
|
||||
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
|
||||
intent = SignupUtils.getTokenRegistrationIntent(this, jid, preAuth);
|
||||
} else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) {
|
||||
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth);
|
||||
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
|
||||
} else {
|
||||
intent = null;
|
||||
}
|
||||
if (intent != null) {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
this.inviteUri = xmppUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.utils;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
@ -9,6 +10,7 @@ import android.util.Log;
|
|||
import com.android.installreferrer.api.InstallReferrerClient;
|
||||
import com.android.installreferrer.api.InstallReferrerStateListener;
|
||||
import com.android.installreferrer.api.ReferrerDetails;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.ui.WelcomeActivity;
|
||||
|
@ -49,8 +51,11 @@ public class InstallReferrerUtils implements InstallReferrerStateListener {
|
|||
try {
|
||||
final ReferrerDetails referrerDetails = installReferrerClient.getInstallReferrer();
|
||||
final String referrer = referrerDetails.getInstallReferrer();
|
||||
welcomeActivity.onInstallReferrerDiscovered(referrer);
|
||||
} catch (final RemoteException e) {
|
||||
if (Strings.isNullOrEmpty(referrer)) {
|
||||
return;
|
||||
}
|
||||
welcomeActivity.onInstallReferrerDiscovered(Uri.parse(referrer));
|
||||
} catch (final RemoteException | IllegalArgumentException e) {
|
||||
Log.d(Config.LOGTAG, "unable to get install referrer", e);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue