From 6f6bc74fb173f0faf89ec0cc73481d20ff718b85 Mon Sep 17 00:00:00 2001 From: S1210 Date: Wed, 31 May 2023 15:50:47 +0200 Subject: [PATCH] Encrypt databases --- app/build.gradle | 18 ++-- app/proguard-rules.pro | 4 + .../1.json | 0 .../2.json | 0 .../3.json | 0 .../4.json | 0 .../6.json | 0 .../7.json | 0 .../8.json | 0 .../9.json | 0 .../1.json | 0 .../dashboard/DashboardViewModel.kt | 2 +- .../dashboard/TreesToSyncHelper.kt | 2 +- .../TreeTracker/database/AppDatabase.kt | 88 ------------------- .../TreeTracker/database/app/AppDatabase.kt | 67 ++++++++++++++ .../database/{ => app}/Converters.kt | 2 +- .../database/{ => app}/Migrations.kt | 4 +- .../database/{ => app/dao}/TreeTrackerDAO.kt | 24 ++--- .../{ => app}/entity/DeviceConfigEntity.kt | 2 +- .../{ => app}/entity/LocationEntity.kt | 2 +- .../{ => app}/entity/OrganizationEntity.kt | 2 +- .../{ => app}/entity/SessionEntity.kt | 2 +- .../database/{ => app}/entity/TreeEntity.kt | 2 +- .../database/{ => app}/entity/UserEntity.kt | 2 +- .../legacy/entity/LocationDataEntity.kt | 2 +- .../legacy/entity/PlanterCheckInEntity.kt | 2 +- .../legacy/entity/PlanterInfoEntity.kt | 2 +- .../legacy/entity/TreeAttributeEntity.kt | 2 +- .../legacy/entity/TreeCaptureEntity.kt | 2 +- .../legacy/views/TreeMapMarkerDbView.kt | 2 +- .../legacy/views/TreeUploadDbView.kt | 2 +- .../TreeTracker/database/common/Encrypt.kt | 37 ++++++++ .../messages}/DatabaseConverters.kt | 8 +- .../messages}/MessageDatabase.kt | 29 ++---- .../messages/dao}/MessagesDAO.kt | 8 +- .../messages}/entities/MessageEntity.kt | 2 +- .../messages}/entities/QuestionEntity.kt | 2 +- .../messages}/entities/SurveyEntity.kt | 2 +- .../android/TreeTracker/di/RoomModule.kt | 51 +++++++++-- .../TreeTracker/models/DeviceConfigUpdater.kt | 6 +- .../models/DeviceConfigUploader.kt | 2 +- .../TreeTracker/models/PlanterUploader.kt | 2 +- .../TreeTracker/models/SessionTracker.kt | 6 +- .../TreeTracker/models/SessionUploader.kt | 2 +- .../TreeTracker/models/TreeUploader.kt | 6 +- .../models/location/LocationDataCapturer.kt | 8 +- .../models/messages/MessageUploader.kt | 4 +- .../models/messages/MessagesRepo.kt | 20 +++-- .../models/organization/OrgRepo.kt | 4 +- .../TreeTracker/models/user/UserRepo.kt | 8 +- .../usecases/CreateFakeTreesUseCase.kt | 8 +- .../usecases/CreateLegacyTreeUseCase.kt | 6 +- .../usecases/CreateTreeRequestUseCase.kt | 2 +- .../TreeTracker/usecases/CreateTreeUseCase.kt | 4 +- .../TreeTracker/usecases/SyncDataUseCase.kt | 2 +- .../usecases/UploadLocationDataUseCase.kt | 2 +- .../dashboard/DashboardViewModelTest.kt | 2 +- .../database/TreeTrackerDaoTest.kt | 2 + .../location/LocationDataCapturerTest.kt | 2 +- .../models/messages/MessagesRepoTest.kt | 4 +- .../TreeTracker/utils/FakeFileGenerator.kt | 13 ++- 61 files changed, 280 insertions(+), 211 deletions(-) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/1.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/2.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/3.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/4.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/6.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/7.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/8.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.database.AppDatabase => org.greenstand.android.TreeTracker.database.app.AppDatabase}/9.json (100%) rename app/schemas/{org.greenstand.android.TreeTracker.models.messages.database.MessageDatabase => org.greenstand.android.TreeTracker.database.messages.MessageDatabase}/1.json (100%) delete mode 100644 app/src/main/java/org/greenstand/android/TreeTracker/database/AppDatabase.kt create mode 100644 app/src/main/java/org/greenstand/android/TreeTracker/database/app/AppDatabase.kt rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/Converters.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/Migrations.kt (98%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app/dao}/TreeTrackerDAO.kt (92%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/entity/DeviceConfigEntity.kt (95%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/entity/LocationEntity.kt (95%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/entity/OrganizationEntity.kt (94%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/entity/SessionEntity.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/entity/TreeEntity.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/entity/UserEntity.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/entity/LocationDataEntity.kt (95%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/entity/PlanterCheckInEntity.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/entity/PlanterInfoEntity.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/entity/TreeAttributeEntity.kt (95%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/entity/TreeCaptureEntity.kt (97%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/views/TreeMapMarkerDbView.kt (91%) rename app/src/main/java/org/greenstand/android/TreeTracker/database/{ => app}/legacy/views/TreeUploadDbView.kt (97%) create mode 100644 app/src/main/java/org/greenstand/android/TreeTracker/database/common/Encrypt.kt rename app/src/main/java/org/greenstand/android/TreeTracker/{models/messages/database => database/messages}/DatabaseConverters.kt (94%) rename app/src/main/java/org/greenstand/android/TreeTracker/{models/messages/database => database/messages}/MessageDatabase.kt (50%) rename app/src/main/java/org/greenstand/android/TreeTracker/{models/messages/database => database/messages/dao}/MessagesDAO.kt (91%) rename app/src/main/java/org/greenstand/android/TreeTracker/{models/messages/database => database/messages}/entities/MessageEntity.kt (96%) rename app/src/main/java/org/greenstand/android/TreeTracker/{models/messages/database => database/messages}/entities/QuestionEntity.kt (94%) rename app/src/main/java/org/greenstand/android/TreeTracker/{models/messages/database => database/messages}/entities/SurveyEntity.kt (91%) diff --git a/app/build.gradle b/app/build.gradle index 8a71328c1..5ef1ddda3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,11 +44,11 @@ android { buildConfigField 'Boolean', 'BLUR_DETECTION_ENABLED', "false" buildConfigField 'Boolean', 'USE_AWS_S3', "false" buildConfigField 'Boolean', 'ORG_LINK', "false" + buildConfigField 'String', 'CRYPTO_KEY', "\"THE_BEST_APP_IN_THE_WORLD\"" - - javaCompileOptions { - annotationProcessorOptions { - arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] + kapt { + arguments { + arg("room.schemaLocation", "$projectDir/schemas") } } } @@ -228,9 +228,13 @@ dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5") //Database - implementation 'androidx.room:room-runtime:2.4.0-beta01' - implementation 'androidx.room:room-ktx:2.4.0-beta01' - kapt "androidx.room:room-compiler:2.4.0-beta01" + implementation 'androidx.room:room-runtime:2.4.0' + implementation 'androidx.room:room-ktx:2.4.0' + kapt "androidx.room:room-compiler:2.4.0" + + // Sqlcipher + implementation "net.zetetic:android-database-sqlcipher:4.4.2" + implementation "androidx.sqlite:sqlite:2.1.0" devImplementation 'com.amitshekhar.android:debug-db:1.0.6' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 67f342e4b..25dde02f1 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -51,3 +51,7 @@ # The SDK has several references of Apache HTTP client -dontwarn com.amazonaws.http.** -dontwarn com.amazonaws.metrics.** + +# SQLCipher +-keep,includedescriptorclasses class net.sqlcipher.** { *; } +-keep,includedescriptorclasses interface net.sqlcipher.** { *; } diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/1.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/1.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/1.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/1.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/2.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/2.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/2.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/2.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/3.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/3.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/3.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/3.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/4.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/4.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/4.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/4.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/6.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/6.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/6.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/6.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/7.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/7.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/7.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/7.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/8.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/8.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/8.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/8.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/9.json b/app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/9.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.database.AppDatabase/9.json rename to app/schemas/org.greenstand.android.TreeTracker.database.app.AppDatabase/9.json diff --git a/app/schemas/org.greenstand.android.TreeTracker.models.messages.database.MessageDatabase/1.json b/app/schemas/org.greenstand.android.TreeTracker.database.messages.MessageDatabase/1.json similarity index 100% rename from app/schemas/org.greenstand.android.TreeTracker.models.messages.database.MessageDatabase/1.json rename to app/schemas/org.greenstand.android.TreeTracker.database.messages.MessageDatabase/1.json diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModel.kt b/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModel.kt index 3267d7476..838c30ca8 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModel.kt @@ -35,7 +35,7 @@ import kotlinx.coroutines.withContext import org.greenstand.android.TreeTracker.R import org.greenstand.android.TreeTracker.analytics.Analytics import org.greenstand.android.TreeTracker.background.TreeSyncWorker -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.models.FeatureFlags import org.greenstand.android.TreeTracker.models.location.LocationDataCapturer import org.greenstand.android.TreeTracker.models.messages.MessagesRepo diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/TreesToSyncHelper.kt b/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/TreesToSyncHelper.kt index 7f4a387d3..f1fe73125 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/TreesToSyncHelper.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/dashboard/TreesToSyncHelper.kt @@ -15,7 +15,7 @@ */ package org.greenstand.android.TreeTracker.dashboard -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.preferences.PrefKey import org.greenstand.android.TreeTracker.preferences.PrefKeys import org.greenstand.android.TreeTracker.preferences.Preferences diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/AppDatabase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/AppDatabase.kt deleted file mode 100644 index 9019366f4..000000000 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/AppDatabase.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2023 Treetracker - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.greenstand.android.TreeTracker.database - -import android.content.Context -import androidx.room.AutoMigration -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -import androidx.room.TypeConverters -import org.greenstand.android.TreeTracker.database.entity.DeviceConfigEntity -import org.greenstand.android.TreeTracker.database.entity.LocationEntity -import org.greenstand.android.TreeTracker.database.entity.OrganizationEntity -import org.greenstand.android.TreeTracker.database.entity.SessionEntity -import org.greenstand.android.TreeTracker.database.entity.TreeEntity -import org.greenstand.android.TreeTracker.database.entity.UserEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.LocationDataEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterCheckInEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterInfoEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeAttributeEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeCaptureEntity - -@Database( - version = 9, - exportSchema = true, - entities = [ - PlanterCheckInEntity::class, - PlanterInfoEntity::class, - TreeAttributeEntity::class, - TreeCaptureEntity::class, - LocationDataEntity::class, - SessionEntity::class, - UserEntity::class, - LocationEntity::class, - TreeEntity::class, - DeviceConfigEntity::class, - OrganizationEntity::class, - ], - autoMigrations = [ - // 8 -> 9 for v2.2 - AutoMigration(from = 8, to = 9) - ], -) -@TypeConverters(Converters::class) -abstract class AppDatabase : RoomDatabase() { - - abstract fun treeTrackerDao(): TreeTrackerDAO - - companion object { - - private var INSTANCE: AppDatabase? = null - - fun getInstance(context: Context): AppDatabase { - if (INSTANCE == null) { - synchronized(AppDatabase::class) { - INSTANCE = Room.databaseBuilder( - context.applicationContext, - AppDatabase::class.java, - DB_NAME - ) - .addMigrations( - MIGRATION_3_4, - MIGRATION_4_5, - MIGRATION_5_6, - MIGRATION_6_7, - ) - .build() - } - } - return INSTANCE!! - } - - private const val DB_NAME = "treetracker.v2.db" - } -} \ No newline at end of file diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/app/AppDatabase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/AppDatabase.kt new file mode 100644 index 000000000..b760a89ae --- /dev/null +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/AppDatabase.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2023 Treetracker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.greenstand.android.TreeTracker.database.app + +import androidx.room.AutoMigration +import androidx.room.Database +import androidx.room.RoomDatabase +import androidx.room.TypeConverters +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.DeviceConfigEntity +import org.greenstand.android.TreeTracker.database.app.entity.LocationEntity +import org.greenstand.android.TreeTracker.database.app.entity.OrganizationEntity +import org.greenstand.android.TreeTracker.database.app.entity.SessionEntity +import org.greenstand.android.TreeTracker.database.app.entity.TreeEntity +import org.greenstand.android.TreeTracker.database.app.entity.UserEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.LocationDataEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterCheckInEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterInfoEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeAttributeEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeCaptureEntity + +@Database( + version = 9, + exportSchema = true, + entities = [ + PlanterCheckInEntity::class, + PlanterInfoEntity::class, + TreeAttributeEntity::class, + TreeCaptureEntity::class, + LocationDataEntity::class, + SessionEntity::class, + UserEntity::class, + LocationEntity::class, + TreeEntity::class, + DeviceConfigEntity::class, + OrganizationEntity::class, + ], + autoMigrations = [ + // 8 -> 9 for v2.2 + AutoMigration(from = 8, to = 9) + ], +) +@TypeConverters(Converters::class) +abstract class AppDatabase : RoomDatabase() { + + abstract fun treeTrackerDao(): TreeTrackerDAO + + companion object { + + const val DB_NAME = "treetracker.v2.db" + const val DB_NAME_ENCRYPT = "treetracker.v2-encrypt.db" + + } +} \ No newline at end of file diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/Converters.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/Converters.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/Converters.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/Converters.kt index 54312422e..68987b72f 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/Converters.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/Converters.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database +package org.greenstand.android.TreeTracker.database.app import androidx.room.TypeConverter import com.google.gson.Gson diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/Migrations.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/Migrations.kt similarity index 98% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/Migrations.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/Migrations.kt index 317e351df..9e00a381c 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/Migrations.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/Migrations.kt @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database +package org.greenstand.android.TreeTracker.database.app import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterInfoEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterInfoEntity val MIGRATION_6_7 = object : Migration(6, 7) { diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/TreeTrackerDAO.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/dao/TreeTrackerDAO.kt similarity index 92% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/TreeTrackerDAO.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/dao/TreeTrackerDAO.kt index b69865f2f..8c779d2ef 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/TreeTrackerDAO.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/dao/TreeTrackerDAO.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database +package org.greenstand.android.TreeTracker.database.app.dao import androidx.room.Dao import androidx.room.Delete @@ -23,17 +23,17 @@ import androidx.room.Query import androidx.room.Transaction import androidx.room.Update import kotlinx.coroutines.flow.Flow -import org.greenstand.android.TreeTracker.database.entity.DeviceConfigEntity -import org.greenstand.android.TreeTracker.database.entity.LocationEntity -import org.greenstand.android.TreeTracker.database.entity.OrganizationEntity -import org.greenstand.android.TreeTracker.database.entity.SessionEntity -import org.greenstand.android.TreeTracker.database.entity.TreeEntity -import org.greenstand.android.TreeTracker.database.entity.UserEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterCheckInEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterInfoEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeAttributeEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeCaptureEntity -import org.greenstand.android.TreeTracker.database.legacy.views.TreeMapMarkerDbView +import org.greenstand.android.TreeTracker.database.app.entity.DeviceConfigEntity +import org.greenstand.android.TreeTracker.database.app.entity.LocationEntity +import org.greenstand.android.TreeTracker.database.app.entity.OrganizationEntity +import org.greenstand.android.TreeTracker.database.app.entity.SessionEntity +import org.greenstand.android.TreeTracker.database.app.entity.TreeEntity +import org.greenstand.android.TreeTracker.database.app.entity.UserEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterCheckInEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterInfoEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeAttributeEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeCaptureEntity +import org.greenstand.android.TreeTracker.database.app.legacy.views.TreeMapMarkerDbView @Dao interface TreeTrackerDAO { diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/DeviceConfigEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/DeviceConfigEntity.kt similarity index 95% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/entity/DeviceConfigEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/DeviceConfigEntity.kt index ab2d9c7e3..d8f41da2d 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/DeviceConfigEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/DeviceConfigEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.entity +package org.greenstand.android.TreeTracker.database.app.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/LocationEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/LocationEntity.kt similarity index 95% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/entity/LocationEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/LocationEntity.kt index 86e39955b..4e7d6f341 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/LocationEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/LocationEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.entity +package org.greenstand.android.TreeTracker.database.app.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/OrganizationEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/OrganizationEntity.kt similarity index 94% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/entity/OrganizationEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/OrganizationEntity.kt index 3218116b4..25888f217 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/OrganizationEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/OrganizationEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.entity +package org.greenstand.android.TreeTracker.database.app.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/SessionEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/SessionEntity.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/entity/SessionEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/SessionEntity.kt index 0d3f3479d..babb92f33 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/SessionEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/SessionEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.entity +package org.greenstand.android.TreeTracker.database.app.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/TreeEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/TreeEntity.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/entity/TreeEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/TreeEntity.kt index 73f062417..ecdb7126b 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/TreeEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/TreeEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.entity +package org.greenstand.android.TreeTracker.database.app.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/UserEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/UserEntity.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/entity/UserEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/UserEntity.kt index 6b41af2f5..5ce029db2 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/entity/UserEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/entity/UserEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.entity +package org.greenstand.android.TreeTracker.database.app.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/LocationDataEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/LocationDataEntity.kt similarity index 95% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/LocationDataEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/LocationDataEntity.kt index a08dca8ae..e0334a718 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/LocationDataEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/LocationDataEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.entity +package org.greenstand.android.TreeTracker.database.app.legacy.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/PlanterCheckInEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/PlanterCheckInEntity.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/PlanterCheckInEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/PlanterCheckInEntity.kt index 892aeff27..0c85f30ed 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/PlanterCheckInEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/PlanterCheckInEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.entity +package org.greenstand.android.TreeTracker.database.app.legacy.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/PlanterInfoEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/PlanterInfoEntity.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/PlanterInfoEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/PlanterInfoEntity.kt index 2e94d85df..05f7a41fc 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/PlanterInfoEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/PlanterInfoEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.entity +package org.greenstand.android.TreeTracker.database.app.legacy.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/TreeAttributeEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/TreeAttributeEntity.kt similarity index 95% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/TreeAttributeEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/TreeAttributeEntity.kt index 7f1b81ac1..ffe23d190 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/TreeAttributeEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/TreeAttributeEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.entity +package org.greenstand.android.TreeTracker.database.app.legacy.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/TreeCaptureEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/TreeCaptureEntity.kt similarity index 97% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/TreeCaptureEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/TreeCaptureEntity.kt index 6f68a108d..ec1dc9f1e 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/entity/TreeCaptureEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/entity/TreeCaptureEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.entity +package org.greenstand.android.TreeTracker.database.app.legacy.entity import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/views/TreeMapMarkerDbView.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/views/TreeMapMarkerDbView.kt similarity index 91% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/views/TreeMapMarkerDbView.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/views/TreeMapMarkerDbView.kt index 151afa7cf..c07b1d225 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/views/TreeMapMarkerDbView.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/views/TreeMapMarkerDbView.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.views +package org.greenstand.android.TreeTracker.database.app.legacy.views class TreeMapMarkerDbView( val latitude: Double, diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/views/TreeUploadDbView.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/views/TreeUploadDbView.kt similarity index 97% rename from app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/views/TreeUploadDbView.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/views/TreeUploadDbView.kt index 881d5435f..69a216d75 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/database/legacy/views/TreeUploadDbView.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/app/legacy/views/TreeUploadDbView.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.database.legacy.views +package org.greenstand.android.TreeTracker.database.app.legacy.views // @DatabaseView(""" // SELECT diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/database/common/Encrypt.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/common/Encrypt.kt new file mode 100644 index 000000000..25815e598 --- /dev/null +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/common/Encrypt.kt @@ -0,0 +1,37 @@ +package org.greenstand.android.TreeTracker.database.common + +import android.content.Context +import net.sqlcipher.database.SQLiteDatabase +import org.greenstand.android.TreeTracker.BuildConfig + +object Encrypt { + + fun encrypt(context: Context, oldName: String, newName: String) { + SQLiteDatabase.loadLibs(context) + val dbFile = context.getDatabasePath(newName) + val legacyFile = context.getDatabasePath(oldName) + if (!dbFile.exists() && legacyFile.exists()) { + var db = SQLiteDatabase.openOrCreateDatabase(legacyFile, "", null) + db.rawExecSQL( + String.format( + "ATTACH DATABASE '%s' AS encrypted KEY '%s';", + dbFile.absolutePath, + if (BuildConfig.DEBUG) "" else BuildConfig.CRYPTO_KEY + ) + ) + db.rawExecSQL("SELECT sqlcipher_export('encrypted')") + db.rawExecSQL("DETACH DATABASE encrypted;") + val version = db.version + db.close() + db = SQLiteDatabase.openOrCreateDatabase( + dbFile, + if (BuildConfig.DEBUG) "" else BuildConfig.CRYPTO_KEY, + null + ) + db.version = version + db.close() + legacyFile.delete() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/DatabaseConverters.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/DatabaseConverters.kt similarity index 94% rename from app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/DatabaseConverters.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/messages/DatabaseConverters.kt index fcc2877ff..30f1b0260 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/DatabaseConverters.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/DatabaseConverters.kt @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.models.messages.database +package org.greenstand.android.TreeTracker.database.messages +import org.greenstand.android.TreeTracker.database.messages.entities.MessageEntity +import org.greenstand.android.TreeTracker.database.messages.entities.QuestionEntity +import org.greenstand.android.TreeTracker.database.messages.entities.SurveyEntity import org.greenstand.android.TreeTracker.models.messages.AnnouncementMessage import org.greenstand.android.TreeTracker.models.messages.DirectMessage import org.greenstand.android.TreeTracker.models.messages.Message import org.greenstand.android.TreeTracker.models.messages.Question import org.greenstand.android.TreeTracker.models.messages.SurveyMessage import org.greenstand.android.TreeTracker.models.messages.SurveyResponseMessage -import org.greenstand.android.TreeTracker.models.messages.database.entities.MessageEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.QuestionEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.SurveyEntity import org.greenstand.android.TreeTracker.models.messages.network.requests.MessageRequest import org.greenstand.android.TreeTracker.models.messages.network.responses.MessageType diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/MessageDatabase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/MessageDatabase.kt similarity index 50% rename from app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/MessageDatabase.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/messages/MessageDatabase.kt index 90e50ccc9..0ba28d3b3 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/MessageDatabase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/MessageDatabase.kt @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.models.messages.database +package org.greenstand.android.TreeTracker.database.messages -import android.content.Context import androidx.room.Database -import androidx.room.Room import androidx.room.RoomDatabase import androidx.room.TypeConverters -import org.greenstand.android.TreeTracker.database.Converters -import org.greenstand.android.TreeTracker.models.messages.database.entities.MessageEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.QuestionEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.SurveyEntity +import org.greenstand.android.TreeTracker.database.app.Converters +import org.greenstand.android.TreeTracker.database.messages.dao.MessagesDAO +import org.greenstand.android.TreeTracker.database.messages.entities.MessageEntity +import org.greenstand.android.TreeTracker.database.messages.entities.QuestionEntity +import org.greenstand.android.TreeTracker.database.messages.entities.SurveyEntity @Database( version = 1, @@ -41,21 +40,9 @@ abstract class MessageDatabase : RoomDatabase() { companion object { - private var INSTANCE: MessageDatabase? = null + const val DB_NAME = "treetracker.messages.db" + const val DB_NAME_ENCRYPT = "treetracker.messages-encrypt.db" - fun getInstance(context: Context): MessageDatabase { - if (INSTANCE == null) { - synchronized(MessageDatabase::class) { - INSTANCE = Room.databaseBuilder( - context.applicationContext, - MessageDatabase::class.java, - DB_NAME - ).build() - } - } - return INSTANCE!! - } - private const val DB_NAME = "treetracker.messages.db" } } \ No newline at end of file diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/MessagesDAO.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/dao/MessagesDAO.kt similarity index 91% rename from app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/MessagesDAO.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/messages/dao/MessagesDAO.kt index 38a761d75..c0cc0fc0e 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/MessagesDAO.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/dao/MessagesDAO.kt @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.models.messages.database +package org.greenstand.android.TreeTracker.database.messages.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import kotlinx.coroutines.flow.Flow -import org.greenstand.android.TreeTracker.models.messages.database.entities.MessageEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.QuestionEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.SurveyEntity +import org.greenstand.android.TreeTracker.database.messages.entities.MessageEntity +import org.greenstand.android.TreeTracker.database.messages.entities.QuestionEntity +import org.greenstand.android.TreeTracker.database.messages.entities.SurveyEntity @Dao interface MessagesDAO { diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/MessageEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/MessageEntity.kt similarity index 96% rename from app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/MessageEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/MessageEntity.kt index eda22b940..4a92e58e9 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/MessageEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/MessageEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.models.messages.database.entities +package org.greenstand.android.TreeTracker.database.messages.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/QuestionEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/QuestionEntity.kt similarity index 94% rename from app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/QuestionEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/QuestionEntity.kt index cdf6430da..8df7a3028 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/QuestionEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/QuestionEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.models.messages.database.entities +package org.greenstand.android.TreeTracker.database.messages.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/SurveyEntity.kt b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/SurveyEntity.kt similarity index 91% rename from app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/SurveyEntity.kt rename to app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/SurveyEntity.kt index af0da9ebf..bb8305129 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/database/entities/SurveyEntity.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/database/messages/entities/SurveyEntity.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.greenstand.android.TreeTracker.models.messages.database.entities +package org.greenstand.android.TreeTracker.database.messages.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/di/RoomModule.kt b/app/src/main/java/org/greenstand/android/TreeTracker/di/RoomModule.kt index 26ce3a28c..a12860ada 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/di/RoomModule.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/di/RoomModule.kt @@ -15,17 +15,56 @@ */ package org.greenstand.android.TreeTracker.di -import org.greenstand.android.TreeTracker.database.AppDatabase -import org.greenstand.android.TreeTracker.models.messages.database.MessageDatabase +import androidx.room.Room +import net.sqlcipher.database.SupportFactory +import org.greenstand.android.TreeTracker.BuildConfig +import org.greenstand.android.TreeTracker.database.app.AppDatabase +import org.greenstand.android.TreeTracker.database.app.MIGRATION_3_4 +import org.greenstand.android.TreeTracker.database.app.MIGRATION_4_5 +import org.greenstand.android.TreeTracker.database.app.MIGRATION_5_6 +import org.greenstand.android.TreeTracker.database.app.MIGRATION_6_7 +import org.greenstand.android.TreeTracker.database.common.Encrypt.encrypt +import org.greenstand.android.TreeTracker.database.messages.MessageDatabase import org.koin.dsl.module val roomModule = module { - single { AppDatabase.getInstance(get()) } + single { + encrypt( + context = get(), + oldName = AppDatabase.DB_NAME, + newName = AppDatabase.DB_NAME_ENCRYPT + ) + Room.databaseBuilder( + get(), + AppDatabase::class.java, + AppDatabase.DB_NAME_ENCRYPT + ).addMigrations( + MIGRATION_3_4, + MIGRATION_4_5, + MIGRATION_5_6, + MIGRATION_6_7, + ).openHelperFactory( + if (BuildConfig.DEBUG) null else SupportFactory(BuildConfig.CRYPTO_KEY.toByteArray()) + ).build() + } - single { AppDatabase.getInstance(get()).treeTrackerDao() } + single { get().treeTrackerDao() } - single { MessageDatabase.getInstance(get()) } + single { + encrypt( + context = get(), + oldName = MessageDatabase.DB_NAME, + newName = MessageDatabase.DB_NAME_ENCRYPT + ) + Room.databaseBuilder( + get(), + MessageDatabase::class.java, + MessageDatabase.DB_NAME_ENCRYPT + ).openHelperFactory( + if (BuildConfig.DEBUG) null else SupportFactory(BuildConfig.CRYPTO_KEY.toByteArray()) + ).build() + } - single { MessageDatabase.getInstance(get()).messagesDao() } + single { get().messagesDao() } } \ No newline at end of file diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUpdater.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUpdater.kt index 29f5aa39b..176f73777 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUpdater.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUpdater.kt @@ -17,10 +17,10 @@ package org.greenstand.android.TreeTracker.models import android.os.Build import org.greenstand.android.TreeTracker.BuildConfig -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.DeviceConfigEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.DeviceConfigEntity import org.greenstand.android.TreeTracker.utilities.TimeProvider -import java.util.* +import java.util.UUID class DeviceConfigUpdater( private val dao: TreeTrackerDAO, diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUploader.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUploader.kt index c7d03d128..e3308ed82 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUploader.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/DeviceConfigUploader.kt @@ -19,7 +19,7 @@ import com.google.gson.Gson import org.greenstand.android.TreeTracker.api.ObjectStorageClient import org.greenstand.android.TreeTracker.api.models.requests.DeviceConfigRequest import org.greenstand.android.TreeTracker.api.models.requests.UploadBundle -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.utilities.md5 class DeviceConfigUploader( diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/PlanterUploader.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/PlanterUploader.kt index a9a97b43b..0a39ca5ef 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/PlanterUploader.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/PlanterUploader.kt @@ -24,7 +24,7 @@ import org.greenstand.android.TreeTracker.api.ObjectStorageClient import org.greenstand.android.TreeTracker.api.models.requests.RegistrationRequest import org.greenstand.android.TreeTracker.api.models.requests.UploadBundle import org.greenstand.android.TreeTracker.api.models.requests.WalletRegistrationRequest -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.usecases.UploadImageParams import org.greenstand.android.TreeTracker.usecases.UploadImageUseCase import org.greenstand.android.TreeTracker.utilities.md5 diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionTracker.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionTracker.kt index 1c552d7ad..e419e032c 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionTracker.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionTracker.kt @@ -19,15 +19,15 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.greenstand.android.TreeTracker.analytics.ExceptionDataCollector import org.greenstand.android.TreeTracker.dashboard.TreesToSyncHelper -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.SessionEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.SessionEntity import org.greenstand.android.TreeTracker.models.organization.OrgRepo import org.greenstand.android.TreeTracker.models.setupflow.CaptureSetupScopeManager import org.greenstand.android.TreeTracker.preferences.PrefKey import org.greenstand.android.TreeTracker.preferences.PrefKeys import org.greenstand.android.TreeTracker.preferences.Preferences import org.greenstand.android.TreeTracker.utilities.TimeProvider -import java.util.* +import java.util.UUID class SessionTracker( private val dao: TreeTrackerDAO, diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionUploader.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionUploader.kt index 049b6e8da..24e3964e5 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionUploader.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/SessionUploader.kt @@ -19,7 +19,7 @@ import com.google.gson.Gson import org.greenstand.android.TreeTracker.api.ObjectStorageClient import org.greenstand.android.TreeTracker.api.models.requests.SessionRequest import org.greenstand.android.TreeTracker.api.models.requests.UploadBundle -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.utilities.md5 class SessionUploader( diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/TreeUploader.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/TreeUploader.kt index 3637d62a6..9b72d1681 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/TreeUploader.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/TreeUploader.kt @@ -23,9 +23,9 @@ import kotlinx.coroutines.isActive import org.greenstand.android.TreeTracker.api.ObjectStorageClient import org.greenstand.android.TreeTracker.api.models.requests.TreeCaptureRequest import org.greenstand.android.TreeTracker.api.models.requests.UploadBundle -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.TreeEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeCaptureEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.TreeEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeCaptureEntity import org.greenstand.android.TreeTracker.usecases.CreateTreeRequestParams import org.greenstand.android.TreeTracker.usecases.CreateTreeRequestUseCase import org.greenstand.android.TreeTracker.usecases.UploadImageParams diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturer.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturer.kt index 4c0799849..f276e6e2a 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturer.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturer.kt @@ -25,15 +25,17 @@ import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withTimeout -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.LocationEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.LocationEntity import org.greenstand.android.TreeTracker.models.ConvergenceConfiguration import org.greenstand.android.TreeTracker.models.ConvergenceStatus import org.greenstand.android.TreeTracker.models.LocationData import org.greenstand.android.TreeTracker.models.SessionTracker import org.greenstand.android.TreeTracker.utilities.TimeProvider import timber.log.Timber -import java.util.* +import java.util.Deque +import java.util.LinkedList +import java.util.UUID import kotlin.math.min import kotlin.properties.Delegates diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessageUploader.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessageUploader.kt index b0b4c5beb..c7d8f6447 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessageUploader.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessageUploader.kt @@ -20,8 +20,8 @@ import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import org.greenstand.android.TreeTracker.api.ObjectStorageClient import org.greenstand.android.TreeTracker.api.models.requests.UploadBundle -import org.greenstand.android.TreeTracker.models.messages.database.DatabaseConverters -import org.greenstand.android.TreeTracker.models.messages.database.MessagesDAO +import org.greenstand.android.TreeTracker.database.messages.DatabaseConverters +import org.greenstand.android.TreeTracker.database.messages.dao.MessagesDAO import org.greenstand.android.TreeTracker.utilities.md5 import kotlin.time.ExperimentalTime diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepo.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepo.kt index 2a06f25e6..1ed8e0ed5 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepo.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepo.kt @@ -15,16 +15,22 @@ */ package org.greenstand.android.TreeTracker.models.messages -import kotlinx.coroutines.* +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map +import kotlinx.coroutines.withContext import kotlinx.datetime.Instant +import org.greenstand.android.TreeTracker.database.messages.DatabaseConverters +import org.greenstand.android.TreeTracker.database.messages.dao.MessagesDAO +import org.greenstand.android.TreeTracker.database.messages.entities.MessageEntity +import org.greenstand.android.TreeTracker.database.messages.entities.QuestionEntity +import org.greenstand.android.TreeTracker.database.messages.entities.SurveyEntity import org.greenstand.android.TreeTracker.models.UserRepo -import org.greenstand.android.TreeTracker.models.messages.database.DatabaseConverters -import org.greenstand.android.TreeTracker.models.messages.database.MessagesDAO -import org.greenstand.android.TreeTracker.models.messages.database.entities.MessageEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.QuestionEntity -import org.greenstand.android.TreeTracker.models.messages.database.entities.SurveyEntity import org.greenstand.android.TreeTracker.models.messages.network.MessagesApiService import org.greenstand.android.TreeTracker.models.messages.network.responses.MessageResponse import org.greenstand.android.TreeTracker.models.messages.network.responses.MessageType @@ -34,7 +40,7 @@ import org.greenstand.android.TreeTracker.utilities.Constants import org.greenstand.android.TreeTracker.utilities.TimeProvider import org.greenstand.android.TreeTracker.utils.runInParallel import timber.log.Timber -import java.util.* +import java.util.UUID /** * For test data, use 'handle2@test', 'handle3@test', or 'handle4@test' as a wallet (email) diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/organization/OrgRepo.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/organization/OrgRepo.kt index d70deed6d..7737597e3 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/organization/OrgRepo.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/organization/OrgRepo.kt @@ -18,8 +18,8 @@ package org.greenstand.android.TreeTracker.models.organization import com.google.gson.Gson import com.google.gson.JsonParser import com.google.gson.reflect.TypeToken -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.OrganizationEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.OrganizationEntity import org.greenstand.android.TreeTracker.models.NavRoute import org.greenstand.android.TreeTracker.preferences.PrefKey import org.greenstand.android.TreeTracker.preferences.PrefKeys diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/models/user/UserRepo.kt b/app/src/main/java/org/greenstand/android/TreeTracker/models/user/UserRepo.kt index ea28f6e0e..9fa75fcaf 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/models/user/UserRepo.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/models/user/UserRepo.kt @@ -21,13 +21,13 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.withContext import org.greenstand.android.TreeTracker.analytics.Analytics import org.greenstand.android.TreeTracker.analytics.ExceptionDataCollector -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.UserEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.UserEntity +import org.greenstand.android.TreeTracker.database.messages.dao.MessagesDAO import org.greenstand.android.TreeTracker.models.location.LocationUpdateManager -import org.greenstand.android.TreeTracker.models.messages.database.MessagesDAO import org.greenstand.android.TreeTracker.models.user.User import org.greenstand.android.TreeTracker.utilities.TimeProvider -import java.util.* +import java.util.UUID class UserRepo( private val locationUpdateManager: LocationUpdateManager, diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateFakeTreesUseCase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateFakeTreesUseCase.kt index 05c78c359..42d32e0ce 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateFakeTreesUseCase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateFakeTreesUseCase.kt @@ -18,15 +18,15 @@ package org.greenstand.android.TreeTracker.usecases import android.content.Context import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterCheckInEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.PlanterInfoEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterCheckInEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterInfoEntity import org.greenstand.android.TreeTracker.models.SessionTracker import org.greenstand.android.TreeTracker.models.Tree import org.greenstand.android.TreeTracker.models.location.LocationUpdateManager import org.greenstand.android.TreeTracker.utilities.ImageUtils import org.greenstand.android.TreeTracker.utilities.TimeProvider -import java.util.* +import java.util.UUID data class CreateFakeTreesParams(val amount: Int) diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateLegacyTreeUseCase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateLegacyTreeUseCase.kt index 6e92f7345..ddf25e939 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateLegacyTreeUseCase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateLegacyTreeUseCase.kt @@ -17,9 +17,9 @@ package org.greenstand.android.TreeTracker.usecases import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeAttributeEntity -import org.greenstand.android.TreeTracker.database.legacy.entity.TreeCaptureEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeAttributeEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeCaptureEntity import org.greenstand.android.TreeTracker.models.Tree import org.greenstand.android.TreeTracker.utilities.TimeProvider import timber.log.Timber diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeRequestUseCase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeRequestUseCase.kt index 998b6bf7a..7f065a525 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeRequestUseCase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeRequestUseCase.kt @@ -17,7 +17,7 @@ package org.greenstand.android.TreeTracker.usecases import org.greenstand.android.TreeTracker.api.models.requests.AttributeRequest import org.greenstand.android.TreeTracker.api.models.requests.NewTreeRequest -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.utilities.DeviceUtils data class CreateTreeRequestParams( diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeUseCase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeUseCase.kt index d0731efe0..e325c3667 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeUseCase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/CreateTreeUseCase.kt @@ -18,8 +18,8 @@ package org.greenstand.android.TreeTracker.usecases import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.greenstand.android.TreeTracker.analytics.Analytics -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO -import org.greenstand.android.TreeTracker.database.entity.TreeEntity +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.entity.TreeEntity import org.greenstand.android.TreeTracker.models.Tree import org.greenstand.android.TreeTracker.utilities.TimeProvider import timber.log.Timber diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/SyncDataUseCase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/SyncDataUseCase.kt index 655f9dd26..7b4595242 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/SyncDataUseCase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/SyncDataUseCase.kt @@ -19,7 +19,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.cancel import kotlinx.coroutines.isActive import kotlinx.coroutines.withContext -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.models.DeviceConfigUploader import org.greenstand.android.TreeTracker.models.PlanterUploader import org.greenstand.android.TreeTracker.models.SessionUploader diff --git a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/UploadLocationDataUseCase.kt b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/UploadLocationDataUseCase.kt index 3b945e642..8ff7d27c3 100644 --- a/app/src/main/java/org/greenstand/android/TreeTracker/usecases/UploadLocationDataUseCase.kt +++ b/app/src/main/java/org/greenstand/android/TreeTracker/usecases/UploadLocationDataUseCase.kt @@ -22,7 +22,7 @@ import kotlinx.coroutines.withContext import org.greenstand.android.TreeTracker.api.ObjectStorageClient import org.greenstand.android.TreeTracker.api.models.requests.TracksRequest import org.greenstand.android.TreeTracker.api.models.requests.UploadBundle -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.models.LocationData import org.greenstand.android.TreeTracker.utilities.md5 import timber.log.Timber diff --git a/app/src/test/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModelTest.kt b/app/src/test/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModelTest.kt index 49986d09b..97fdb554f 100644 --- a/app/src/test/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModelTest.kt +++ b/app/src/test/java/org/greenstand/android/TreeTracker/dashboard/DashboardViewModelTest.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.greenstand.android.TreeTracker.MainCoroutineRule import org.greenstand.android.TreeTracker.analytics.Analytics -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.models.location.LocationDataCapturer import org.greenstand.android.TreeTracker.models.messages.MessagesRepo import org.greenstand.android.TreeTracker.models.organization.OrgRepo diff --git a/app/src/test/java/org/greenstand/android/TreeTracker/database/TreeTrackerDaoTest.kt b/app/src/test/java/org/greenstand/android/TreeTracker/database/TreeTrackerDaoTest.kt index 1527e117d..43d0c3349 100644 --- a/app/src/test/java/org/greenstand/android/TreeTracker/database/TreeTrackerDaoTest.kt +++ b/app/src/test/java/org/greenstand/android/TreeTracker/database/TreeTrackerDaoTest.kt @@ -21,6 +21,8 @@ import androidx.test.core.app.ApplicationProvider import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking +import org.greenstand.android.TreeTracker.database.app.AppDatabase +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.utils.* import org.junit.After import org.junit.Assert.* diff --git a/app/src/test/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturerTest.kt b/app/src/test/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturerTest.kt index a2b96e2cf..e941483f0 100644 --- a/app/src/test/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturerTest.kt +++ b/app/src/test/java/org/greenstand/android/TreeTracker/models/location/LocationDataCapturerTest.kt @@ -27,7 +27,7 @@ import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.mockk import io.mockk.verify -import org.greenstand.android.TreeTracker.database.TreeTrackerDAO +import org.greenstand.android.TreeTracker.database.app.dao.TreeTrackerDAO import org.greenstand.android.TreeTracker.models.ConvergenceConfiguration import org.greenstand.android.TreeTracker.models.LocationDataConfig import org.greenstand.android.TreeTracker.models.SessionTracker diff --git a/app/src/test/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepoTest.kt b/app/src/test/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepoTest.kt index 887a408e5..652cfe55e 100644 --- a/app/src/test/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepoTest.kt +++ b/app/src/test/java/org/greenstand/android/TreeTracker/models/messages/MessagesRepoTest.kt @@ -24,9 +24,9 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.* import org.greenstand.android.TreeTracker.MainCoroutineRule +import org.greenstand.android.TreeTracker.database.messages.dao.MessagesDAO +import org.greenstand.android.TreeTracker.database.messages.entities.MessageEntity import org.greenstand.android.TreeTracker.models.UserRepo -import org.greenstand.android.TreeTracker.models.messages.database.MessagesDAO -import org.greenstand.android.TreeTracker.models.messages.database.entities.MessageEntity import org.greenstand.android.TreeTracker.models.messages.network.MessagesApiService import org.greenstand.android.TreeTracker.models.messages.network.responses.* import org.greenstand.android.TreeTracker.models.user.User diff --git a/app/src/test/java/org/greenstand/android/TreeTracker/utils/FakeFileGenerator.kt b/app/src/test/java/org/greenstand/android/TreeTracker/utils/FakeFileGenerator.kt index 55330a739..97012173d 100644 --- a/app/src/test/java/org/greenstand/android/TreeTracker/utils/FakeFileGenerator.kt +++ b/app/src/test/java/org/greenstand/android/TreeTracker/utils/FakeFileGenerator.kt @@ -16,8 +16,17 @@ package org.greenstand.android.TreeTracker.utils import kotlinx.datetime.Instant -import org.greenstand.android.TreeTracker.database.entity.* -import org.greenstand.android.TreeTracker.database.legacy.entity.* +import org.greenstand.android.TreeTracker.database.app.entity.DeviceConfigEntity +import org.greenstand.android.TreeTracker.database.app.entity.LocationEntity +import org.greenstand.android.TreeTracker.database.app.entity.OrganizationEntity +import org.greenstand.android.TreeTracker.database.app.entity.SessionEntity +import org.greenstand.android.TreeTracker.database.app.entity.TreeEntity +import org.greenstand.android.TreeTracker.database.app.entity.UserEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.LocationDataEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterCheckInEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.PlanterInfoEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeAttributeEntity +import org.greenstand.android.TreeTracker.database.app.legacy.entity.TreeCaptureEntity import org.greenstand.android.TreeTracker.models.messages.AnnouncementMessage import org.greenstand.android.TreeTracker.models.messages.DirectMessage import org.greenstand.android.TreeTracker.models.messages.Question