Added long polling

This commit is contained in:
Mikunj 2019-06-18 12:49:21 +10:00
parent fc4ea70621
commit 6928bfa2ae
2 changed files with 35 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.multidex.MultiDexApplication; import android.support.multidex.MultiDexApplication;
import com.google.android.gms.security.ProviderInstaller; import com.google.android.gms.security.ProviderInstaller;
@ -52,6 +53,7 @@ import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.logging.PersistentLogger; import org.thoughtcrime.securesms.logging.PersistentLogger;
import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger; import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger;
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
@ -70,6 +72,8 @@ import org.webrtc.PeerConnectionFactory.InitializationOptions;
import org.webrtc.voiceengine.WebRtcAudioManager; import org.webrtc.voiceengine.WebRtcAudioManager;
import org.webrtc.voiceengine.WebRtcAudioUtils; import org.webrtc.voiceengine.WebRtcAudioUtils;
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider; import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
import org.whispersystems.signalservice.loki.api.LokiAPI;
import org.whispersystems.signalservice.loki.api.LokiLongPoller;
import org.whispersystems.signalservice.loki.api.LokiP2PAPI; import org.whispersystems.signalservice.loki.api.LokiP2PAPI;
import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate; import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate;
@ -101,6 +105,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
private ObjectGraph objectGraph; private ObjectGraph objectGraph;
private PersistentLogger persistentLogger; private PersistentLogger persistentLogger;
private LokiLongPoller lokiLongPoller = null;
private volatile boolean isAppVisible; private volatile boolean isAppVisible;
public static ApplicationContext getInstance(Context context) { public static ApplicationContext getInstance(Context context) {
@ -149,6 +155,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
Log.i(TAG, "App is now visible."); Log.i(TAG, "App is now visible.");
executePendingContactSync(); executePendingContactSync();
KeyCachingService.onAppForegrounded(this); KeyCachingService.onAppForegrounded(this);
// Start message receiving if we have registered
startLokiLongPolling();
} }
@Override @Override
@ -156,6 +165,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
isAppVisible = false; isAppVisible = false;
Log.i(TAG, "App is no longer visible."); Log.i(TAG, "App is no longer visible.");
KeyCachingService.onAppBackgrounded(this); KeyCachingService.onAppBackgrounded(this);
if (lokiLongPoller != null) {
lokiLongPoller.stop();
}
} }
@Override @Override
@ -189,6 +202,24 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
return persistentLogger; return persistentLogger;
} }
public void startLokiLongPolling() {
initializeLokiLongPoller();
if (lokiLongPoller != null) {
lokiLongPoller.startIfNecessary();
}
}
private void initializeLokiLongPoller() {
if (lokiLongPoller != null) return;
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
if (hexEncodedPublicKey == null) return;
LokiAPIDatabase database = DatabaseFactory.getLokiAPIDatabase(this);
LokiAPI lokiAPI = new LokiAPI(hexEncodedPublicKey, database);
lokiLongPoller = new LokiLongPoller(hexEncodedPublicKey, lokiAPI);
}
private void initializeSecurityProvider() { private void initializeSecurityProvider() {
try { try {
Class.forName("org.signal.aesgcmprovider.AesGcmCipher"); Class.forName("org.signal.aesgcmprovider.AesGcmCipher");

View File

@ -7,6 +7,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import kotlinx.android.synthetic.main.activity_key_pair.* import kotlinx.android.synthetic.main.activity_key_pair.*
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.ConversationListActivity import org.thoughtcrime.securesms.ConversationListActivity
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
@ -96,6 +97,9 @@ class KeyPairActivity : BaseActionBarActivity() {
// TODO: Configure P2P API // TODO: Configure P2P API
// Loki - start the long polling
ApplicationContext.getInstance(this).startLokiLongPolling()
startActivity(Intent(this, ConversationListActivity::class.java)) startActivity(Intent(this, ConversationListActivity::class.java))
finish() finish()
} }