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

Commit 418ee825 authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Merge all install stages in a single file

In Kotlin, we can use a sealed class to define a super class and keep all its
subclasses in the same file. As such, merge all files in the
installstagedata/ inside InstallStages.kt. Accordingly, import the right
classes where required.

Bug: 182205982
Test: builds successfully
Change-Id: I706f1edc145ab3c9efcb6fb3aeaac09c80420ccc
parent 37838e24
Loading
Loading
Loading
Loading
+7 −15
Original line number Diff line number Diff line
@@ -43,6 +43,13 @@ import com.android.packageinstaller.R
import com.android.packageinstaller.common.EventResultPersister
import com.android.packageinstaller.common.EventResultPersister.OutOfIdsException
import com.android.packageinstaller.common.InstallEventReceiver
import com.android.packageinstaller.v2.model.InstallAborted.Companion.ABORT_REASON_DONE
import com.android.packageinstaller.v2.model.InstallAborted.Companion.ABORT_REASON_INTERNAL_ERROR
import com.android.packageinstaller.v2.model.InstallAborted.Companion.ABORT_REASON_POLICY
import com.android.packageinstaller.v2.model.InstallAborted.Companion.DLG_PACKAGE_ERROR
import com.android.packageinstaller.v2.model.InstallUserActionRequired.Companion.USER_ACTION_REASON_ANONYMOUS_SOURCE
import com.android.packageinstaller.v2.model.InstallUserActionRequired.Companion.USER_ACTION_REASON_INSTALL_CONFIRMATION
import com.android.packageinstaller.v2.model.InstallUserActionRequired.Companion.USER_ACTION_REASON_UNKNOWN_SOURCE
import com.android.packageinstaller.v2.model.PackageUtil.canPackageQuery
import com.android.packageinstaller.v2.model.PackageUtil.generateStubPackageInfo
import com.android.packageinstaller.v2.model.PackageUtil.getAppSnippet
@@ -51,21 +58,6 @@ import com.android.packageinstaller.v2.model.PackageUtil.getPackageNameForUid
import com.android.packageinstaller.v2.model.PackageUtil.isCallerSessionOwner
import com.android.packageinstaller.v2.model.PackageUtil.isInstallPermissionGrantedOrRequested
import com.android.packageinstaller.v2.model.PackageUtil.isPermissionGranted
import com.android.packageinstaller.v2.model.installstagedata.InstallAborted
import com.android.packageinstaller.v2.model.installstagedata.InstallAborted.Companion.ABORT_REASON_DONE
import com.android.packageinstaller.v2.model.installstagedata.InstallAborted.Companion.ABORT_REASON_INTERNAL_ERROR
import com.android.packageinstaller.v2.model.installstagedata.InstallAborted.Companion.ABORT_REASON_POLICY
import com.android.packageinstaller.v2.model.installstagedata.InstallAborted.Companion.DLG_PACKAGE_ERROR
import com.android.packageinstaller.v2.model.installstagedata.InstallFailed
import com.android.packageinstaller.v2.model.installstagedata.InstallInstalling
import com.android.packageinstaller.v2.model.installstagedata.InstallReady
import com.android.packageinstaller.v2.model.installstagedata.InstallStage
import com.android.packageinstaller.v2.model.installstagedata.InstallStaging
import com.android.packageinstaller.v2.model.installstagedata.InstallSuccess
import com.android.packageinstaller.v2.model.installstagedata.InstallUserActionRequired
import com.android.packageinstaller.v2.model.installstagedata.InstallUserActionRequired.Companion.USER_ACTION_REASON_ANONYMOUS_SOURCE
import com.android.packageinstaller.v2.model.installstagedata.InstallUserActionRequired.Companion.USER_ACTION_REASON_INSTALL_CONFIRMATION
import com.android.packageinstaller.v2.model.installstagedata.InstallUserActionRequired.Companion.USER_ACTION_REASON_UNKNOWN_SOURCE
import java.io.File
import java.io.IOException

+134 −0
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,12 +14,98 @@
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model.installstagedata
package com.android.packageinstaller.v2.model

import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable

class InstallAborted(
sealed class InstallStage(val stageCode: Int) {

    companion object {
        const val STAGE_DEFAULT = -1
        const val STAGE_ABORTED = 0
        const val STAGE_STAGING = 1
        const val STAGE_READY = 2
        const val STAGE_USER_ACTION_REQUIRED = 3
        const val STAGE_INSTALLING = 4
        const val STAGE_SUCCESS = 5
        const val STAGE_FAILED = 6
    }
}

class InstallStaging : InstallStage(STAGE_STAGING)

class InstallReady : InstallStage(STAGE_READY)

data class InstallUserActionRequired(
    val actionReason: Int,
    private val appSnippet: PackageUtil.AppSnippet? = null,
    val isAppUpdating: Boolean = false,
    val dialogMessage: String? = null,
) : InstallStage(STAGE_USER_ACTION_REQUIRED) {

    val appIcon: Drawable?
        get() = appSnippet?.icon

    val appLabel: String?
        get() = appSnippet?.let { appSnippet.label as String? }

    companion object {
        const val USER_ACTION_REASON_UNKNOWN_SOURCE = 0
        const val USER_ACTION_REASON_ANONYMOUS_SOURCE = 1
        const val USER_ACTION_REASON_INSTALL_CONFIRMATION = 2
    }
}

data class InstallInstalling(private val appSnippet: PackageUtil.AppSnippet) :
    InstallStage(STAGE_INSTALLING) {

    val appIcon: Drawable?
        get() = appSnippet.icon

    val appLabel: String?
        get() = appSnippet.label as String?
}

data class InstallSuccess(
    private val appSnippet: PackageUtil.AppSnippet,
    val shouldReturnResult: Boolean = false,
    /**
     *
     * * If the caller is requesting a result back, this will hold the Intent with
     * [Intent.EXTRA_INSTALL_RESULT] set to [PackageManager.INSTALL_SUCCEEDED] which is sent
     * back to the caller.
     *
     * * If the caller doesn't want the result back, this will hold the Intent that launches
     * the newly installed / updated app if a launchable activity exists.
     */
    val resultIntent: Intent? = null,
) : InstallStage(STAGE_SUCCESS) {

    val appIcon: Drawable?
        get() = appSnippet.icon

    val appLabel: String?
        get() = appSnippet.label as String?
}

data class InstallFailed(
    private val appSnippet: PackageUtil.AppSnippet,
    val legacyCode: Int,
    val statusCode: Int,
    val message: String?,
) : InstallStage(STAGE_FAILED) {

    val appIcon: Drawable?
        get() = appSnippet.icon

    val appLabel: String?
        get() = appSnippet.label as String?
}

data class InstallAborted(
    val abortReason: Int,
    /**
     * It will hold the restriction name, when the restriction was enforced by the system, and not
@@ -37,9 +123,7 @@ class InstallAborted(
    val resultIntent: Intent? = null,
    val activityResultCode: Int = Activity.RESULT_CANCELED,
    val errorDialogType: Int? = 0,
) : InstallStage() {

    override val stageCode = STAGE_ABORTED
) : InstallStage(STAGE_ABORTED) {

    companion object {
        const val ABORT_REASON_INTERNAL_ERROR = 0
+0 −36
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model.installstagedata

import android.graphics.drawable.Drawable
import com.android.packageinstaller.v2.model.PackageUtil

class InstallFailed(
    private val appSnippet: PackageUtil.AppSnippet,
    val legacyCode: Int,
    val statusCode: Int,
    val message: String?
) : InstallStage() {

    override val stageCode = STAGE_FAILED

    val appIcon: Drawable?
        get() = appSnippet.icon

    val appLabel: String?
        get() = appSnippet.label as String?
}
+0 −31
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model.installstagedata

import android.graphics.drawable.Drawable
import com.android.packageinstaller.v2.model.PackageUtil

class InstallInstalling(private val appSnippet: PackageUtil.AppSnippet) : InstallStage() {

    override val stageCode = STAGE_INSTALLING

    val appIcon: Drawable?
        get() = appSnippet.icon

    val appLabel: String?
        get() = appSnippet.label as String?
}
+0 −22
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model.installstagedata

class InstallReady : InstallStage() {

    override val stageCode = STAGE_READY
}
Loading