finish migration to room: remove requery

Resolves #2244

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-07-26 21:16:38 +02:00
parent 125d6770b4
commit 66b2d44739
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
10 changed files with 29 additions and 267 deletions

View file

@ -246,10 +246,7 @@ dependencies {
compileOnly 'javax.annotation:javax.annotation-api:1.3.2' compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
// Android only // Android only
implementation 'org.greenrobot:eventbus:3.3.1' implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'io.requery:requery:1.6.1'
implementation 'io.requery:requery-android:1.6.1'
implementation 'net.zetetic:android-database-sqlcipher:4.5.1' implementation 'net.zetetic:android-database-sqlcipher:4.5.1'
kapt 'io.requery:requery-processor:1.6.1'
implementation "androidx.room:room-runtime:${roomVersion}" implementation "androidx.room:room-runtime:${roomVersion}"
implementation "androidx.room:room-rxjava2:${roomVersion}" implementation "androidx.room:room-rxjava2:${roomVersion}"

View file

@ -63,9 +63,6 @@ import io.reactivex.SingleObserver
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import io.requery.Persistable
import io.requery.android.sqlcipher.SqlCipherDatabaseSource
import io.requery.reactivex.ReactiveEntityStore
import org.parceler.Parcels import org.parceler.Parcels
import javax.inject.Inject import javax.inject.Inject
@ -73,12 +70,6 @@ import javax.inject.Inject
class MainActivity : BaseActivity(), ActionBarProvider { class MainActivity : BaseActivity(), ActionBarProvider {
lateinit var binding: ActivityMainBinding lateinit var binding: ActivityMainBinding
@Inject
lateinit var dataStore: ReactiveEntityStore<Persistable>
@Inject
lateinit var sqlCipherDatabaseSource: SqlCipherDatabaseSource
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -103,46 +94,34 @@ class MainActivity : BaseActivity(), ActionBarProvider {
router = Conductor.attachRouter(this, binding.controllerContainer, savedInstanceState) router = Conductor.attachRouter(this, binding.controllerContainer, savedInstanceState)
var hasDb = true
try {
sqlCipherDatabaseSource.writableDatabase
} catch (exception: Exception) {
hasDb = false
}
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
onNewIntent(intent) onNewIntent(intent)
} else if (!router!!.hasRootController()) { } else if (!router!!.hasRootController()) {
if (hasDb) { if (!appPreferences.isDbRoomMigrated) {
if (!appPreferences.isDbRoomMigrated) { appPreferences.isDbRoomMigrated = true
appPreferences.isDbRoomMigrated = true }
userManager.users.subscribe(object : SingleObserver<List<User>> {
override fun onSubscribe(d: Disposable) {
// unused atm
} }
userManager.users.subscribe(object : SingleObserver<List<User>> { override fun onSuccess(users: List<User>) {
override fun onSubscribe(d: Disposable) { if (users.isNotEmpty()) {
// unused atm runOnUiThread {
} setDefaultRootController()
}
override fun onSuccess(users: List<User>) { } else {
if (users.isNotEmpty()) { runOnUiThread {
runOnUiThread { launchLoginScreen()
setDefaultRootController()
}
} else {
runOnUiThread {
launchLoginScreen()
}
} }
} }
}
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
Log.e(TAG, "Error loading existing users", e) Log.e(TAG, "Error loading existing users", e)
} }
}) })
} else {
launchLoginScreen()
}
} }
} }

View file

@ -50,7 +50,6 @@ import com.facebook.cache.disk.DiskCacheConfig
import com.facebook.drawee.backends.pipeline.Fresco import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.imagepipeline.core.ImagePipelineConfig import com.facebook.imagepipeline.core.ImagePipelineConfig
import com.nextcloud.talk.BuildConfig import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.components.filebrowser.webdav.DavUtils import com.nextcloud.talk.components.filebrowser.webdav.DavUtils
import com.nextcloud.talk.dagger.modules.BusModule import com.nextcloud.talk.dagger.modules.BusModule
import com.nextcloud.talk.dagger.modules.ContextModule import com.nextcloud.talk.dagger.modules.ContextModule
@ -62,7 +61,6 @@ import com.nextcloud.talk.dagger.modules.ViewModelModule
import com.nextcloud.talk.jobs.AccountRemovalWorker import com.nextcloud.talk.jobs.AccountRemovalWorker
import com.nextcloud.talk.jobs.CapabilitiesWorker import com.nextcloud.talk.jobs.CapabilitiesWorker
import com.nextcloud.talk.jobs.SignalingSettingsWorker import com.nextcloud.talk.jobs.SignalingSettingsWorker
import com.nextcloud.talk.models.database.Models
import com.nextcloud.talk.utils.ClosedInterfaceImpl import com.nextcloud.talk.utils.ClosedInterfaceImpl
import com.nextcloud.talk.utils.DeviceUtils import com.nextcloud.talk.utils.DeviceUtils
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
@ -76,17 +74,14 @@ import com.vanniktech.emoji.EmojiManager
import com.vanniktech.emoji.google.GoogleEmojiProvider import com.vanniktech.emoji.google.GoogleEmojiProvider
import de.cotech.hw.SecurityKeyManager import de.cotech.hw.SecurityKeyManager
import de.cotech.hw.SecurityKeyManagerConfig import de.cotech.hw.SecurityKeyManagerConfig
import io.requery.android.sqlcipher.SqlCipherDatabaseSource
import net.sqlcipher.database.SQLiteDatabase import net.sqlcipher.database.SQLiteDatabase
import net.sqlcipher.database.SQLiteDatabaseHook import net.sqlcipher.database.SQLiteDatabaseHook
import net.sqlcipher.database.SQLiteOpenHelper
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.conscrypt.Conscrypt import org.conscrypt.Conscrypt
import org.webrtc.PeerConnectionFactory import org.webrtc.PeerConnectionFactory
import org.webrtc.voiceengine.WebRtcAudioManager import org.webrtc.voiceengine.WebRtcAudioManager
import org.webrtc.voiceengine.WebRtcAudioUtils import org.webrtc.voiceengine.WebRtcAudioUtils
import java.security.Security import java.security.Security
import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -172,8 +167,6 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
componentApplication.inject(this) componentApplication.inject(this)
checkAndUpgradeDbCypher()
Coil.setImageLoader(buildDefaultImageLoader()) Coil.setImageLoader(buildDefaultImageLoader())
setAppTheme(appPreferences.theme) setAppTheme(appPreferences.theme)
super.onCreate() super.onCreate()
@ -262,47 +255,6 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
.build() .build()
} }
private fun checkAndUpgradeDbCypher() {
if (appPreferences.isDbCypherToUpgrade) {
val database = object : SqlCipherDatabaseSource(
this,
Models.DEFAULT,
this
.resources
.getString(R.string.nc_app_product_name)
.lowercase(Locale.getDefault())
.replace(" ", "_")
.trim { it <= ' ' } +
".sqlite",
this.getString(R.string.nc_talk_database_encryption_key),
DatabaseModule.DB_VERSION
) {
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
checkAndUpdateCipherMigrationStatus(newVersion, appPreferences)
super.onUpgrade(db, oldVersion, newVersion)
}
}
try {
val field = SQLiteOpenHelper::class.java.getDeclaredField("mHook")
field.isAccessible = true
field.set(database, hook)
} catch (e: NoSuchFieldException) {
Log.e("SqlCipherDatabaseSource", "Error accessing mHook field")
} catch (e: IllegalAccessException) {
Log.e("SqlCipherDatabaseSource", "Error setting mHook field")
}
checkAndUpdateCipherMigrationStatus(database.writableDatabase.version, appPreferences)
}
}
private fun checkAndUpdateCipherMigrationStatus(version: Int, appPreferences: AppPreferences) {
if (version >= CIPHER_V4_MIGRATION && appPreferences.isDbCypherToUpgrade) {
appPreferences.isDbCypherToUpgrade = false
}
}
companion object { companion object {
private val TAG = NextcloudTalkApplication::class.java.simpleName private val TAG = NextcloudTalkApplication::class.java.simpleName
const val FIFTY_PERCENT = 0.5 const val FIFTY_PERCENT = 0.5

View file

@ -67,8 +67,6 @@ import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder
import com.nextcloud.talk.utils.ssl.MagicTrustManager import com.nextcloud.talk.utils.ssl.MagicTrustManager
import de.cotech.hw.fido.WebViewFidoBridge import de.cotech.hw.fido.WebViewFidoBridge
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.requery.Persistable
import io.requery.reactivex.ReactiveEntityStore
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import java.lang.reflect.Field import java.lang.reflect.Field
import java.net.CookieManager import java.net.CookieManager
@ -89,9 +87,6 @@ class WebViewLoginController(args: Bundle? = null) : NewBaseController(
@Inject @Inject
lateinit var userManager: UserManager lateinit var userManager: UserManager
@Inject
lateinit var dataStore: ReactiveEntityStore<Persistable>
@Inject @Inject
lateinit var magicTrustManager: MagicTrustManager lateinit var magicTrustManager: MagicTrustManager

View file

@ -22,66 +22,20 @@
package com.nextcloud.talk.dagger.modules; package com.nextcloud.talk.dagger.modules;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import com.nextcloud.talk.R;
import com.nextcloud.talk.data.source.local.TalkDatabase; import com.nextcloud.talk.data.source.local.TalkDatabase;
import com.nextcloud.talk.models.database.Models;
import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.preferences.AppPreferences;
import dagger.Module;
import dagger.Provides;
import io.requery.Persistable;
import io.requery.android.sqlcipher.SqlCipherDatabaseSource;
import io.requery.reactivex.ReactiveEntityStore;
import io.requery.reactivex.ReactiveSupport;
import io.requery.sql.Configuration;
import io.requery.sql.EntityDataStore;
import net.orange_box.storebox.StoreBox; import net.orange_box.storebox.StoreBox;
import net.sqlcipher.database.SQLiteDatabase;
import javax.inject.Singleton; import javax.inject.Singleton;
import androidx.annotation.NonNull;
import dagger.Module;
import dagger.Provides;
@Module @Module
public class DatabaseModule { public class DatabaseModule {
public static final int DB_VERSION = 7;
@Provides
@Singleton
public SqlCipherDatabaseSource provideSqlCipherDatabaseSource(
@NonNull final Context context,
final AppPreferences appPreferences) {
int version = DB_VERSION;
if (appPreferences.getIsDbRoomMigrated()) {
version++;
}
return new SqlCipherDatabaseSource(
context,
Models.DEFAULT,
context
.getResources()
.getString(R.string.nc_app_product_name)
.toLowerCase()
.replace(" ", "_")
.trim()
+ ".sqlite",
context.getString(R.string.nc_talk_database_encryption_key),
version) {
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion < 7) {
super.onDowngrade(db, oldVersion, newVersion);
}
}
};
}
@Provides
@Singleton
public ReactiveEntityStore<Persistable> provideDataStore(
@NonNull final SqlCipherDatabaseSource sqlCipherDatabaseSource) {
final Configuration configuration = sqlCipherDatabaseSource.getConfiguration();
return ReactiveSupport.toReactiveStore(new EntityDataStore<>(configuration));
}
@Provides @Provides
@Singleton @Singleton
public AppPreferences providePreferences(@NonNull final Context poContext) { public AppPreferences providePreferences(@NonNull final Context poContext) {

View file

@ -1,44 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.database;
import android.os.Parcelable;
import io.requery.Entity;
import io.requery.Key;
import io.requery.Persistable;
import java.io.Serializable;
/**
* Legacy arbitrary storage entity, please migrate to {@link com.nextcloud.talk.data.storage.model.ArbitraryStorage}.
*/
@Deprecated
@Entity
public interface ArbitraryStorage extends Parcelable, Persistable, Serializable {
@Key
long getAccountIdentifier();
String getKey();
String getObject();
String getValue();
}

View file

@ -1,66 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.database;
import android.os.Parcelable;
import java.io.Serializable;
import io.requery.Entity;
import io.requery.Generated;
import io.requery.Key;
import io.requery.Persistable;
/**
* Legacy user entity, please migrate to {@link com.nextcloud.talk.data.user.model.User}.
*/
@Deprecated
@Entity
public interface User extends Parcelable, Persistable, Serializable {
String TAG = "UserEntity";
@Key
@Generated
long getId();
String getUserId();
String getUsername();
String getBaseUrl();
String getToken();
String getDisplayName();
String getPushConfigurationState();
String getCapabilities();
String getClientCertificate();
String getExternalSignalingServer();
boolean getCurrent();
boolean getScheduledForDeletion();
}

View file

@ -32,7 +32,6 @@ import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User; import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew; import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View file

@ -81,7 +81,6 @@ import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User; import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.events.UserMentionClickEvent; import com.nextcloud.talk.events.UserMentionClickEvent;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.utils.text.Spans; import com.nextcloud.talk.utils.text.Spans;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@ -93,7 +92,6 @@ import java.text.DateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;

View file

@ -19,18 +19,16 @@
*/ */
package com.nextcloud.talk.utils.database.arbitrarystorage; package com.nextcloud.talk.utils.database.arbitrarystorage;
import autodagger.AutoInjector;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager; import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager;
import com.nextcloud.talk.dagger.modules.DatabaseModule; import com.nextcloud.talk.dagger.modules.DatabaseModule;
import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository; import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository;
import javax.inject.Inject;
import autodagger.AutoInjector;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import io.requery.Persistable;
import io.requery.reactivex.ReactiveEntityStore;
import javax.inject.Inject;
@Module(includes = DatabaseModule.class) @Module(includes = DatabaseModule.class)
@AutoInjector(NextcloudTalkApplication.class) @AutoInjector(NextcloudTalkApplication.class)