mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-29 08:42:15 +00:00
Linked storage api and database.
This commit is contained in:
parent
ff65d4e342
commit
901d627d32
@ -83,12 +83,7 @@ import org.webrtc.voiceengine.WebRtcAudioUtils;
|
|||||||
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
|
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiGroupChat;
|
import org.whispersystems.signalservice.loki.api.*;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI;
|
|
||||||
import org.whispersystems.signalservice.loki.api.LokiLongPoller;
|
|
||||||
import org.whispersystems.signalservice.loki.api.LokiP2PAPI;
|
|
||||||
import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate;
|
|
||||||
import org.whispersystems.signalservice.loki.api.LokiRSSFeed;
|
|
||||||
import org.whispersystems.signalservice.loki.utilities.Analytics;
|
import org.whispersystems.signalservice.loki.utilities.Analytics;
|
||||||
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
@ -164,6 +159,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
||||||
// Loki - Set up P2P API if needed
|
// Loki - Set up P2P API if needed
|
||||||
setUpP2PAPI();
|
setUpP2PAPI();
|
||||||
|
setUpStorageAPI();
|
||||||
// Loki - Set up beta analytics
|
// Loki - Set up beta analytics
|
||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
Fabric.with(this, new Crashlytics());
|
Fabric.with(this, new Crashlytics());
|
||||||
@ -414,6 +410,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// region Loki
|
// region Loki
|
||||||
|
public void setUpStorageAPI() {
|
||||||
|
LokiStorageAPI.Companion.configure(DatabaseFactory.getLokiMultiDeviceDatabase(this));
|
||||||
|
}
|
||||||
|
|
||||||
public void setUpP2PAPI() {
|
public void setUpP2PAPI() {
|
||||||
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
|
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||||
if (hexEncodedPublicKey == null) { return; }
|
if (hexEncodedPublicKey == null) { return; }
|
||||||
|
@ -31,12 +31,7 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|||||||
import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper;
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper;
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
import org.thoughtcrime.securesms.loki.*;
|
||||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
|
||||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
|
||||||
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
|
||||||
import org.thoughtcrime.securesms.loki.LokiThreadDatabase;
|
|
||||||
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
|
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
|
||||||
public class DatabaseFactory {
|
public class DatabaseFactory {
|
||||||
@ -68,6 +63,7 @@ public class DatabaseFactory {
|
|||||||
|
|
||||||
// Loki
|
// Loki
|
||||||
private final LokiAPIDatabase lokiAPIDatabase;
|
private final LokiAPIDatabase lokiAPIDatabase;
|
||||||
|
private final LokiMultiDeviceDatabase lokiMultiDeviceDatabase;
|
||||||
private final LokiPreKeyRecordDatabase lokiContactPreKeyDatabase;
|
private final LokiPreKeyRecordDatabase lokiContactPreKeyDatabase;
|
||||||
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
|
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
|
||||||
private final LokiMessageDatabase lokiMessageDatabase;
|
private final LokiMessageDatabase lokiMessageDatabase;
|
||||||
@ -168,6 +164,10 @@ public class DatabaseFactory {
|
|||||||
return getInstance(context).lokiAPIDatabase;
|
return getInstance(context).lokiAPIDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LokiMultiDeviceDatabase getLokiMultiDeviceDatabase(Context context) {
|
||||||
|
return getInstance(context).lokiMultiDeviceDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
public static LokiPreKeyRecordDatabase getLokiPreKeyRecordDatabase(Context context) {
|
public static LokiPreKeyRecordDatabase getLokiPreKeyRecordDatabase(Context context) {
|
||||||
return getInstance(context).lokiContactPreKeyDatabase;
|
return getInstance(context).lokiContactPreKeyDatabase;
|
||||||
}
|
}
|
||||||
@ -221,6 +221,7 @@ public class DatabaseFactory {
|
|||||||
this.jobDatabase = new JobDatabase(context, databaseHelper);
|
this.jobDatabase = new JobDatabase(context, databaseHelper);
|
||||||
this.stickerDatabase = new StickerDatabase(context, databaseHelper, attachmentSecret);
|
this.stickerDatabase = new StickerDatabase(context, databaseHelper, attachmentSecret);
|
||||||
this.lokiAPIDatabase = new LokiAPIDatabase(context, databaseHelper);
|
this.lokiAPIDatabase = new LokiAPIDatabase(context, databaseHelper);
|
||||||
|
this.lokiMultiDeviceDatabase = new LokiMultiDeviceDatabase(context, databaseHelper);
|
||||||
this.lokiContactPreKeyDatabase = new LokiPreKeyRecordDatabase(context, databaseHelper);
|
this.lokiContactPreKeyDatabase = new LokiPreKeyRecordDatabase(context, databaseHelper);
|
||||||
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
|
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
|
||||||
this.lokiMessageDatabase = new LokiMessageDatabase(context, databaseHelper);
|
this.lokiMessageDatabase = new LokiMessageDatabase(context, databaseHelper);
|
||||||
|
@ -7,9 +7,10 @@ import org.thoughtcrime.securesms.database.Database
|
|||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
import org.thoughtcrime.securesms.util.Base64
|
import org.thoughtcrime.securesms.util.Base64
|
||||||
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
||||||
|
import org.whispersystems.signalservice.loki.api.LokiStorageAPIDatabaseProtocol
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiStorageAPIDatabaseProtocol {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Authorisation
|
// Authorisation
|
||||||
@ -27,7 +28,7 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
|||||||
");"
|
");"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertOrUpdatePairingAuthorisation(authorisation: LokiPairingAuthorisation) {
|
override fun insertOrUpdatePairingAuthorisation(authorisation: LokiPairingAuthorisation) {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(primaryDevice, authorisation.primaryDevicePubKey)
|
values.put(primaryDevice, authorisation.primaryDevicePubKey)
|
||||||
@ -37,6 +38,11 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
|||||||
database.insertOrUpdate(authorisation_table, values, "$primaryDevice = ? AND $secondaryDevice = ?", arrayOf(authorisation.primaryDevicePubKey, authorisation.secondaryDevicePubKey))
|
database.insertOrUpdate(authorisation_table, values, "$primaryDevice = ? AND $secondaryDevice = ?", arrayOf(authorisation.primaryDevicePubKey, authorisation.secondaryDevicePubKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun removePairingAuthorisations(pubKey: String) {
|
||||||
|
val database = databaseHelper.readableDatabase
|
||||||
|
database.delete(authorisation_table, "$primaryDevice = ? OR $secondaryDevice = ?", arrayOf(pubKey, pubKey))
|
||||||
|
}
|
||||||
|
|
||||||
fun getAuthorisationForSecondaryDevice(pubKey: String): LokiPairingAuthorisation? {
|
fun getAuthorisationForSecondaryDevice(pubKey: String): LokiPairingAuthorisation? {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
return database.get(authorisation_table, "$secondaryDevice = ?", arrayOf(pubKey)) { cursor ->
|
return database.get(authorisation_table, "$secondaryDevice = ?", arrayOf(pubKey)) { cursor ->
|
||||||
@ -48,7 +54,7 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSecondaryDevices(primaryDevicePubKey: String): List<String> {
|
override fun getSecondaryDevices(primaryDevicePubKey: String): List<String> {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
|
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
@ -68,7 +74,7 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPrimaryDevice(secondaryDevicePubKey: String): String? {
|
override fun getPrimaryDevice(secondaryDevicePubKey: String): String? {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
return database.get(authorisation_table, "$secondaryDevice = ?", arrayOf(secondaryDevicePubKey)) { cursor ->
|
return database.get(authorisation_table, "$secondaryDevice = ?", arrayOf(secondaryDevicePubKey)) { cursor ->
|
||||||
cursor.getString(primaryDevice)
|
cursor.getString(primaryDevice)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user