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

Commit 1e628d92 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge remote-tracking branch 'origin/2237-gplay_apps_installer_fakestore'

parents f565a8ab 1b7660a7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ open class PkgManagerBR : BroadcastReceiver() {
    @Inject
    lateinit var fusedManagerRepository: FusedManagerRepository

    @Inject
    lateinit var pkgManagerModule: PkgManagerModule

    override fun onReceive(context: Context?, intent: Intent?) {
        val action = intent?.action
        if (context != null && action != null) {
@@ -86,6 +89,7 @@ open class PkgManagerBR : BroadcastReceiver() {
        }
        GlobalScope.launch {
            val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = pkgName)
            pkgManagerModule.setFakeStoreAsInstallerIfNeeded(fusedDownload)
            fusedManagerRepository.updateDownloadStatus(fusedDownload, Status.INSTALLED)
        }
    }
+31 −1
Original line number Diff line number Diff line
@@ -30,7 +30,10 @@ import android.os.Build
import android.util.Log
import androidx.core.content.pm.PackageInfoCompat
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
import kotlinx.coroutines.DelicateCoroutinesApi
import java.io.File
import javax.inject.Inject
@@ -87,9 +90,36 @@ class PkgManagerModule @Inject constructor(
        }
    }

    /**
     * Sets an installed app's installer as FakeStore if its source / origin is from Google play.
     * If the origin is not Google play, no operation is performed.
     *
     * [See issue 2237](https://gitlab.e.foundation/e/backlog/-/issues/2237)
     *
     * Surrounded by try-catch to prevent exception is case App Lounge and FakeStore's
     * signing certificate is not the same.
     */
    fun setFakeStoreAsInstallerIfNeeded(fusedDownload: FusedDownload?) {
        if (fusedDownload == null || fusedDownload.package_name.isBlank()) {
            return
        }
        if (fusedDownload.origin == Origin.GPLAY) {
            val fakeStorePackageName = "com.android.vending"
            if (fusedDownload.type == Type.NATIVE && isInstalled(fakeStorePackageName)) {
                val targetPackage = fusedDownload.package_name
                try {
                    packageManager.setInstallerPackageName(targetPackage, fakeStorePackageName)
                    Log.d(TAG, "Changed installer to $fakeStorePackageName for $targetPackage")
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
        }
    }

    /**
     * Installs the given package using system API
     * @param file An instance of [File]
     * @param list List of [File] to be written to install session.
     */
    @OptIn(DelicateCoroutinesApi::class)
    fun installApplication(list: List<File>, packageName: String) {