fix: Move temporary files outside of the cache directory (#2122)

This commit is contained in:
kitadai31 2024-08-13 01:23:31 +09:00 committed by GitHub
parent 936a9efd0b
commit e869db0555
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 22 deletions

View file

@ -1,10 +1,11 @@
package app.revanced.manager.data.platform
import android.Manifest
import android.app.Application
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Environment
import android.Manifest
import android.content.pm.PackageManager
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import app.revanced.manager.util.RequestManageStorageContract
@ -16,7 +17,7 @@ class Filesystem(private val app: Application) {
* A directory that gets cleared when the app restarts.
* Do not store paths to this directory in a parcel.
*/
val tempDir = app.cacheDir.resolve("ephemeral").apply {
val tempDir = app.getDir("ephemeral", Context.MODE_PRIVATE).apply {
deleteRecursively()
mkdirs()
}

View file

@ -193,6 +193,9 @@ class PatcherWorker(
Result.failure()
} finally {
patchedApk.delete()
if (args.input is SelectedApp.Local && args.input.temporary) {
args.input.file.delete()
}
}
}

View file

@ -25,7 +25,7 @@ class AppSelectorViewModel(
private val pm: PM,
private val patchBundleRepository: PatchBundleRepository
) : ViewModel() {
private val inputFile = File(app.cacheDir, "input.apk").also {
private val inputFile = File(app.filesDir, "input.apk").also {
it.delete()
}
val appList = pm.appList

View file

@ -48,7 +48,6 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.time.withTimeout
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.io.File
@ -189,26 +188,14 @@ class PatcherViewModel(
app.unregisterReceiver(installBroadcastReceiver)
workManager.cancelWorkById(patcherWorkerId)
when (val selectedApp = input.selectedApp) {
is SelectedApp.Local -> {
if (selectedApp.temporary) selectedApp.file.delete()
}
is SelectedApp.Installed -> {
GlobalScope.launch(Dispatchers.Main) {
uiSafe(app, R.string.failed_to_mount, "Failed to mount") {
installedApp?.let {
if (it.installType == InstallType.ROOT) {
withTimeout(Duration.ofMinutes(1L)) {
rootInstaller.mount(packageName)
}
}
}
if (input.selectedApp is SelectedApp.Installed && installedApp?.installType == InstallType.ROOT) {
GlobalScope.launch(Dispatchers.Main) {
uiSafe(app, R.string.failed_to_mount, "Failed to mount") {
withTimeout(Duration.ofMinutes(1L)) {
rootInstaller.mount(packageName)
}
}
}
else -> Unit
}
tempDir.deleteRecursively()