diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 32b69baa1f67c4dc7fb08d5229a1c552b1f3d5d5..b9335574405d1a2574844ecc88007a3968168f25 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ - + + + + @@ -57,7 +64,7 @@ - + @@ -65,10 +72,9 @@ - + tools:node="remove" /> - + \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/AppProgressViewModel.kt b/app/src/main/java/foundation/e/apps/AppProgressViewModel.kt index 192954e8e17c913bb20c9faa6bcebcee32a4060d..42b72c5f00a3c52e44eb91e574817db1ecafd834 100644 --- a/app/src/main/java/foundation/e/apps/AppProgressViewModel.kt +++ b/app/src/main/java/foundation/e/apps/AppProgressViewModel.kt @@ -22,10 +22,10 @@ class AppProgressViewModel @Inject constructor( ): Pair { fusedApp?.let { app -> val appDownload = fusedManagerRepository.getDownloadList() - .singleOrNull { it.id.contentEquals(app._id) && it.package_name.contentEquals(app.package_name) } + .singleOrNull { it.id.contentEquals(app._id) && it.packageName.contentEquals(app.package_name) } ?: return Pair(1, 0) - if (!appDownload.id.contentEquals(app._id) || !appDownload.package_name.contentEquals(app.package_name)) { + if (!appDownload.id.contentEquals(app._id) || !appDownload.packageName.contentEquals(app.package_name)) { return@let } val downloadingMap = progress.totalSizeBytes.filter { item -> diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index cc8e20ef7e44d67619c7ef574cd9c9106cff5e1f..f884e11ae6c3814ed6c3f02f7c496062ad094d45 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -172,7 +172,7 @@ class MainActivity : AppCompatActivity() { viewModel.purchaseAppLiveData.observe(this) { val action = - AppPurchaseFragmentDirections.actionGlobalAppPurchaseFragment(it.package_name) + AppPurchaseFragmentDirections.actionGlobalAppPurchaseFragment(it.packageName) findNavController(R.id.fragment).navigate(action) } diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index cb4561cc600923998a0cb733446ebbdbc981c02b..98820cb767e90e5ca06d79aa8ea9af76fb14a1bf 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -146,16 +146,13 @@ class MainActivityViewModel @Inject constructor( val fusedDownload: FusedDownload try { val appIcon = imageView?.let { getImageBase64(it) } ?: "" - val downloadList: List - downloadList = getAppDownloadLink(app).toMutableList() - fusedDownload = FusedDownload( app._id, app.origin, app.status, app.name, app.package_name, - downloadList, + mutableListOf(), mutableMapOf(), app.status, app.type, @@ -164,6 +161,7 @@ class MainActivityViewModel @Inject constructor( app.offer_type, app.isFree ) + updateFusedDownloadWithAppDownloadLink(app, fusedDownload) } catch (e: Exception) { if (e is ApiException.AppNotPurchased) { handleAppNotPurchased(imageView, app) @@ -215,14 +213,11 @@ class MainActivityViewModel @Inject constructor( authData.value?.let { if (!it.isAnonymous) { try { - fusedDownload.downloadURLList = fusedAPIRepository.getDownloadLink( - fusedDownload.id, - fusedDownload.package_name, - fusedDownload.versionCode, - fusedDownload.offerType, + fusedAPIRepository.updateFusedDownloadWithDownloadingInfo( it, - Origin.GPLAY - ).toMutableList() + Origin.GPLAY, + fusedDownload + ) } catch (e: Exception) { Log.e(TAG, e.stackTraceToString()) _errorMessage.value = e @@ -248,25 +243,23 @@ class MainActivityViewModel @Inject constructor( } } - private suspend fun getAppDownloadLink(app: FusedApp): List { + private suspend fun updateFusedDownloadWithAppDownloadLink( + app: FusedApp, + fusedDownload: FusedDownload + ) { val downloadList = mutableListOf() authData.value?.let { if (app.type == Type.PWA) { downloadList.add(app.url) + fusedDownload.downloadURLList = downloadList } else { - downloadList.addAll( - fusedAPIRepository.getDownloadLink( - app._id, - app.package_name, - app.latest_version_code, - app.offer_type, - it, - app.origin - ) + fusedAPIRepository.updateFusedDownloadWithDownloadingInfo( + it, + app.origin, + fusedDownload ) } } - return downloadList } private fun getImageBase64(imageView: ImageView): String { diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 409c03fd4dc024f2babd423526fbb54f8127e1bc..7e850ad7321000b06a3bcdd500d19fbdc214574d 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -25,7 +25,6 @@ import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.Artwork import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.data.models.Category -import com.aurora.gplayapi.data.models.File import com.aurora.gplayapi.helpers.TopChartsHelper import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.R @@ -40,6 +39,7 @@ import foundation.e.apps.api.fused.data.FusedHome import foundation.e.apps.api.fused.data.Ratings import foundation.e.apps.api.fused.utils.CategoryUtils import foundation.e.apps.api.gplay.GPlayAPIRepository +import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status @@ -152,38 +152,31 @@ class FusedAPIImpl @Inject constructor( return gPlayAPIRepository.validateAuthData(authData) } - suspend fun getDownloadLink( - id: String, - packageName: String, - versionCode: Int, - offerType: Int, + suspend fun updateFusedDownloadWithDownloadingInfo( authData: AuthData, - origin: Origin - ): List { + origin: Origin, + fusedDownload: FusedDownload + ) { val list = mutableListOf() when (origin) { Origin.CLEANAPK -> { - val downloadInfo = cleanAPKRepository.getDownloadInfo(id).body() + val downloadInfo = cleanAPKRepository.getDownloadInfo(fusedDownload.id).body() downloadInfo?.download_data?.download_link?.let { list.add(it) } } Origin.GPLAY -> { val downloadList = gPlayAPIRepository.getDownloadInfo( - packageName, - versionCode, - offerType, + fusedDownload.packageName, + fusedDownload.versionCode, + fusedDownload.offerType, authData ) - // TODO: DEAL WITH MULTIPLE PACKAGES - downloadList.forEach { - if (it.type == File.FileType.BASE || it.type == File.FileType.SPLIT) { - list.add(it.url) - } - } + fusedDownload.files = downloadList + list.addAll(downloadList.map { it.url }) } Origin.GITLAB -> { } } - return list + fusedDownload.downloadURLList = list } suspend fun listApps(category: String, browseUrl: String, authData: AuthData): List? { diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIRepository.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIRepository.kt index bc01e12300080d28122460781928a9c8839a098c..f194ea88d22373194d0ec1611d5f0f1ac416da7d 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIRepository.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIRepository.kt @@ -24,6 +24,7 @@ import com.aurora.gplayapi.data.models.Category import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.api.fused.data.FusedCategory import foundation.e.apps.api.fused.data.FusedHome +import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.utils.enums.Origin import javax.inject.Inject import javax.inject.Singleton @@ -57,21 +58,15 @@ class FusedAPIRepository @Inject constructor( return fusedAPIImpl.getApplicationDetails(id, packageName, authData, origin) } - suspend fun getDownloadLink( - id: String, - packageName: String, - versionCode: Int, - offerType: Int, + suspend fun updateFusedDownloadWithDownloadingInfo( authData: AuthData, - origin: Origin - ): List { - return fusedAPIImpl.getDownloadLink( - id, - packageName, - versionCode, - offerType, + origin: Origin, + fusedDownload: FusedDownload + ) { + fusedAPIImpl.updateFusedDownloadWithDownloadingInfo( authData, - origin + origin, + fusedDownload ) } diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index a08402cc64054fc053071587e033100b9d4a8562..cdeb6da9bc98ab76106aa76857451d4071215d40 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -127,7 +127,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> list.forEach { - if (it.origin == args.origin && (it.package_name == args.packageName || it.id == args.id)) { + if (it.origin == args.origin && (it.packageName == args.packageName || it.id == args.id)) { applicationViewModel.appStatus.value = it.status } } diff --git a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt index f3d8ed137df8d71944f9377a845a327dcc68a5f2..4f2132faebae2cc5b783b9636483c825831329ec 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -86,7 +86,7 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu if (!categoryList.isNullOrEmpty()) { list.forEach { categoryList.find { app -> - app.origin == it.origin && (app.package_name == it.package_name || app._id == it.id) + app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } viewModel.appListLiveData.value = categoryList diff --git a/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt b/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt index 1595866c3847fec9c8699243003d4d018e883b42..5d32668340ae803712a921da458565bdbaa4c75a 100644 --- a/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt @@ -95,7 +95,7 @@ class HomeParentRVAdapter( private fun findInstallingApp(fusedHome: FusedHome, fusedDownload: FusedDownload): FusedApp? { return fusedHome.list.find { app -> - app.origin == fusedDownload.origin && (app.package_name == fusedDownload.package_name || app._id == fusedDownload.id) + app.origin == fusedDownload.origin && (app.package_name == fusedDownload.packageName || app._id == fusedDownload.id) } } diff --git a/app/src/main/java/foundation/e/apps/manager/database/FusedConverter.kt b/app/src/main/java/foundation/e/apps/manager/database/FusedConverter.kt index 85c90d11e3ba9ab1d052a9df02f5093b3c27269f..adc654cc537236d47666b6807e83667aa775b069 100644 --- a/app/src/main/java/foundation/e/apps/manager/database/FusedConverter.kt +++ b/app/src/main/java/foundation/e/apps/manager/database/FusedConverter.kt @@ -1,6 +1,7 @@ package foundation.e.apps.manager.database import androidx.room.TypeConverter +import com.aurora.gplayapi.data.models.File import com.google.gson.Gson import com.google.gson.reflect.TypeToken @@ -19,4 +20,11 @@ class FusedConverter { @TypeConverter fun jsonLongToList(value: String): MutableMap = Gson().fromJson(value, object : TypeToken>() {}.type) + + @TypeConverter + fun filesToJsonString(value: List): String = Gson().toJson(value) + + @TypeConverter + fun jsonStringToFiles(value: String) = + Gson().fromJson(value, Array::class.java).toMutableList() } diff --git a/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownload.kt b/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownload.kt index 7b9c2be82175bcd6a49c71bb308cda2b495417b6..097539429cb256c61faa811f5684441982104e77 100644 --- a/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownload.kt +++ b/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownload.kt @@ -2,6 +2,7 @@ package foundation.e.apps.manager.database.fusedDownload import androidx.room.Entity import androidx.room.PrimaryKey +import com.aurora.gplayapi.data.models.File import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type @@ -12,7 +13,7 @@ data class FusedDownload( val origin: Origin = Origin.CLEANAPK, var status: Status = Status.UNAVAILABLE, val name: String = String(), - val package_name: String = String(), + val packageName: String = String(), var downloadURLList: MutableList = mutableListOf(), var downloadIdMap: MutableMap = mutableMapOf(), val orgStatus: Status = Status.UNAVAILABLE, @@ -20,5 +21,6 @@ data class FusedDownload( val iconByteArray: String = String(), val versionCode: Int = 1, val offerType: Int = -1, - val isFree: Boolean = true + val isFree: Boolean = true, + var files: List = mutableListOf() ) diff --git a/app/src/main/java/foundation/e/apps/manager/download/DownloadManagerUtils.kt b/app/src/main/java/foundation/e/apps/manager/download/DownloadManagerUtils.kt index 6581743a16db3cdfcb3efd1709329151501bc462..a7b5250f1ad27d2db854ede8049cb9b2c0d91f52 100644 --- a/app/src/main/java/foundation/e/apps/manager/download/DownloadManagerUtils.kt +++ b/app/src/main/java/foundation/e/apps/manager/download/DownloadManagerUtils.kt @@ -18,7 +18,9 @@ package foundation.e.apps.manager.download +import android.content.Context import android.util.Log +import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.utils.enums.Status import kotlinx.coroutines.DelicateCoroutinesApi @@ -32,7 +34,8 @@ import javax.inject.Singleton @Singleton class DownloadManagerUtils @Inject constructor( - private val fusedManagerRepository: FusedManagerRepository + private val fusedManagerRepository: FusedManagerRepository, + @ApplicationContext private val context: Context ) { private val TAG = DownloadManagerUtils::class.java.simpleName private val mutex = Mutex() @@ -59,6 +62,7 @@ class DownloadManagerUtils @Inject constructor( "===> updateDownloadStatus: ${fusedDownload.name}: $downloadId: $downloaded/${fusedDownload.downloadIdMap.size} " ) if (downloaded == fusedDownload.downloadIdMap.size) { + fusedManagerRepository.moveOBBFileToOBBDirectory(fusedDownload) fusedManagerRepository.updateDownloadStatus(fusedDownload, Status.INSTALLING) } } diff --git a/app/src/main/java/foundation/e/apps/manager/fused/FileManager.kt b/app/src/main/java/foundation/e/apps/manager/fused/FileManager.kt new file mode 100644 index 0000000000000000000000000000000000000000..3aa7b4c59c26e78dd24314237338f1a1b7db1213 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/manager/fused/FileManager.kt @@ -0,0 +1,46 @@ +package foundation.e.apps.manager.fused + +import android.util.Log +import java.io.File +import java.io.FileInputStream +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.InputStream +import java.io.OutputStream + +object FileManager { + private const val TAG = "FileManager" + + fun moveFile(inputPath: String, inputFile: String, outputPath: String) { + var inputStream: InputStream? = null + var outputStream: OutputStream? = null + try { + + // create output directory if it doesn't exist + val dir = File(outputPath) + if (!dir.exists()) { + dir.mkdirs() + } + inputStream = FileInputStream(inputPath + inputFile) + outputStream = FileOutputStream(outputPath + inputFile) + val buffer = ByteArray(1024) + var read: Int + while (inputStream.read(buffer).also { read = it } != -1) { + outputStream.write(buffer, 0, read) + } + // write the output file + outputStream.flush() + // delete the original file + File(inputPath + inputFile).delete() + } catch (e: FileNotFoundException) { + Log.e(TAG, e.stackTraceToString()) + } catch (e: Exception) { + Log.e(TAG, e.stackTraceToString()) + } finally { + inputStream?.close() + inputStream = null + outputStream?.close() + outputStream = null + } + } +} diff --git a/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt b/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt index 42081827b9dd37c4f58fd930aa78453865fbdba6..c593a1a244b21d95786cb2c7157b295948a92818 100644 --- a/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt @@ -3,11 +3,14 @@ package foundation.e.apps.manager.fused import android.app.DownloadManager import android.app.NotificationChannel import android.app.NotificationManager +import android.content.Context import android.net.Uri import android.os.Build +import android.os.Environment import android.util.Log import androidx.annotation.RequiresApi import androidx.lifecycle.LiveData +import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.manager.database.DatabaseRepository import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.download.DownloadManagerBR @@ -21,6 +24,7 @@ import kotlinx.coroutines.delay import java.io.File import javax.inject.Inject import javax.inject.Named +import com.aurora.gplayapi.data.models.File as AuroraFile class FusedManagerImpl @Inject constructor( @Named("cacheDir") private val cacheDir: String, @@ -30,7 +34,8 @@ class FusedManagerImpl @Inject constructor( private val pwaManagerModule: PWAManagerModule, private val pkgManagerModule: PkgManagerModule, @Named("download") private val downloadNotificationChannel: NotificationChannel, - @Named("update") private val updateNotificationChannel: NotificationChannel + @Named("update") private val updateNotificationChannel: NotificationChannel, + @ApplicationContext private val context: Context ) { private val TAG = FusedManagerImpl::class.java.simpleName @@ -57,7 +62,7 @@ class FusedManagerImpl @Inject constructor( } suspend fun clearInstallationIssue(fusedDownload: FusedDownload) { - flushOldDownload(fusedDownload.package_name) + flushOldDownload(fusedDownload.packageName) databaseRepository.deleteDownload(fusedDownload) } @@ -68,7 +73,7 @@ class FusedManagerImpl @Inject constructor( databaseRepository.updateDownload(fusedDownload) DownloadManagerBR.downloadedList.clear() delay(100) - flushOldDownload(fusedDownload.package_name) + flushOldDownload(fusedDownload.packageName) databaseRepository.deleteDownload(fusedDownload) } else if (status == Status.INSTALLING) { Log.d(TAG, "updateDownloadStatus: Downloaded ===> ${fusedDownload.name} INSTALLING") @@ -92,12 +97,12 @@ class FusedManagerImpl @Inject constructor( val list = mutableListOf() when (fusedDownload.type) { Type.NATIVE -> { - val parentPathFile = File("$cacheDir/${fusedDownload.package_name}") + val parentPathFile = File("$cacheDir/${fusedDownload.packageName}") parentPathFile.listFiles()?.let { list.addAll(it) } list.sort() if (list.size != 0) { Log.d(TAG, "installApp: STARTED ${fusedDownload.name} ${list.size}") - pkgManagerModule.installApplication(list, fusedDownload.package_name) + pkgManagerModule.installApplication(list, fusedDownload.packageName) Log.d(TAG, "installApp: ENDED ${fusedDownload.name} ${list.size}") } } @@ -124,7 +129,7 @@ class FusedManagerImpl @Inject constructor( delay(100) databaseRepository.deleteDownload(fusedDownload) - flushOldDownload(fusedDownload.package_name) + flushOldDownload(fusedDownload.packageName) } else { Log.d(TAG, "Unable to cancel download!") } @@ -139,7 +144,7 @@ class FusedManagerImpl @Inject constructor( fusedDownload = it } } else if (packageName.isNotBlank()) { - if (it.package_name == packageName) { + if (it.packageName == packageName) { fusedDownload = it } } @@ -155,10 +160,10 @@ class FusedManagerImpl @Inject constructor( private suspend fun downloadNativeApp(fusedDownload: FusedDownload) { var count = 0 - val parentPath = "$cacheDir/${fusedDownload.package_name}" + var parentPath = "$cacheDir/${fusedDownload.packageName}" // Clean old downloads and re-create download dir - flushOldDownload(fusedDownload.package_name) + flushOldDownload(fusedDownload.packageName) File(parentPath).mkdirs() fusedDownload.status = Status.DOWNLOADING @@ -168,8 +173,12 @@ class FusedManagerImpl @Inject constructor( Log.d(TAG, "downloadNativeApp: ${fusedDownload.name} ${fusedDownload.downloadURLList.size}") fusedDownload.downloadURLList.forEach { count += 1 - val packagePath = File(parentPath, "${fusedDownload.package_name}_$count.apk") - + val packagePath: File = if (fusedDownload.files.isNotEmpty()) { + getGplayInstallationPackagePath(fusedDownload, it, parentPath, count) + } else { + File(parentPath, "${fusedDownload.packageName}_$count.apk") + } + Log.d(TAG, "downloadNativeApp: destination path: $packagePath") val request = DownloadManager.Request(Uri.parse(it)) .setTitle(if (count == 1) fusedDownload.name else "Additional file for ${fusedDownload.name}") .setDestinationUri(Uri.fromFile(packagePath)) @@ -180,8 +189,49 @@ class FusedManagerImpl @Inject constructor( databaseRepository.updateDownload(fusedDownload) } + private fun getGplayInstallationPackagePath( + fusedDownload: FusedDownload, + it: String, + parentPath: String, + count: Int + ): File { + val downloadingFile = fusedDownload.files[fusedDownload.downloadURLList.indexOf(it)] + return if (downloadingFile.type == AuroraFile.FileType.BASE || downloadingFile.type == AuroraFile.FileType.SPLIT) { + File(parentPath, "${fusedDownload.packageName}_$count.apk") + } else { + createObbFileForDownload(fusedDownload, it) + } + } + + private fun createObbFileForDownload( + fusedDownload: FusedDownload, + url: String + ): File { + val parentPath = + context.getExternalFilesDir(null)?.absolutePath + "/Android/obb/" + fusedDownload.packageName + File(parentPath).mkdirs() + val obbFile = fusedDownload.files[fusedDownload.downloadURLList.indexOf(url)] + return File(parentPath, obbFile.name) + } + + fun moveOBBFilesToOBBDirectory(fusedDownload: FusedDownload) { + fusedDownload.files.forEach { + val parentPath = + context.getExternalFilesDir(null)?.absolutePath + "/Android/obb/" + fusedDownload.packageName + Log.d(TAG, "updateDownloadStatus: source path: $parentPath filename: ${it.name}") + val file = File(parentPath, it.name) + if (file.exists()) { + val destinationDirectory = Environment.getExternalStorageDirectory() + .toString() + "/Android/obb/" + fusedDownload.packageName + Log.d(TAG, "updateDownloadStatus: destination path: $destinationDirectory") + File(destinationDirectory).mkdirs() + FileManager.moveFile("$parentPath/", it.name, "$destinationDirectory/") + } + } + } + suspend fun installationIssue(fusedDownload: FusedDownload) { - flushOldDownload(fusedDownload.package_name) + flushOldDownload(fusedDownload.packageName) fusedDownload.status = Status.INSTALLATION_ISSUE databaseRepository.updateDownload(fusedDownload) } diff --git a/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerRepository.kt b/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerRepository.kt index ab138ef8a24adf4f09347aae1a888331dbbdad83..adcfbd44eab9498a3cf5719dda75d4155446d26e 100644 --- a/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerRepository.kt +++ b/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerRepository.kt @@ -24,6 +24,10 @@ class FusedManagerRepository @Inject constructor( return fusedManagerImpl.downloadApp(fusedDownload) } + fun moveOBBFileToOBBDirectory(fusedDownload: FusedDownload) { + return fusedManagerImpl.moveOBBFilesToOBBDirectory(fusedDownload) + } + suspend fun addDownload(fusedDownload: FusedDownload) { return fusedManagerImpl.addDownload(fusedDownload) } diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt index f09f19038634afd9dfcc24d38e442144650303f7..f0722088943d99c250faee6d9fd493fdd8e1ea36 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt @@ -40,11 +40,12 @@ class InstallAppWorker @AssistedInject constructor( } override suspend fun doWork(): Result { + var fusedDownload: FusedDownload? = null try { val fusedDownloadString = params.inputData.getString(INPUT_DATA_FUSED_DOWNLOAD) ?: "" Log.d(TAG, "Fused download name $fusedDownloadString") - val fusedDownload = databaseRepository.getDownloadById(fusedDownloadString) + fusedDownload = databaseRepository.getDownloadById(fusedDownloadString) fusedDownload?.let { if (fusedDownload.status != Status.AWAITING) { return@let @@ -55,6 +56,9 @@ class InstallAppWorker @AssistedInject constructor( return Result.success() } catch (e: Exception) { Log.e(TAG, "doWork: Failed: ${e.stackTraceToString()}") + fusedDownload?.let { + fusedManagerRepository.installationIssue(it) + } return Result.failure() } } diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 589cd6c3717f489b5c8092116e75cfe3bc34343a..beec6154569fbb6859e4f313a5e49b503b6bd9a1 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -165,7 +165,7 @@ class SearchFragment : if (!searchResult.isNullOrEmpty()) { list.forEach { searchResult.find { app -> - app.origin == it.origin && (app.package_name == it.package_name || app._id == it.id) + app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } searchViewModel.searchResult.value = searchResult diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt index f9b2962e9b41728942fe36a2336a564e83ec9690..a8549a8fe52a2759ecaee62511f86b3bc21c8ce5 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -113,7 +113,7 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { if (!updatesList.isNullOrEmpty()) { list.forEach { updatesList.find { app -> - app.origin == it.origin && (app.package_name == it.package_name || app._id == it.id) + app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } updatesViewModel.updatesList.value = updatesList diff --git a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt index 42cece105e1c432752f4c3c00bd55b13cb4383bf..5f410400213225a9d9505119dab355ac302cd95f 100644 --- a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt @@ -119,7 +119,6 @@ class UpdatesWorker @AssistedInject constructor( fusedApp.offer_type ) } - val downloadList = getAppDownloadLink(fusedApp, authData).toMutableList() val iconBase64 = getIconImageToBase64(fusedApp) val fusedDownload = FusedDownload( @@ -128,7 +127,7 @@ class UpdatesWorker @AssistedInject constructor( fusedApp.status, fusedApp.name, fusedApp.package_name, - downloadList, + mutableListOf(), mutableMapOf(), fusedApp.status, fusedApp.type, @@ -137,6 +136,9 @@ class UpdatesWorker @AssistedInject constructor( fusedApp.offer_type, fusedApp.isFree ) + + updateFusedDownloadWithAppDownloadLink(fusedApp, authData, fusedDownload) + fusedManagerRepository.addDownload(fusedDownload) fusedManagerRepository.updateAwaiting(fusedDownload) Log.d( @@ -171,23 +173,22 @@ class UpdatesWorker @AssistedInject constructor( ) } - private suspend fun getAppDownloadLink(app: FusedApp, authData: AuthData): List { + private suspend fun updateFusedDownloadWithAppDownloadLink( + app: FusedApp, + authData: AuthData, + fusedDownload: FusedDownload + ) { val downloadList = mutableListOf() if (app.type == Type.PWA) { downloadList.add(app.url) + fusedDownload.downloadURLList = downloadList } else { - downloadList.addAll( - fusedAPIRepository.getDownloadLink( - app._id, - app.package_name, - app.latest_version_code, - app.offer_type, - authData, - app.origin - ) + fusedAPIRepository.updateFusedDownloadWithDownloadingInfo( + authData, + app.origin, + fusedDownload ) } - return downloadList } private fun getIconImageToBase64(fusedApp: FusedApp): String {