Merge "Allow persistent APKs updates using PM flags." into qt-dev

This commit is contained in:
Dario Freni
2019-05-09 18:49:13 +00:00
committed by Android (Google) Code Review
3 changed files with 11 additions and 4 deletions

View File

@@ -725,6 +725,7 @@ public abstract class PackageManager {
INSTALL_APEX,
INSTALL_ENABLE_ROLLBACK,
INSTALL_ALLOW_DOWNGRADE,
INSTALL_STAGED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface InstallFlags {}
@@ -894,6 +895,14 @@ public abstract class PackageManager {
*/
public static final int INSTALL_ALLOW_DOWNGRADE = 0x00100000;
/**
* Flag parameter for {@link #installPackage} to indicate that this package
* is being installed as part of a staged install.
*
* @hide
*/
public static final int INSTALL_STAGED = 0x00200000;
/** @hide */
@IntDef(flag = true, prefix = { "DONT_KILL_APP" }, value = {
DONT_KILL_APP

View File

@@ -939,7 +939,6 @@ public class PackageManagerService extends IPackageManager.Stub
ComponentName mCustomResolverComponentName;
boolean mResolverReplaced = false;
boolean mOkToReplacePersistentPackages = false;
private final @Nullable ComponentName mIntentFilterVerifierComponent;
private final @Nullable IntentFilterVerifier<ActivityIntentInfo> mIntentFilterVerifier;
@@ -17401,7 +17400,7 @@ public class PackageManagerService extends IPackageManager.Stub
}
// Prevent persistent apps from being updated
if (((oldPackage.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) != 0)
&& !mOkToReplacePersistentPackages) {
&& ((installFlags & PackageManager.INSTALL_STAGED) == 0)) {
throw new PrepareFailure(PackageManager.INSTALL_FAILED_INVALID_APK,
"Package " + oldPackage.packageName + " is a persistent app. "
+ "Persistent apps are not updateable.");
@@ -21583,12 +21582,10 @@ public class PackageManagerService extends IPackageManager.Stub
mModuleInfoProvider.systemReady();
mOkToReplacePersistentPackages = true;
// Installer service might attempt to install some packages that have been staged for
// installation on reboot. Make sure this is the last component to be call since the
// installation might require other components to be ready.
mInstallerService.restoreAndApplyStagedSessionIfNeeded();
mOkToReplacePersistentPackages = false;
}
public void waitForAppDataPrepared() {

View File

@@ -383,6 +383,7 @@ public class StagingManager {
PackageInstaller.SessionParams params = originalSession.params.copy();
params.isStaged = false;
params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION;
params.installFlags |= PackageManager.INSTALL_STAGED;
// TODO(b/129744602): use the userid from the original session.
int apkSessionId = mPi.createSession(
params, originalSession.getInstallerPackageName(),