Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a085f7a2 authored by Hasib Prince's avatar Hasib Prince
Browse files

Handled app install error: INSTALL_PARSE_FAILED_NOT_APK

parent abbe8ecb
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import foundation.e.apps.home.HomeFragmentDirections
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.User
import timber.log.Timber

class HomeChildRVAdapter(
    private var fusedAPIInterface: FusedAPIInterface?,
+5 −19
Original line number Diff line number Diff line
@@ -6,8 +6,6 @@ import foundation.e.apps.OpenForTesting
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.database.fusedDownload.FusedDownloadDAO
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import javax.inject.Inject
import javax.inject.Singleton

@@ -17,41 +15,29 @@ class DatabaseRepository @Inject constructor(
    private val fusedDownloadDAO: FusedDownloadDAO
) {

    private val mutex = Mutex()

    suspend fun addDownload(fusedDownload: FusedDownload) {
        mutex.withLock {
        return fusedDownloadDAO.addDownload(fusedDownload)
    }
    }

    suspend fun getDownloadList(): List<FusedDownload> {
        mutex.withLock {
        return fusedDownloadDAO.getDownloadList()
    }
    }

    fun getDownloadLiveList(): LiveData<List<FusedDownload>> {
        return fusedDownloadDAO.getDownloadLiveList()
    }

    suspend fun updateDownload(fusedDownload: FusedDownload) {
        mutex.withLock {
        fusedDownloadDAO.updateDownload(fusedDownload)
    }
    }

    suspend fun deleteDownload(fusedDownload: FusedDownload) {
        mutex.withLock {
        return fusedDownloadDAO.deleteDownload(fusedDownload)
    }
    }

    suspend fun getDownloadById(id: String): FusedDownload? {
        mutex.withLock {
        return fusedDownloadDAO.getDownloadById(id)
    }
    }

    fun getDownloadFlowById(id: String): Flow<FusedDownload> {
        return fusedDownloadDAO.getDownloadFlowById(id).asFlow()
+0 −2
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
import foundation.e.apps.utils.modules.PWAManagerModule
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import timber.log.Timber
@@ -92,7 +91,6 @@ class FusedManagerImpl @Inject constructor(
    suspend fun updateDownloadStatus(fusedDownload: FusedDownload, status: Status) {
        if (status == Status.INSTALLED) {
            fusedDownload.status = status
//            databaseRepository.updateDownload(fusedDownload)
            DownloadManagerBR.downloadedList.clear()
            flushOldDownload(fusedDownload.packageName)
            databaseRepository.deleteDownload(fusedDownload)
+10 −1
Original line number Diff line number Diff line
@@ -56,8 +56,17 @@ class InstallerService : Service() {
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
        val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -69)
        val packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)
        var packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)
        val extra = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE)

        /**
         There is some error case where package name from PackageInstaller remains
         empty (example: INSTALL_PARSE_FAILED_NOT_APK).
         the packageName from PkgManagerModule will be used in this error case.
         */
        val packageNamePackageManagerModule = intent.getStringExtra(PkgManagerModule.PACKAGE_NAME)

        packageName = packageName ?: packageNamePackageManagerModule
        postStatus(status, packageName, extra)
        stopSelf()
        return START_NOT_STICKY
+3 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ class PkgManagerModule @Inject constructor(
) {
    companion object {
        const val ERROR_PACKAGE_INSTALL = "ERROR_PACKAGE_INSTALL"
        const val PACKAGE_NAME = "packageName"
        private const val TAG = "PkgManagerModule"
    }
    private val packageManager = context.packageManager
@@ -159,6 +160,8 @@ class PkgManagerModule @Inject constructor(
            }

            val callBackIntent = Intent(context, InstallerService::class.java)
            callBackIntent.putExtra(PACKAGE_NAME, packageName)

            val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
                PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE else
                PendingIntent.FLAG_UPDATE_CURRENT