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

Commit 0bb04000 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "pia-j2k" into main

* changes:
  Migrate AsyncTask to Coroutines
  Merge all uninstall stages in a single file
  Merge all install stages in a single file
  Convert code in UninstallRepository from Java to Kotlin
  Rename .java to .kt
  Convert code in InstallRepository and related classes from Java to Kotlin (install repo)
  Rename .java to .kt
  Convert code in PackageUtil from Java to Kotlin
  Rename .java to .kt
  Convert code in files from Java to Kotlin (view)
  Rename .java to .kt (view files)
  Convert code in files from Java to Kotlin (viewmodel)
  Rename .java to .kt (viewmodel files)
  Convert all uninstallstagedata/ classes from Java to Kotlin
  Rename .java to .kt
  Convert all installstagedata/ classes from Java to Kotlin
  Rename .java to .kt
parents a76dae6e b09b6ef0
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -35,7 +35,10 @@ android_app {
    name: "PackageInstaller",
    defaults: ["platform_app_defaults"],

    srcs: ["src/**/*.java"],
    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
    ],

    certificate: "platform",
    privileged: true,
@@ -62,7 +65,10 @@ android_app {
    name: "PackageInstaller_tablet",
    defaults: ["platform_app_defaults"],

    srcs: ["src/**/*.java"],
    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
    ],

    certificate: "platform",
    privileged: true,
@@ -91,7 +97,10 @@ android_app {
    name: "PackageInstaller_tv",
    defaults: ["platform_app_defaults"],

    srcs: ["src/**/*.java"],
    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
    ],

    certificate: "platform",
    privileged: true,
+0 −912

File deleted.

Preview size limit exceeded, changes collapsed.

+867 −0

File added.

Preview size limit exceeded, changes collapsed.

+134 −0
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

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

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
     * a device admin.
     */
    val message: String? = null,
    /**
     * * If abort reason is [ABORT_REASON_POLICY], then this will hold the Intent
     * to display a support dialog when a feature was disabled by an admin. It will be
     * `null` if the feature is disabled by the system. In this case, the restriction name
     * will be set in [message]
     * * If the abort reason is [ABORT_REASON_INTERNAL_ERROR], it **may** hold an
     * intent to be sent as a result to the calling activity.
     */
    val resultIntent: Intent? = null,
    val activityResultCode: Int = Activity.RESULT_CANCELED,
    val errorDialogType: Int? = 0,
) : InstallStage(STAGE_ABORTED) {

    companion object {
        const val ABORT_REASON_INTERNAL_ERROR = 0
        const val ABORT_REASON_POLICY = 1
        const val ABORT_REASON_DONE = 2
        const val DLG_PACKAGE_ERROR = 1
    }
}
+440 −0

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading