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

Commit 78d9c1b7 authored by Sumedh Sen's avatar Sumedh Sen
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
Change-Id: I19f39bfe0270b02c731ea990ac1e1dbe3e21d5b1
parent d9227e90
Loading
Loading
Loading
Loading
+21 −7
Original line number Original line Diff line number Diff line
@@ -97,6 +97,7 @@ class InstallRepository(private val context: Context) {
        private set
        private set
    private var callingUid = Process.INVALID_UID
    private var callingUid = Process.INVALID_UID
    private var originatingUid = Process.INVALID_UID
    private var originatingUid = Process.INVALID_UID
    private var originatingUidFromSessionInfo = Process.INVALID_UID
    private var callingPackage: String? = null
    private var callingPackage: String? = null
    private var sessionStager: SessionStager? = null
    private var sessionStager: SessionStager? = null
    private lateinit var intent: Intent
    private lateinit var intent: Intent
@@ -136,17 +137,25 @@ class InstallRepository(private val context: Context) {


        callingPackage = callerInfo.packageName
        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
        // Uid of the source package, coming from ActivityManager
        callingUid = callerInfo.uid
        callingUid = callerInfo.uid
        if (callingUid == Process.INVALID_UID) {
        if (callingUid == Process.INVALID_UID) {
            Log.e(LOG_TAG, "Could not determine the launching 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)
        val sourceInfo: ApplicationInfo? = getSourceInfo(callingPackage)
        // Uid of the source package, with a preference to uid from ApplicationInfo
        // Uid of the source package, with a preference to uid from ApplicationInfo
        originatingUid = sourceInfo?.uid ?: callingUid
        originatingUid = sourceInfo?.uid ?: callingUid
@@ -651,7 +660,12 @@ class InstallRepository(private val context: Context) {
    private fun getUpdateMessage(pkgInfo: PackageInfo, userActionReason: Int): String? {
    private fun getUpdateMessage(pkgInfo: PackageInfo, userActionReason: Int): String? {
        if (isAppUpdating(pkgInfo)) {
        if (isAppUpdating(pkgInfo)) {
            val existingUpdateOwnerLabel = getExistingUpdateOwnerLabel(pkgInfo)
            val existingUpdateOwnerLabel = getExistingUpdateOwnerLabel(pkgInfo)
            val requestedUpdateOwnerLabel = getApplicationLabel(callingPackage)

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

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