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

Commit 1962cb15 authored by Nikita Ioffe's avatar Nikita Ioffe
Browse files

staged sessions: clear INSTALL_ALLOW_DOWNGRADE if pre-reboot session did not have it

Note: this applies only to user builds.

In case of staged sessions, post-reboot StagingManager creates new
non-staged sessions to install apks. Since StagingManager is in
system_server, those sessions will have INSTALL_ALLOW_DOWNGRADE flag
enabled, even if original session did not have it (e.g. if it's created
by Phonesky). This gives an installer an ability to downgrade an app by
issuing a staged install.

This CL fixes it by allowing downgrade only if one of the following
applies:
* It's a debuggable build.
* Session was created by a system_server (RollbackManager use case).
* Session was created by root or shell (adb development use case).

Test: adb install foo_v2.apk && adb install --staged -d foo_v1.apk on user build
Test: CtsStagedInstallHostTestCases (userdebug and user builds)
Bug: 128409829
Fixes: 128409829
Change-Id: I2e5e8fd98584095b7d52891c88f033cb4c5caf70
parent 319e7cb6
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -493,10 +493,11 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
            }
            }
        }
        }


        if (callingUid == Process.SYSTEM_UID) {
        if (Build.IS_DEBUGGABLE || isDowngradeAllowedForCaller(callingUid)) {
            params.installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
            params.installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
        } else {
        } else {
            params.installFlags &= ~PackageManager.INSTALL_ALLOW_DOWNGRADE;
            params.installFlags &= ~PackageManager.INSTALL_ALLOW_DOWNGRADE;
            params.installFlags &= ~PackageManager.INSTALL_REQUEST_DOWNGRADE;
        }
        }


        boolean isApex = (params.installFlags & PackageManager.INSTALL_APEX) != 0;
        boolean isApex = (params.installFlags & PackageManager.INSTALL_APEX) != 0;
@@ -616,6 +617,11 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        return sessionId;
        return sessionId;
    }
    }


    private boolean isDowngradeAllowedForCaller(int callingUid) {
        return callingUid == Process.SYSTEM_UID || callingUid == Process.ROOT_UID
                || callingUid == Process.SHELL_UID;
    }

    @Override
    @Override
    public void updateSessionAppIcon(int sessionId, Bitmap appIcon) {
    public void updateSessionAppIcon(int sessionId, Bitmap appIcon) {
        synchronized (mSessions) {
        synchronized (mSessions) {