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

Commit f8f7410e authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Show a user confirmation dialog only when update-ownership isn't changed

Bug: 319320680
Test: atest CtsPackageInstallTestCases:UpdateOwnershipEnforcementTest

Change-Id: Ia08960fb98929f58591a705e3da9ecc3c2c630a3
parent 74d3b3ff
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -176,11 +176,14 @@ public class PackageInstallerActivity extends Activity {
    }

    private CharSequence getExistingUpdateOwnerLabel() {
        return getApplicationLabel(getExistingUpdateOwner());
    }

    private String getExistingUpdateOwner() {
        try {
            final String packageName = mPkgInfo.packageName;
            final InstallSourceInfo sourceInfo = mPm.getInstallSourceInfo(packageName);
            final String existingUpdateOwner = sourceInfo.getUpdateOwnerPackageName();
            return getApplicationLabel(existingUpdateOwner);
            return sourceInfo.getUpdateOwnerPackageName();
        } catch (NameNotFoundException e) {
            return null;
        }
@@ -299,6 +302,18 @@ public class PackageInstallerActivity extends Activity {
    }

    private void initiateInstall() {
        final String existingUpdateOwner = getExistingUpdateOwner();
        if (mSessionId == SessionInfo.INVALID_ID &&
            !TextUtils.isEmpty(existingUpdateOwner) &&
            !TextUtils.equals(existingUpdateOwner, mOriginatingPackage)) {
            // Since update ownership is being changed, the system will request another
            // user confirmation shortly. Thus, we don't need to ask the user to confirm
            // installation here.
            startInstall();
            return;
        }

        // Proceed with user confirmation as we are not changing the update-owner in this install.
        String pkgName = mPkgInfo.packageName;
        // Check if there is already a package on the device with this name
        // but it has been renamed to something else.