mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 01:39:22 +02:00
Increase encrypted app list size limit
This commit is contained in:
parent
71c0f3a06e
commit
caf3e905c1
2 changed files with 12 additions and 7 deletions
|
@ -21,6 +21,7 @@ import io.timelimit.android.crypto.CryptContainer
|
||||||
import io.timelimit.android.data.Database
|
import io.timelimit.android.data.Database
|
||||||
import io.timelimit.android.data.model.CryptContainerData
|
import io.timelimit.android.data.model.CryptContainerData
|
||||||
import io.timelimit.android.data.model.CryptContainerMetadata
|
import io.timelimit.android.data.model.CryptContainerMetadata
|
||||||
|
import io.timelimit.android.logic.ServerApiLevelInfo
|
||||||
import io.timelimit.android.proto.build
|
import io.timelimit.android.proto.build
|
||||||
import io.timelimit.android.proto.encodeDeflated
|
import io.timelimit.android.proto.encodeDeflated
|
||||||
import io.timelimit.android.sync.SyncUtil
|
import io.timelimit.android.sync.SyncUtil
|
||||||
|
@ -32,8 +33,6 @@ import io.timelimit.proto.applist.InstalledAppsProto
|
||||||
import io.timelimit.proto.applist.SavedAppsDifferenceProto
|
import io.timelimit.proto.applist.SavedAppsDifferenceProto
|
||||||
|
|
||||||
object CryptoAppListSync {
|
object CryptoAppListSync {
|
||||||
private const val SIZE_LIMIT_COMPRESSED = 1024 * 256
|
|
||||||
|
|
||||||
class TooLargeException(val size: Int): RuntimeException("app list is too big: $size")
|
class TooLargeException(val size: Int): RuntimeException("app list is too big: $size")
|
||||||
|
|
||||||
suspend fun sync(
|
suspend fun sync(
|
||||||
|
@ -41,7 +40,8 @@ object CryptoAppListSync {
|
||||||
database: Database,
|
database: Database,
|
||||||
installed: InstalledAppsProto,
|
installed: InstalledAppsProto,
|
||||||
syncUtil: SyncUtil,
|
syncUtil: SyncUtil,
|
||||||
disableLegacySync: Boolean
|
disableLegacySync: Boolean,
|
||||||
|
serverApiLevelInfo: ServerApiLevelInfo
|
||||||
) {
|
) {
|
||||||
fun dispatch(action: AppLogicAction) {
|
fun dispatch(action: AppLogicAction) {
|
||||||
if (deviceState.isConnectedMode) {
|
if (deviceState.isConnectedMode) {
|
||||||
|
@ -49,6 +49,10 @@ object CryptoAppListSync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val compressedDataSizeLimit =
|
||||||
|
if (serverApiLevelInfo.hasLevelOrIsOffline(5)) 1024 * 512
|
||||||
|
else 1024 * 256
|
||||||
|
|
||||||
val savedCrypt = Threads.database.executeAndWait {
|
val savedCrypt = Threads.database.executeAndWait {
|
||||||
InstalledAppsUtil.getEncryptedInstalledAppsFromDatabaseSync(database, deviceState.id)
|
InstalledAppsUtil.getEncryptedInstalledAppsFromDatabaseSync(database, deviceState.id)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +64,7 @@ object CryptoAppListSync {
|
||||||
val baseEncrypted = CryptContainer.encrypt(installed.encodeDeflated(), baseKey)
|
val baseEncrypted = CryptContainer.encrypt(installed.encodeDeflated(), baseKey)
|
||||||
val diffEncrypted = CryptContainer.encrypt(SavedAppsDifferenceProto.build(baseEncrypted, InstalledAppsDifferenceProto()).encodeDeflated(), diffKey)
|
val diffEncrypted = CryptContainer.encrypt(SavedAppsDifferenceProto.build(baseEncrypted, InstalledAppsDifferenceProto()).encodeDeflated(), diffKey)
|
||||||
|
|
||||||
if (baseEncrypted.size > SIZE_LIMIT_COMPRESSED) throw TooLargeException(baseEncrypted.size)
|
if (baseEncrypted.size > compressedDataSizeLimit) throw TooLargeException(baseEncrypted.size)
|
||||||
|
|
||||||
Threads.database.executeAndWait {
|
Threads.database.executeAndWait {
|
||||||
database.cryptContainer().removeDeviceCryptoMetadata(
|
database.cryptContainer().removeDeviceCryptoMetadata(
|
||||||
|
@ -133,7 +137,7 @@ object CryptoAppListSync {
|
||||||
diffCryptParams.params
|
diffCryptParams.params
|
||||||
)
|
)
|
||||||
|
|
||||||
if (baseEncrypted.size > SIZE_LIMIT_COMPRESSED) throw TooLargeException(baseEncrypted.size)
|
if (baseEncrypted.size > compressedDataSizeLimit) throw TooLargeException(baseEncrypted.size)
|
||||||
|
|
||||||
Threads.database.executeAndWait {
|
Threads.database.executeAndWait {
|
||||||
database.cryptContainer().updateMetadata(listOf(
|
database.cryptContainer().updateMetadata(listOf(
|
||||||
|
@ -166,7 +170,7 @@ object CryptoAppListSync {
|
||||||
diffCryptParams.params
|
diffCryptParams.params
|
||||||
)
|
)
|
||||||
|
|
||||||
if (diffEncrypted.size > SIZE_LIMIT_COMPRESSED) throw TooLargeException(diffEncrypted.size)
|
if (diffEncrypted.size > compressedDataSizeLimit) throw TooLargeException(diffEncrypted.size)
|
||||||
|
|
||||||
Threads.database.executeAndWait {
|
Threads.database.executeAndWait {
|
||||||
database.cryptContainer().updateMetadata(diffCryptParams.newMetadata)
|
database.cryptContainer().updateMetadata(diffCryptParams.newMetadata)
|
||||||
|
|
|
@ -137,7 +137,8 @@ class SyncInstalledAppsLogic(val appLogic: AppLogic) {
|
||||||
database = appLogic.database,
|
database = appLogic.database,
|
||||||
installed = installed,
|
installed = installed,
|
||||||
syncUtil = appLogic.syncUtil,
|
syncUtil = appLogic.syncUtil,
|
||||||
disableLegacySync = deviceState.disableLegacySync
|
disableLegacySync = deviceState.disableLegacySync,
|
||||||
|
serverApiLevelInfo = deviceState.serverApiLevel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue