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

Commit 3d9d86b4 authored by Sumedh Sen's avatar Sumedh Sen Committed by Android Build Coastguard Worker
Browse files

[piav2] Ensure correct installer name is shown in UpdateOwnership dialog

If an APK is being sideloaded, the update ownership dialog must show the
name of the app installing the APK, and not the Package Installer.

This was implemented for Pia V1 in ag/26217760

Bug: 319319384
Test: Manual. Follow repro steps from the bug
Test: atest CtsPackageInstallTestCases:UpdateOwnershipEnforcementTest
Flag: EXEMPT bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:78d9c1b780fe65c3ec11e1b7b3b363ee762fa8b0)
Merged-In: I19f39bfe0270b02c731ea990ac1e1dbe3e21d5b1
Change-Id: I19f39bfe0270b02c731ea990ac1e1dbe3e21d5b1
parent dba9f96a
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ class InstallRepository(private val context: Context) {
        private set
    private var callingUid = Process.INVALID_UID
    private var originatingUid = Process.INVALID_UID
    private var originatingUidFromSessionInfo = Process.INVALID_UID
    private var callingPackage: String? = null
    private var sessionStager: SessionStager? = null
    private lateinit var intent: Intent
@@ -136,17 +137,25 @@ class InstallRepository(private val context: Context) {

        callingPackage = callerInfo.packageName

        if (sessionId != SessionInfo.INVALID_ID) {
            val sessionInfo: SessionInfo? = packageInstaller.getSessionInfo(sessionId)
            callingPackage = sessionInfo?.getInstallerPackageName()
            callingAttributionTag = sessionInfo?.getInstallerAttributionTag()
        }

        // Uid of the source package, coming from ActivityManager
        callingUid = callerInfo.uid
        if (callingUid == Process.INVALID_UID) {
            Log.e(LOG_TAG, "Could not determine the launching uid.")
        }

        originatingUidFromSessionInfo = callingUid
        val sessionInfo: SessionInfo? =
            if (sessionId != SessionInfo.INVALID_ID)
                packageInstaller.getSessionInfo(sessionId)
            else null
        if (sessionInfo != null) {
            callingPackage = sessionInfo.installerPackageName
            callingAttributionTag = sessionInfo.installerAttributionTag
            if (sessionInfo.originatingUid != Process.INVALID_UID) {
                originatingUidFromSessionInfo = sessionInfo.originatingUid
            }
        }

        val sourceInfo: ApplicationInfo? = getSourceInfo(callingPackage)
        // Uid of the source package, with a preference to uid from ApplicationInfo
        originatingUid = sourceInfo?.uid ?: callingUid
@@ -651,7 +660,12 @@ class InstallRepository(private val context: Context) {
    private fun getUpdateMessage(pkgInfo: PackageInfo, userActionReason: Int): String? {
        if (isAppUpdating(pkgInfo)) {
            val existingUpdateOwnerLabel = getExistingUpdateOwnerLabel(pkgInfo)
            val requestedUpdateOwnerLabel = getApplicationLabel(callingPackage)

            val originatingPackageNameFromSessionInfo =
                getPackageNameForUid(context, originatingUidFromSessionInfo, callingPackage)
            val requestedUpdateOwnerLabel =
                getApplicationLabel(originatingPackageNameFromSessionInfo)

            if (!TextUtils.isEmpty(existingUpdateOwnerLabel)
                && userActionReason == PackageInstaller.REASON_REMIND_OWNERSHIP
            ) {