Skip to content

Commit

Permalink
fix: Move temporary files outside of the cache directory (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitadai31 authored Aug 12, 2024
1 parent 936a9ef commit e869db0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class PatcherWorker(
Result.failure()
} finally {
patchedApk.delete()
if (args.input is SelectedApp.Local && args.input.temporary) {
args.input.file.delete()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e869db0

Please sign in to comment.