Delete cached icons after restore is done

This commit is contained in:
Torsten Grote 2024-05-31 12:22:17 -03:00
parent ebf68cfe73
commit 66f3852edf
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 12 additions and 0 deletions

View file

@ -66,7 +66,9 @@ import com.stevesoltys.seedvault.ui.systemData
import com.stevesoltys.seedvault.worker.IconManager import com.stevesoltys.seedvault.worker.IconManager
import com.stevesoltys.seedvault.worker.NUM_PACKAGES_PER_TRANSACTION import com.stevesoltys.seedvault.worker.NUM_PACKAGES_PER_TRANSACTION
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.calyxos.backup.storage.api.SnapshotItem import org.calyxos.backup.storage.api.SnapshotItem
import org.calyxos.backup.storage.api.StorageBackup import org.calyxos.backup.storage.api.StorageBackup
@ -328,6 +330,8 @@ internal class RestoreViewModel(
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(ioDispatcher) { iconManager.removeIcons() }
closeSession() closeSession()
} }

View file

@ -10,6 +10,7 @@ import android.graphics.Bitmap.CompressFormat.WEBP_LOSSY
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.Log import android.util.Log
import androidx.annotation.WorkerThread
import androidx.appcompat.content.res.AppCompatResources.getDrawable import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import androidx.core.graphics.drawable.toDrawable import androidx.core.graphics.drawable.toDrawable
@ -134,6 +135,13 @@ internal class IconManager(
} }
} }
@WorkerThread
fun removeIcons() {
val folder = File(context.cacheDir, CACHE_FOLDER)
val result = folder.deleteRecursively()
Log.e(TAG, "Could delete icons: $result")
}
private fun getAD(version: Byte, token: Long) = ByteBuffer.allocate(2 + 8) private fun getAD(version: Byte, token: Long) = ByteBuffer.allocate(2 + 8)
.put(version) .put(version)
.put(TYPE_ICONS) .put(TYPE_ICONS)