diff options
| author | 2020-08-28 17:18:35 +0000 | |
|---|---|---|
| committer | 2020-08-28 17:18:35 +0000 | |
| commit | 92d9af6c476f880652e226fe8efee7029e288c69 (patch) | |
| tree | 03f23d0d5c8c325437cd01a5454d6e0b289785e3 | |
| parent | e7c2611944aa7a3bcd07ce4e5a586a5296fb3da2 (diff) | |
| parent | b1d0a839f1045ba8c3cf421c668127d0231084e1 (diff) | |
Merge "Fix transfer API." into rvc-qpr-dev
| -rw-r--r-- | core/java/android/content/pm/PackageInstaller.java | 5 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageInstallerSession.java | 19 |
2 files changed, 16 insertions, 8 deletions
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index fc4ccd072e75..191c4655c708 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -1291,9 +1291,8 @@ public class PackageInstaller { * * @throws PackageManager.NameNotFoundException if the new owner could not be found. * @throws SecurityException if called after the session has been committed or abandoned. - * @throws SecurityException if the session does not update the original installer - * @throws SecurityException if streams opened through - * {@link #openWrite(String, long, long) are still open. + * @throws IllegalArgumentException if streams opened through + * {@link #openWrite(String, long, long) are still open. */ public void transfer(@NonNull String packageName) throws PackageManager.NameNotFoundException { diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 994cec2b1e59..ea53132ae409 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -267,6 +267,9 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { /** Uid of the creator of this session. */ private final int mOriginalInstallerUid; + /** Package name of the app that created the installation session. */ + private final String mOriginalInstallerPackageName; + /** Uid of the owner of the installer session */ @GuardedBy("mLock") private int mInstallerUid; @@ -556,6 +559,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mOriginalInstallerUid = installerUid; mInstallerUid = installerUid; mInstallSource = Objects.requireNonNull(installSource); + mOriginalInstallerPackageName = mInstallSource.installerPackageName; this.params = params; this.createdMillis = createdMillis; this.updatedMillis = createdMillis; @@ -1666,11 +1670,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { throw new IllegalArgumentException("Package is not valid", e); } - if (!mPackageName.equals(mInstallSource.installerPackageName)) { - throw new SecurityException("Can only transfer sessions that update the original " - + "installer"); - } - mInstallerUid = newOwnerAppInfo.uid; mInstallSource = InstallSource.create(packageName, null, packageName); } @@ -2157,6 +2156,15 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } + if (mInstallerUid != mOriginalInstallerUid) { + // Session has been transferred, check package name. + if (TextUtils.isEmpty(mPackageName) || !mPackageName.equals( + mOriginalInstallerPackageName)) { + throw new PackageManagerException(PackageManager.INSTALL_FAILED_PACKAGE_CHANGED, + "Can only transfer sessions that update the original installer"); + } + } + if (params.mode == SessionParams.MODE_FULL_INSTALL) { // Full installs must include a base package if (!stagedSplits.contains(null)) { @@ -3182,6 +3190,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { pw.printPair("userId", userId); pw.printPair("mOriginalInstallerUid", mOriginalInstallerUid); + pw.printPair("mOriginalInstallerPackageName", mOriginalInstallerPackageName); pw.printPair("installerPackageName", mInstallSource.installerPackageName); pw.printPair("installInitiatingPackageName", mInstallSource.initiatingPackageName); pw.printPair("installOriginatingPackageName", mInstallSource.originatingPackageName); |