Skip to content

Commit

Permalink
Delete cached icons after restore is done
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed May 31, 2024
1 parent ebf68cf commit 4f28d0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ import com.stevesoltys.seedvault.ui.systemData
import com.stevesoltys.seedvault.worker.IconManager
import com.stevesoltys.seedvault.worker.NUM_PACKAGES_PER_TRANSACTION
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.calyxos.backup.storage.api.SnapshotItem
import org.calyxos.backup.storage.api.StorageBackup
Expand Down Expand Up @@ -328,6 +330,8 @@ internal class RestoreViewModel(

override fun onCleared() {
super.onCleared()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { iconManager.removeIcons() }
closeSession()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.graphics.Bitmap.CompressFormat.WEBP_LOSSY
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
import android.util.Log
import androidx.annotation.WorkerThread
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.core.graphics.drawable.toBitmap
import androidx.core.graphics.drawable.toDrawable
Expand Down Expand Up @@ -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)
.put(version)
.put(TYPE_ICONS)
Expand Down

0 comments on commit 4f28d0e

Please sign in to comment.