Check google play license and send when registering with cheogram.com

Stephen Paul Weber created

Change summary

src/cheogram/java/eu/siacs/conversations/ui/WelcomeActivity.java                 |  1 
src/conversationsPlaystore/java/com/cheogram/android/CheogramLicenseChecker.java |  9 
src/free/java/com/cheogram/android/CheogramLicenseChecker.java                   |  9 
src/main/java/eu/siacs/conversations/entities/Conversation.java                  | 24 
src/main/java/eu/siacs/conversations/utils/BiConsumer.java                       |  6 
5 files changed, 42 insertions(+), 7 deletions(-)

Detailed changes

src/cheogram/java/eu/siacs/conversations/ui/WelcomeActivity.java 🔗

@@ -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);
         }

src/conversationsPlaystore/java/com/cheogram/android/CheogramLicenseChecker.java 🔗

@@ -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);
 	}
 }

src/free/java/com/cheogram/android/CheogramLicenseChecker.java 🔗

@@ -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);
 	}
 }

src/main/java/eu/siacs/conversations/entities/Conversation.java 🔗

@@ -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();