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

Commit 78af29b0 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch '0000-port-split-install-as-is' into 'main'

Use new AuthenticatorRepository to get AuthData

See merge request !412
parents c69caf91 47cea453
Loading
Loading
Loading
Loading
Loading
+14 −8
Original line number Original line Diff line number Diff line
@@ -20,10 +20,11 @@ package foundation.e.apps.install.splitinstall


import android.content.Context
import android.content.Context
import androidx.core.content.pm.PackageInfoCompat
import androidx.core.content.pm.PackageInfoCompat
import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.ISplitInstallService
import foundation.e.apps.ISplitInstallService
import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.login.exceptions.GPlayLoginException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.launch
@@ -35,7 +36,7 @@ class SplitInstallBinder(
    private val coroutineScope: CoroutineScope,
    private val coroutineScope: CoroutineScope,
    val applicationRepository: ApplicationRepository,
    val applicationRepository: ApplicationRepository,
    val downloadManager: DownloadManager,
    val downloadManager: DownloadManager,
    val authData: AuthData?,
    val authenticatorRepository: AuthenticatorRepository,
    private var splitInstallSystemService: foundation.e.splitinstall.ISplitInstallService?
    private var splitInstallSystemService: foundation.e.splitinstall.ISplitInstallService?
) : ISplitInstallService.Stub() {
) : ISplitInstallService.Stub() {


@@ -43,17 +44,22 @@ class SplitInstallBinder(


    companion object {
    companion object {
        const val TAG = "SplitInstallerBinder"
        const val TAG = "SplitInstallerBinder"
        const val AUTH_DATA_ERROR_MESSAGE = "Could not get auth data"
    }
    }


    override fun installSplitModule(packageName: String, moduleName: String) {
    override fun installSplitModule(packageName: String, moduleName: String) {
        if (authData == null) {
        try {
            Timber.i("No authentication data. Could not install on demand module")
            if (authenticatorRepository.gplayAuth == null) {
                Timber.w(AUTH_DATA_ERROR_MESSAGE)
                return
                return
            }
            }


            coroutineScope.launch {
            coroutineScope.launch {
                downloadModule(packageName, moduleName)
                downloadModule(packageName, moduleName)
            }
            }
        } catch (exception: GPlayLoginException) {
            Timber.w("$AUTH_DATA_ERROR_MESSAGE $exception")
        }
    }
    }


    fun setService(service: foundation.e.splitinstall.ISplitInstallService) {
    fun setService(service: foundation.e.splitinstall.ISplitInstallService) {
+3 −14
Original line number Original line Diff line number Diff line
@@ -24,15 +24,14 @@ import android.content.ServiceConnection
import android.os.IBinder
import android.os.IBinder
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.lifecycleScope
import com.aurora.gplayapi.data.models.AuthData
import com.google.gson.Gson
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.preference.AppLoungeDataStore
import foundation.e.apps.data.preference.AppLoungeDataStore
import foundation.e.splitinstall.ISplitInstallService
import foundation.e.splitinstall.ISplitInstallService
import foundation.e.splitinstall.SplitInstall
import foundation.e.splitinstall.SplitInstall
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Inject


@AndroidEntryPoint
@AndroidEntryPoint
@@ -46,8 +45,8 @@ class SplitInstallService : LifecycleService() {
    @Inject lateinit var applicationRepository: ApplicationRepository
    @Inject lateinit var applicationRepository: ApplicationRepository
    @Inject lateinit var downloadManager: DownloadManager
    @Inject lateinit var downloadManager: DownloadManager
    @Inject lateinit var gson: Gson
    @Inject lateinit var gson: Gson
    @Inject lateinit var authenticatorRepository: AuthenticatorRepository
    private lateinit var binder: SplitInstallBinder
    private lateinit var binder: SplitInstallBinder
    private var authData: AuthData? = null
    private var splitInstallSystemService: ISplitInstallService? = null
    private var splitInstallSystemService: ISplitInstallService? = null


    private val serviceConnection = object : ServiceConnection {
    private val serviceConnection = object : ServiceConnection {
@@ -68,10 +67,6 @@ class SplitInstallService : LifecycleService() {
            component = SplitInstall.SPLIT_INSTALL_SYSTEM_SERVICE
            component = SplitInstall.SPLIT_INSTALL_SYSTEM_SERVICE
        }
        }
        bindService(intent, serviceConnection, BIND_AUTO_CREATE)
        bindService(intent, serviceConnection, BIND_AUTO_CREATE)

        lifecycleScope.launch {
            fetchAuthData()
        }
    }
    }


    override fun onDestroy() {
    override fun onDestroy() {
@@ -81,12 +76,6 @@ class SplitInstallService : LifecycleService() {
        super.onDestroy()
        super.onDestroy()
    }
    }


    private suspend fun fetchAuthData() {
        appLoungeDataStore.authData.collect {
            authData = gson.fromJson(it, AuthData::class.java)
        }
    }

    override fun onBind(intent: Intent): IBinder {
    override fun onBind(intent: Intent): IBinder {
        super.onBind(intent)
        super.onBind(intent)
        binder = SplitInstallBinder(
        binder = SplitInstallBinder(
@@ -94,7 +83,7 @@ class SplitInstallService : LifecycleService() {
            lifecycleScope,
            lifecycleScope,
            applicationRepository,
            applicationRepository,
            downloadManager,
            downloadManager,
            authData,
            authenticatorRepository,
            splitInstallSystemService
            splitInstallSystemService
        )
        )
        return binder
        return binder