Detailed changes
@@ -115,7 +115,6 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
@Override
protected void onCreate(final Bundle savedInstanceState) {
- new com.cheogram.android.CheogramLicenseChecker(this).checkLicense();
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@@ -8,13 +8,17 @@ import android.util.Log;
import com.google.android.vending.licensing.*;
+import eu.siacs.conversations.utils.BiConsumer;
+
import eu.siacs.conversations.R;
public class CheogramLicenseChecker implements LicenseCheckerCallback {
private final LicenseChecker mChecker;
+ private final BiConsumer mCallback;
- public CheogramLicenseChecker(Context context) {
+ public CheogramLicenseChecker(Context context, BiConsumer<String, String> callback) {
mChecker = new LicenseChecker(context, new StrictPolicy(), context.getResources().getString(R.string.licensePublicKey));
+ mCallback = callback;
}
public void checkLicense() {
@@ -24,15 +28,18 @@ public class CheogramLicenseChecker implements LicenseCheckerCallback {
@Override
public void dontAllow(int reason) {
Log.d("CheogramLicenseChecker", "dontAllow: " + reason);
+ mCallback.accept(null, null);
}
@Override
public void applicationError(int errorCode) {
Log.d("CheogramLicenseChecker", "applicationError: " + errorCode);
+ mCallback.accept(null, null);
}
@Override
public void allow(int reason, ResponseData data, String signedData, String signature) {
Log.d("CheogramLicenseChecker", "" + reason + " / " + data + " / " + signedData + " / " + signature);
+ mCallback.accept(signedData, signature);
}
}
@@ -3,10 +3,17 @@ package com.cheogram.android;
import android.content.Context;
import android.util.Log;
+import eu.siacs.conversations.utils.BiConsumer;
+
public class CheogramLicenseChecker {
- public CheogramLicenseChecker(Context context) { }
+ private BiConsumer<String, String> mCallback;
+
+ public CheogramLicenseChecker(Context context, BiConsumer<String, String> callback) {
+ mCallback = callback;
+ }
public void checkLicense() {
Log.d("CheogramLicenseChecker", "skipping license checks in free build");
+ mCallback.accept(null, null);
}
}
@@ -1391,11 +1391,27 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
c.setAttribute("node", command.getAttribute("node"));
c.setAttribute("action", "execute");
View v = mPager;
- xmppConnectionService.sendIqPacket(getAccount(), packet, (a, iq) -> {
- v.post(() -> {
- session.updateWithResponse(iq);
+
+ if (command.getAttribute("node").equals("jabber:iq:register") && packet.getTo().asBareJid().equals(Jid.of("cheogram.com"))) {
+ new com.cheogram.android.CheogramLicenseChecker(v.getContext(), (signedData, signature) -> {
+ if (signedData != null && signature != null) {
+ c.addChild("license", "https://ns.cheogram.com/google-play").setContent(signedData);
+ c.addChild("licenseSignature", "https://ns.cheogram.com/google-play").setContent(signature);
+ }
+
+ xmppConnectionService.sendIqPacket(getAccount(), packet, (a, iq) -> {
+ v.post(() -> {
+ session.updateWithResponse(iq);
+ });
+ });
+ }).checkLicense();
+ } else {
+ xmppConnectionService.sendIqPacket(getAccount(), packet, (a, iq) -> {
+ v.post(() -> {
+ session.updateWithResponse(iq);
+ });
});
- });
+ }
sessions.add(session);
notifyDataSetChanged();
@@ -0,0 +1,6 @@
+package eu.siacs.conversations.utils;
+
+// Based on java.util.function.BiConsumer to avoid Android 24 dependency
+public interface BiConsumer<T,U> {
+ void accept(T t, U u);
+}