PathUtil: Switch to File instead of Path class
Path is only available since Android 8.0+ and it makes no sense to add a dependency upon desugaring lib for it. Switch to File class instead which is available on all Android versions Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import com.aurora.Constants
|
||||
import com.aurora.store.data.installer.AppInstaller
|
||||
import com.aurora.store.util.PathUtil
|
||||
import java.io.File
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
class InstallActivity : AppCompatActivity() {
|
||||
|
||||
@@ -22,8 +21,7 @@ class InstallActivity : AppCompatActivity() {
|
||||
val version = intent.extras?.getInt(Constants.STRING_VERSION)
|
||||
if (packageName.isNotBlank() && version != null) {
|
||||
try {
|
||||
val downloadDir =
|
||||
File(PathUtil.getAppDownloadDir(this, packageName, version).pathString)
|
||||
val downloadDir = File(PathUtil.getAppDownloadDir(this, packageName, version).path)
|
||||
AppInstaller.getInstance(this).getPreferredInstaller()
|
||||
.install(
|
||||
packageName,
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.aurora.store.util.PathUtil
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.io.File
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
@AndroidEntryPoint
|
||||
class InstallReceiver : BroadcastReceiver() {
|
||||
@@ -58,13 +57,7 @@ class InstallReceiver : BroadcastReceiver() {
|
||||
if (packageName.isNotBlank() && version != null) {
|
||||
try {
|
||||
val downloadDir =
|
||||
File(
|
||||
PathUtil.getAppDownloadDir(
|
||||
context,
|
||||
packageName,
|
||||
version
|
||||
).pathString
|
||||
)
|
||||
File(PathUtil.getAppDownloadDir(context, packageName, version).path)
|
||||
AppInstaller.getInstance(context).getPreferredInstaller()
|
||||
.install(
|
||||
packageName,
|
||||
|
||||
@@ -36,8 +36,6 @@ import java.io.File
|
||||
import java.net.URL
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.deleteRecursively
|
||||
import kotlin.properties.Delegates
|
||||
import com.aurora.gplayapi.data.models.File as GPlayFile
|
||||
|
||||
@@ -94,10 +92,9 @@ class DownloadWorker @AssistedInject constructor(
|
||||
// Download and verify all files exists
|
||||
totalBytes = files.sumOf { it.size }
|
||||
|
||||
PathUtil.getAppDownloadDir(appContext, download.packageName, download.versionCode)
|
||||
.createDirectories()
|
||||
PathUtil.getAppDownloadDir(appContext, download.packageName, download.versionCode).mkdirs()
|
||||
if (files.any { it.type == GPlayFile.FileType.OBB || it.type == GPlayFile.FileType.PATCH }) {
|
||||
PathUtil.getObbDownloadDir(download.packageName).createDirectories()
|
||||
PathUtil.getObbDownloadDir(download.packageName).mkdirs()
|
||||
}
|
||||
|
||||
val requestList = getDownloadRequest(files)
|
||||
|
||||
@@ -23,8 +23,6 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.deleteRecursively
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
class DownloadWorkerUtil @Inject constructor(
|
||||
@@ -87,7 +85,6 @@ class DownloadWorkerUtil @Inject constructor(
|
||||
?.let { downloadDao.update(it.copy(status = DownloadStatus.CANCELLED)) }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
suspend fun clearDownload(packageName: String, versionCode: Int) {
|
||||
Log.i(TAG, "Clearing downloads for $packageName ($versionCode)")
|
||||
downloadDao.delete(packageName)
|
||||
|
||||
@@ -22,11 +22,9 @@ package com.aurora.store.util
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import com.aurora.extensions.isRAndAbove
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.File
|
||||
import java.nio.file.Path
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
import kotlin.io.path.Path
|
||||
import com.aurora.gplayapi.data.models.File as GPlayFile
|
||||
|
||||
fun Context.getInternalBaseDirectory(): String {
|
||||
return (getExternalFilesDir(null) ?: filesDir).path
|
||||
@@ -54,15 +52,15 @@ object PathUtil {
|
||||
return getPackageDirectory(context, packageName) + "/$versionCode"
|
||||
}
|
||||
|
||||
fun getAppDownloadDir(context: Context, packageName: String, versionCode: Int): Path {
|
||||
return Path(getPackageDirectory(context, packageName), versionCode.toString())
|
||||
fun getAppDownloadDir(context: Context, packageName: String, versionCode: Int): File {
|
||||
return File(getPackageDirectory(context, packageName), versionCode.toString())
|
||||
}
|
||||
|
||||
fun getApkDownloadFile(
|
||||
context: Context,
|
||||
packageName: String,
|
||||
versionCode: Int,
|
||||
file: File
|
||||
file: GPlayFile
|
||||
): String {
|
||||
return getVersionDirectory(context, packageName, versionCode) + "/${file.name}"
|
||||
}
|
||||
@@ -94,21 +92,20 @@ object PathUtil {
|
||||
.toString() + "/Android/obb/" + packageName
|
||||
}
|
||||
|
||||
fun getObbDownloadDir(packageName: String): Path {
|
||||
return Path(
|
||||
fun getObbDownloadDir(packageName: String): File {
|
||||
return File(
|
||||
Environment.getExternalStorageDirectory().absolutePath,
|
||||
"/Android/obb/",
|
||||
packageName
|
||||
"/Android/obb/$packageName"
|
||||
)
|
||||
}
|
||||
|
||||
fun getObbDownloadFile(packageName: String, file: File): String {
|
||||
fun getObbDownloadFile(packageName: String, file: GPlayFile): String {
|
||||
val obbDir = getObbDownloadPath(packageName)
|
||||
return "$obbDir/${file.name}"
|
||||
}
|
||||
|
||||
fun needsStorageManagerPerm(fileList: List<File>): Boolean {
|
||||
return fileList.any { it.type == File.FileType.OBB || it.type == File.FileType.PATCH }
|
||||
fun needsStorageManagerPerm(fileList: List<GPlayFile>): Boolean {
|
||||
return fileList.any { it.type == GPlayFile.FileType.OBB || it.type == GPlayFile.FileType.PATCH }
|
||||
}
|
||||
|
||||
fun getSpoofDirectory(context: Context): String {
|
||||
|
||||
@@ -47,7 +47,6 @@ import com.aurora.store.util.CommonUtil
|
||||
import com.aurora.store.util.PathUtil
|
||||
import com.aurora.store.view.epoxy.views.BaseView
|
||||
import java.io.File
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
@ModelView(
|
||||
autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT,
|
||||
@@ -146,7 +145,7 @@ class AppUpdateView : RelativeLayout {
|
||||
context,
|
||||
download.packageName,
|
||||
download.versionCode
|
||||
).pathString
|
||||
).path
|
||||
).listFiles()
|
||||
if (files.isNullOrEmpty()) B.btnAction.updateState(DownloadStatus.UNAVAILABLE)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ import java.io.File
|
||||
import java.util.Locale
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
@@ -445,7 +444,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
requireContext(),
|
||||
app.packageName,
|
||||
app.versionCode
|
||||
).pathString
|
||||
).path
|
||||
).listFiles() ?: return
|
||||
|
||||
val apkFiles = files.filter { it.path.endsWith(".apk") }
|
||||
@@ -574,7 +573,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
requireContext(),
|
||||
app.packageName,
|
||||
app.versionCode
|
||||
).pathString
|
||||
).path
|
||||
).listFiles()
|
||||
|
||||
if (files?.isNotEmpty() == true) install() else purchase()
|
||||
|
||||
@@ -49,7 +49,6 @@ import java.io.File
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
@AndroidEntryPoint
|
||||
class UpdatesFragment : BaseFragment(R.layout.fragment_updates) {
|
||||
@@ -166,7 +165,7 @@ class UpdatesFragment : BaseFragment(R.layout.fragment_updates) {
|
||||
requireContext(),
|
||||
app.packageName,
|
||||
app.versionCode
|
||||
).pathString
|
||||
).path
|
||||
).listFiles()
|
||||
|
||||
// Downloaded files are missing, trigger re-download
|
||||
|
||||
Reference in New Issue
Block a user