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

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

Merge changes I079a317c,Ie6023f39 into main

* changes:
  [PM] Don't preserve the label in the stage data (2/N)
  [PM] Don't preserve the label in the stage data (1/N)
parents 11854639 f914ed7c
Loading
Loading
Loading
Loading
+8 −21
Original line number Diff line number Diff line
@@ -760,9 +760,13 @@ class InstallRepository(private val context: Context) : EventResultPersister.Eve
            return Pair(null, null)
        }

        val existingUpdateOwnerLabel = getExistingUpdateOwnerLabel(pkgInfo)
        val existingUpdateOwnerPackageName = getExistingUpdateOwner(pkgInfo)
        val existingUpdateOwnerLabel = PackageUtil.getApplicationLabel(
            context,
            existingUpdateOwnerPackageName.toString()
        )

        var requestedUpdateOwnerLabel: CharSequence? = if (
        var requestedPackageName: CharSequence? = if (
            isAppUpdating &&
            !TextUtils.isEmpty(existingUpdateOwnerLabel) &&
            userActionReason == PackageInstaller.REASON_REMIND_OWNERSHIP
@@ -776,16 +780,12 @@ class InstallRepository(private val context: Context) : EventResultPersister.Eve
            }
            val originatingPackageName =
                getPackageNameForUid(context, uid, callingPackage)
            getApplicationLabel(originatingPackageName)
            originatingPackageName
        } else {
            null
        }

        return Pair(existingUpdateOwnerLabel, requestedUpdateOwnerLabel)
    }

    private fun getExistingUpdateOwnerLabel(pkgInfo: PackageInfo): CharSequence? {
        return getApplicationLabel(getExistingUpdateOwner(pkgInfo))
        return Pair(existingUpdateOwnerPackageName, requestedPackageName)
    }

    private fun getExistingUpdateOwner(pkgInfo: PackageInfo): String? {
@@ -798,19 +798,6 @@ class InstallRepository(private val context: Context) : EventResultPersister.Eve
        }
    }

    private fun getApplicationLabel(packageName: String?): CharSequence? {
        return try {
            val appInfo = packageName?.let {
                packageManager.getApplicationInfo(
                    it, PackageManager.ApplicationInfoFlags.of(0)
                )
            }
            appInfo?.let { packageManager.getApplicationLabel(it) }
        } catch (e: PackageManager.NameNotFoundException) {
            null
        }
    }

    private fun isAppUpdating(newPkgInfo: PackageInfo?): Boolean {
        if (newPkgInfo == null) {
            return false
+15 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.packageinstaller.v2.model

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInstaller
import android.content.pm.PackageManager
@@ -48,8 +49,8 @@ data class InstallUserActionRequired(
    val actionReason: Int,
    val appSnippet: PackageUtil.AppSnippet? = null,
    val isAppUpdating: Boolean = false,
    val existingUpdateOwnerLabel: CharSequence? = null,
    val requestedUpdateOwnerLabel: CharSequence? = null,
    val existingUpdateOwnerPackageName: CharSequence? = null,
    val requestedUpdateOwnerPackageName: CharSequence? = null,
    val unknownSourcePackageName: String? = null,
    val verificationInfo: PackageInstaller.DeveloperVerificationUserConfirmationInfo? = null,
) : InstallStage(STAGE_USER_ACTION_REQUIRED) {
@@ -60,6 +61,18 @@ data class InstallUserActionRequired(
    val appLabel: String?
        get() = appSnippet?.let { appSnippet.label as String? }

    fun getExistingUpdateOwnerLabel(context: Context): String? {
        return existingUpdateOwnerPackageName?.let {
            PackageUtil.getApplicationLabel(context, it.toString()) as String?
        }
    }

    fun getRequestedUpdateOwnerLabel(context: Context): String? {
        return requestedUpdateOwnerPackageName?.let {
            PackageUtil.getApplicationLabel(context, it.toString()) as String?
        }
    }

    companion object {
        const val USER_ACTION_REASON_UNKNOWN_SOURCE = 0
        const val USER_ACTION_REASON_ANONYMOUS_SOURCE = 1
+17 −0
Original line number Diff line number Diff line
@@ -488,6 +488,23 @@ object PackageUtil {
                && userManager.getProfileParent(profileHandle) == userHandle
    }

    /**
     * Utility method to get the application label from the package name
     */
    @JvmStatic
    fun getApplicationLabel(context: Context, packageName: String): CharSequence? {
        return try {
            val appInfo = packageName.let {
                context.packageManager.getApplicationInfo(
                    it, PackageManager.ApplicationInfoFlags.of(0)
                )
            }
            appInfo.let { context.packageManager.getApplicationLabel(it) }
        } catch (e: PackageManager.NameNotFoundException) {
            null
        }
    }

    /**
     * @return If the device supports the material design in the package installer
     */
+4 −15
Original line number Diff line number Diff line
@@ -101,24 +101,13 @@ class UnarchiveRepository(private val context: Context) {
            return UnarchiveAborted(UnarchiveAborted.ABORT_REASON_GENERIC_ERROR)
        }

        var installerTitle: String
        try {
            installerTitle = getAppTitle(installingPackageName, 0)
        } catch (e: NameNotFoundException) {
            Log.e(LOG_TAG, "Could not find installer", e)
        val label = PackageUtil.getApplicationLabel(context, installingPackageName)
        if (label == null) {
            Log.e(LOG_TAG, "Could not find installer")
            return UnarchiveAborted(UnarchiveAborted.ABORT_REASON_GENERIC_ERROR)
        }

        return UnarchiveUserActionRequired(appSnippet, installerTitle)
    }

    @Throws(NameNotFoundException::class)
    private fun getAppTitle(packageName: String, flags: Long): String {
        val appInfo = packageManager.getApplicationInfo(
            packageName,
            PackageManager.ApplicationInfoFlags.of(flags)
        )
        return appInfo.loadLabel(packageManager).toString()
        return UnarchiveUserActionRequired(appSnippet, installingPackageName)
    }

    @SuppressLint("MissingPermission")
+8 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.packageinstaller.v2.model

import android.app.Activity
import android.app.PendingIntent
import android.content.Context
import android.graphics.drawable.Drawable

sealed class UnarchiveStage(val stageCode: Int) {
@@ -45,7 +46,7 @@ class UnarchiveReady() : UnarchiveStage(STAGE_READY)

data class UnarchiveUserActionRequired(
    val appSnippet: PackageUtil.AppSnippet? = null,
    val installerTitle: String
    val installerPackageName: String
) :
    UnarchiveStage(STAGE_USER_ACTION_REQUIRED) {
    val appIcon: Drawable?
@@ -53,6 +54,12 @@ data class UnarchiveUserActionRequired(

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

    fun getInstallerTitle(context: Context): String? {
        return installerPackageName.let {
            PackageUtil.getApplicationLabel(context, it) as String?
        }
    }
}

data class UnarchiveError(
Loading