Skip to content

Commit e00ded4

Browse files
authored
Merge pull request #5155 from nextcloud/chore/5103/support16kbPageSizes
Support 16 KB page sizes
2 parents f760ee3 + 3490393 commit e00ded4

File tree

9 files changed

+18
-132
lines changed

9 files changed

+18
-132
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ dependencies {
252252
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
253253

254254
implementation 'org.greenrobot:eventbus:3.3.1'
255-
implementation 'net.zetetic:android-database-sqlcipher:4.5.4'
255+
implementation 'net.zetetic:sqlcipher-android:4.9.0'
256256

257257
implementation "androidx.room:room-runtime:${roomVersion}"
258258
implementation "androidx.room:room-rxjava2:${roomVersion}"

app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,6 @@ class MainActivity :
253253
startActivity(chatIntent)
254254
}
255255
} else {
256-
if (!appPreferences.isDbRoomMigrated) {
257-
appPreferences.isDbRoomMigrated = true
258-
}
259-
260256
userManager.users.subscribe(object : SingleObserver<List<User>> {
261257
override fun onSubscribe(d: Disposable) {
262258
// unused atm

app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ import com.vanniktech.emoji.EmojiManager
5858
import com.vanniktech.emoji.google.GoogleEmojiProvider
5959
import de.cotech.hw.SecurityKeyManager
6060
import de.cotech.hw.SecurityKeyManagerConfig
61-
import net.sqlcipher.database.SQLiteDatabase
62-
import net.sqlcipher.database.SQLiteDatabaseHook
6361
import okhttp3.OkHttpClient
6462
import org.conscrypt.Conscrypt
6563
import org.webrtc.PeerConnectionFactory
@@ -103,18 +101,6 @@ class NextcloudTalkApplication :
103101
lateinit var okHttpClient: OkHttpClient
104102
//endregion
105103

106-
val hook: SQLiteDatabaseHook = object : SQLiteDatabaseHook {
107-
override fun preKey(database: SQLiteDatabase) {
108-
// unused atm
109-
}
110-
111-
override fun postKey(database: SQLiteDatabase) {
112-
Log.i("TalkApplication", "DB cipher_migrate START")
113-
database.rawExecSQL("PRAGMA cipher_migrate;")
114-
Log.i("TalkApplication", "DB cipher_migrate END")
115-
}
116-
}
117-
118104
//region private methods
119105
private fun initializeWebRtc() {
120106
try {

app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public AppPreferencesImpl providePreferencesImpl(@NonNull final Context poContex
4242

4343
@Provides
4444
@Singleton
45-
public TalkDatabase provideTalkDatabase(@NonNull final Context context,
46-
@NonNull final AppPreferences appPreferences) {
47-
return TalkDatabase.getInstance(context, appPreferences);
45+
public TalkDatabase provideTalkDatabase(@NonNull final Context context) {
46+
return TalkDatabase.getInstance(context);
4847
}
4948

5049
@Provides

app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package com.nextcloud.talk.data.source.local
1010

1111
import android.content.Context
12-
import android.util.Log
1312
import androidx.room.AutoMigration
1413
import androidx.room.Database
1514
import androidx.room.Room
@@ -37,10 +36,7 @@ import com.nextcloud.talk.data.storage.ArbitraryStoragesDao
3736
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
3837
import com.nextcloud.talk.data.user.UsersDao
3938
import com.nextcloud.talk.data.user.model.UserEntity
40-
import com.nextcloud.talk.utils.preferences.AppPreferences
41-
import net.sqlcipher.database.SQLiteDatabase
42-
import net.sqlcipher.database.SQLiteDatabaseHook
43-
import net.sqlcipher.database.SupportFactory
39+
import net.zetetic.database.sqlcipher.SupportOpenHelperFactory
4440
import java.util.Locale
4541

4642
@Database(
@@ -70,7 +66,6 @@ import java.util.Locale
7066
SendStatusConverter::class
7167
)
7268
abstract class TalkDatabase : RoomDatabase() {
73-
7469
abstract fun usersDao(): UsersDao
7570
abstract fun conversationsDao(): ConversationsDao
7671
abstract fun chatMessagesDao(): ChatMessagesDao
@@ -79,27 +74,21 @@ abstract class TalkDatabase : RoomDatabase() {
7974

8075
companion object {
8176
const val TAG = "TalkDatabase"
77+
const val SQL_CIPHER_LIBRARY = "sqlcipher"
8278

8379
@Volatile
8480
private var instance: TalkDatabase? = null
8581

8682
@JvmStatic
87-
fun getInstance(context: Context, appPreferences: AppPreferences): TalkDatabase =
83+
fun getInstance(context: Context): TalkDatabase =
8884
instance ?: synchronized(this) {
89-
instance ?: build(context, appPreferences).also { instance = it }
85+
instance ?: build(context).also { instance = it }
9086
}
9187

92-
private fun build(context: Context, appPreferences: AppPreferences): TalkDatabase {
88+
private fun build(context: Context): TalkDatabase {
9389
val passCharArray = context.getString(R.string.nc_talk_database_encryption_key).toCharArray()
94-
val passphrase: ByteArray = SQLiteDatabase.getBytes(passCharArray)
95-
96-
val factory = if (appPreferences.isDbRoomMigrated) {
97-
Log.i(TAG, "No cipher migration needed")
98-
SupportFactory(passphrase)
99-
} else {
100-
Log.i(TAG, "Add cipher migration hook")
101-
SupportFactory(passphrase, getCipherMigrationHook())
102-
}
90+
val passphrase: ByteArray = getBytesFromChars(passCharArray)
91+
val factory = SupportOpenHelperFactory(passphrase)
10392

10493
val dbName = context
10594
.resources
@@ -109,6 +98,8 @@ abstract class TalkDatabase : RoomDatabase() {
10998
.trim() +
11099
".sqlite"
111100

101+
System.loadLibrary(SQL_CIPHER_LIBRARY)
102+
112103
return Room
113104
.databaseBuilder(context.applicationContext, TalkDatabase::class.java, dbName)
114105
// comment out openHelperFactory to view the database entries in Android Studio for debugging
@@ -126,7 +117,7 @@ abstract class TalkDatabase : RoomDatabase() {
126117
)
127118
.allowMainThreadQueries()
128119
.addCallback(
129-
object : RoomDatabase.Callback() {
120+
object : Callback() {
130121
override fun onOpen(db: SupportSQLiteDatabase) {
131122
super.onOpen(db)
132123
db.execSQL("PRAGMA defer_foreign_keys = 1")
@@ -136,17 +127,6 @@ abstract class TalkDatabase : RoomDatabase() {
136127
.build()
137128
}
138129

139-
private fun getCipherMigrationHook(): SQLiteDatabaseHook =
140-
object : SQLiteDatabaseHook {
141-
override fun preKey(database: SQLiteDatabase) {
142-
// unused atm
143-
}
144-
145-
override fun postKey(database: SQLiteDatabase) {
146-
Log.i(TAG, "DB cipher_migrate START")
147-
database.rawExecSQL("PRAGMA cipher_migrate;")
148-
Log.i(TAG, "DB cipher_migrate END")
149-
}
150-
}
130+
private fun getBytesFromChars(chars: CharArray): ByteArray = String(chars).toByteArray(Charsets.UTF_8)
151131
}
152132
}

app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ public interface AppPreferences {
143143

144144
void setDbCypherToUpgrade(boolean value);
145145

146-
boolean getIsDbRoomMigrated();
147-
148-
void setIsDbRoomMigrated(boolean value);
149-
150146
void setPhoneBookIntegrationLastRun(long currentTimeMillis);
151147

152148
long getPhoneBookIntegrationLastRun(Long defaultValue);

app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,6 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
388388
}
389389
}
390390

391-
override fun getIsDbRoomMigrated(): Boolean =
392-
runBlocking {
393-
async { readBoolean(DB_ROOM_MIGRATED).first() }
394-
}.getCompleted()
395-
396-
override fun setIsDbRoomMigrated(value: Boolean) =
397-
runBlocking<Unit> {
398-
async {
399-
writeBoolean(DB_ROOM_MIGRATED, value)
400-
}
401-
}
402-
403391
override fun getShowRegularNotificationWarning(): Boolean =
404392
runBlocking {
405393
async { readBoolean(SHOW_REGULAR_NOTIFICATION_WARNING, true).first() }

gradle/verification-keyring.keys

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,24 +1036,6 @@ EEIhZlI/ojefaZkRseFrtl3X
10361036
=pJaU
10371037
-----END PGP PUBLIC KEY BLOCK-----
10381038

1039-
pub A6EA2E2BF22E0543
1040-
uid Tobias Warneke (for development purposes) <[email protected]>
1041-
1042-
-----BEGIN PGP PUBLIC KEY BLOCK-----
1043-
1044-
mQGNBFJQhigBDADpuhND/VUQwJT0nnJxfjAIur59hyaZZ3Ph/KIgmCneyq7lzYO6
1045-
xa1ucH8mqNBVNLLBhs4CjihBddU/ZKTX3WnZyhQKQMZr3Tg+TCNFmAR4/hnZ3NjZ
1046-
N5N5gUj/dqVI2rIvypIuxUApl88BYMsxYpn2+8FKeMd8oBJLqFRJ3WNjB4Op2tRO
1047-
XRWoxs1ypubS/IV1zkphHHpi6VSABlTyTWu4kXEj/1/GpsdtHRa9kvdWw7yKQbnM
1048-
XuwOxtzZFJcyu0P2jYVfHHvxcjxuklc9edmCGdNxgKIoo0LXZOeFIi6OWtwzD0pn
1049-
O6ovJ+PL9QscMdnQlPwsiCwjNUNue20GBv3aUIYc+Z8Gq0SqSan5V0IiKRHMJkzd
1050-
FAhnpkSFBvHhPJn07BCcb1kctqL+xnLxIdi7arq3WNA/6bJjsojc/x3FdIvORIeP
1051-
sqejhtL8mCBvbMAMHSBrFxclMp+HSz2ouHEEPIQam0KeN8t1yEqIy3/aYKMzHj9c
1052-
C3s8XOaBCbJbKpMAEQEAAbQ9VG9iaWFzIFdhcm5la2UgKGZvciBkZXZlbG9wbWVu
1053-
dCBwdXJwb3NlcykgPHQud2FybmVrZUBnbXgubmV0Pg==
1054-
=q1C6
1055-
-----END PGP PUBLIC KEY BLOCK-----
1056-
10571039
pub A730529CA355A63E
10581040
uid Jukka Zitting <[email protected]>
10591041

@@ -3802,50 +3784,6 @@ pIXjPlQ0i6kV0h8KapE1Uo005JYgeg==
38023784
=ASmD
38033785
-----END PGP PUBLIC KEY BLOCK-----
38043786

3805-
pub 1DE461528F1F1B2A
3806-
uid Julian Reschke (CODE SIGNING KEY) <[email protected]>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lVJWlAo9M0HFVWcuAZRLGAZIWM2uPhhebqeElDOJORU3B
3842-
3sKQjtdKY1zidyPsjsKuTeq2qkq6bJTbJkZmu/7SX/qAP1Q0fEvsFhGf0ou6RFxe
3843-
Rlu5Z4N59K6lkXo9+GLAWuc99maXWuYioln5OcoP7xTaFZwqDlF+Z9/Pxzu1foQW
3844-
B8KrqPXwhp7/Z3JmW/7jP4EeiXKgA5r4tbBjZnugOhkeRv58z0IKlLLo0c4raiuJ
3845-
ZAstgdvEqFLHh1yX4I+if5VODD2nEzXFDzE=
3846-
=d5S6
3847-
-----END PGP PUBLIC KEY BLOCK-----
3848-
38493787
pub 1F7A8F87B9D8F501
38503788
uid Download <[email protected]>
38513789

gradle/verification-metadata.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@
164164
<trusting group="ch.qos.logback"/>
165165
<trusting group="org.slf4j"/>
166166
</trusted-key>
167-
<trusted-key id="61DEBD732F3F07771269972E2F87304808D40CEC" group="net.zetetic" name="android-database-sqlcipher" version="4.5.4"/>
167+
<trusted-key id="61DEBD732F3F07771269972E2F87304808D40CEC">
168+
<trusting name="android-database-sqlcipher" group="net.zetetic" version="4.5.4"/>
169+
<trusting name="sqlcipher-android" group="net.zetetic" version="4.9.0"/>
170+
</trusted-key>
168171
<trusted-key id="64B9B09F164AA0BF88742EB61188B69F6D6259CA" group="com.google.accompanist"/>
169172
<trusted-key id="666A4692CE11B7B3F4EB7B3410066A9707090CF9" group="org.javassist" name="javassist" version="3.26.0-GA"/>
170173
<trusted-key id="694621A7227D8D5289699830ABE9F3126BB741C1" group="^com[.]google($|([.].*))" regex="true"/>

0 commit comments

Comments
 (0)