Fix crashing during start.

This commit is contained in:
Mikunj 2019-09-25 14:04:25 +10:00
parent 4af63f780c
commit 0b49d7ae0d
3 changed files with 14 additions and 7 deletions

View File

@ -81,6 +81,7 @@ import org.webrtc.PeerConnectionFactory;
import org.webrtc.PeerConnectionFactory.InitializationOptions;
import org.webrtc.voiceengine.WebRtcAudioManager;
import org.webrtc.voiceengine.WebRtcAudioUtils;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
@ -160,7 +161,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
// Loki - Set up P2P API if needed
setUpP2PAPI();
setUpStorageAPI();
// Loki - Set up beta analytics
if (!BuildConfig.DEBUG) {
Fabric.with(this, new Crashlytics());
@ -183,6 +183,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
KeyCachingService.onAppForegrounded(this);
// Loki - Start long polling if needed
startLongPollingIfNeeded();
setUpStorageAPIIfNeeded();
}
@Override
@ -411,11 +412,13 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
// region Loki
public void setUpStorageAPI() {
public void setUpStorageAPIIfNeeded() {
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize();
LokiAPIDatabaseProtocol database = DatabaseFactory.getLokiAPIDatabase(this);
LokiStorageAPI.Companion.configure(userHexEncodedPublicKey, userPrivateKey, database);
if (userHexEncodedPublicKey != null && IdentityKeyUtil.hasIdentityKey(this)) {
byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize();
LokiAPIDatabaseProtocol database = DatabaseFactory.getLokiAPIDatabase(this);
LokiStorageAPI.Companion.configure(userHexEncodedPublicKey, userPrivateKey, database);
}
}
public void setUpP2PAPI() {

View File

@ -1078,7 +1078,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
TextSecurePreferences.setIsSecondaryDevice(context, true);
// Propagate the updates to the file server
LokiStorageAPI.shared.updateOurDeviceMappings();
LokiStorageAPI storageAPI = LokiStorageAPI.Companion.getShared();
if (storageAPI != null) { storageAPI.updateOurDeviceMappings(); }
// TODO: Trigger an event here?
@ -1104,10 +1105,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
if (envelope.isFriendRequest()) {
LokiStorageAPI storageAPI = LokiStorageAPI.Companion.getShared();
if (storageAPI == null) { return; }
// If we get a friend request then we need to check if the sender is a secondary device.
// If it is then we need to check if we have its primary device as our friend
// If so then we add them automatically as a friend
LokiStorageAPI.shared.getPrimaryDevice(content.getSender()).success(primaryDevicePubKey -> {
storageAPI.getPrimaryDevice(content.getSender()).success(primaryDevicePubKey -> {
// Make sure we have a primary device
if (primaryDevicePubKey == null) { return Unit.INSTANCE; }

View File

@ -36,6 +36,7 @@ class AccountDetailsActivity : BaseActionBarActivity() {
val application = ApplicationContext.getInstance(this)
application.setUpP2PAPI()
application.startLongPollingIfNeeded()
application.setUpStorageAPIIfNeeded()
startActivity(Intent(this, ConversationListActivity::class.java))
finish()
}