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

Commit 74d3b3ff authored by Sumedh Sen's avatar Sumedh Sen
Browse files

[piav2] Cleanup CL to prepare for single user-confirmation dialog change

This CL attempts to cleanup the code in PIAV2 to account for nullable
InstallStage returned by InstallRepository

Bug: 319320680
Test: Install an APK manually
Change-Id: Ib09fb91e02978181d5d70f77a63ffde8e0c9f35f
parent 6ecaf709
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -861,7 +861,12 @@ class InstallRepository(private val context: Context) {
            }
            _installResult.setValue(InstallSuccess(appSnippet, shouldReturnResult, resultIntent))
        } else {
            if (statusCode != PackageInstaller.STATUS_FAILURE_ABORTED) {
                _installResult.setValue(InstallFailed(appSnippet, statusCode, legacyStatus, message))
            } else {
                _installResult.setValue(InstallAborted(ABORT_REASON_INTERNAL_ERROR))
            }

        }
    }

+20 −10
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.distinctUntilChanged
import com.android.packageinstaller.v2.model.InstallRepository
import com.android.packageinstaller.v2.model.InstallStage
import com.android.packageinstaller.v2.model.InstallStaging
@@ -37,6 +38,19 @@ class InstallViewModel(application: Application, val repository: InstallReposito
    val currentInstallStage: MutableLiveData<InstallStage>
        get() = _currentInstallStage

    init {
        // Since installing is an async operation, we may get the install result later in time.
        // Result of the installation will be set in InstallRepository#installResult.
        // As such, currentInstallStage will need to add another MutableLiveData as a data source
        _currentInstallStage.addSource(
            repository.installResult.distinctUntilChanged()
        ) { installStage: InstallStage? ->
            if (installStage != null) {
                _currentInstallStage.value = installStage
            }
        }
    }

    fun preprocessIntent(intent: Intent, callerInfo: InstallRepository.CallerInfo) {
        val stage = repository.performPreInstallChecks(intent, callerInfo)
        if (stage.stageCode == InstallStage.STAGE_ABORTED) {
@@ -62,13 +76,17 @@ class InstallViewModel(application: Application, val repository: InstallReposito

    private fun checkIfAllowedAndInitiateInstall() {
        val stage = repository.requestUserConfirmation()
        if (stage != null) {
            _currentInstallStage.value = stage
        }
    }

    fun forcedSkipSourceCheck() {
        val stage = repository.forcedSkipSourceCheck()
        if (stage != null) {
            _currentInstallStage.value = stage
        }
    }

    fun cleanupInstall() {
        repository.cleanupInstall()
@@ -80,15 +98,7 @@ class InstallViewModel(application: Application, val repository: InstallReposito
    }

    fun initiateInstall() {
        // Since installing is an async operation, we will get the install result later in time.
        // Result of the installation will be set in InstallRepository#mInstallResult.
        // As such, mCurrentInstallStage will need to add another MutableLiveData as a data source
        repository.initiateInstall()
        _currentInstallStage.addSource(repository.installResult) { installStage: InstallStage? ->
            if (installStage != null) {
                _currentInstallStage.value = installStage
            }
        }
    }

    val stagedSessionId: Int