Fix transfer API.
Transfer API should throw security exception when transfering the session which is not installing the original installer. Moving it onto commit stage and still fail the installation. Fixes: 158805288 Test: atest InstallSessionTransferTest Test: atest -p frameworks/base/services/core/java/com/android/server/pm Change-Id: I8511d4357788e70f83bcbd366908b42a691afbcb
This commit is contained in:
@@ -1292,9 +1292,8 @@ public class PackageInstaller {
|
|||||||
*
|
*
|
||||||
* @throws PackageManager.NameNotFoundException if the new owner could not be found.
|
* @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 called after the session has been committed or abandoned.
|
||||||
* @throws SecurityException if the session does not update the original installer
|
* @throws IllegalArgumentException if streams opened through
|
||||||
* @throws SecurityException if streams opened through
|
* {@link #openWrite(String, long, long) are still open.
|
||||||
* {@link #openWrite(String, long, long) are still open.
|
|
||||||
*/
|
*/
|
||||||
public void transfer(@NonNull String packageName)
|
public void transfer(@NonNull String packageName)
|
||||||
throws PackageManager.NameNotFoundException {
|
throws PackageManager.NameNotFoundException {
|
||||||
|
|||||||
@@ -268,6 +268,9 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
|||||||
/** Uid of the creator of this session. */
|
/** Uid of the creator of this session. */
|
||||||
private final int mOriginalInstallerUid;
|
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 */
|
/** Uid of the owner of the installer session */
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private int mInstallerUid;
|
private int mInstallerUid;
|
||||||
@@ -557,6 +560,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
|||||||
mOriginalInstallerUid = installerUid;
|
mOriginalInstallerUid = installerUid;
|
||||||
mInstallerUid = installerUid;
|
mInstallerUid = installerUid;
|
||||||
mInstallSource = Objects.requireNonNull(installSource);
|
mInstallSource = Objects.requireNonNull(installSource);
|
||||||
|
mOriginalInstallerPackageName = mInstallSource.installerPackageName;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.createdMillis = createdMillis;
|
this.createdMillis = createdMillis;
|
||||||
this.updatedMillis = createdMillis;
|
this.updatedMillis = createdMillis;
|
||||||
@@ -1662,11 +1666,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
|||||||
throw new IllegalArgumentException("Package is not valid", e);
|
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;
|
mInstallerUid = newOwnerAppInfo.uid;
|
||||||
mInstallSource = InstallSource.create(packageName, null, packageName, null);
|
mInstallSource = InstallSource.create(packageName, null, packageName, null);
|
||||||
}
|
}
|
||||||
@@ -2183,6 +2182,15 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
|||||||
"Incremental installation of this package is not allowed.");
|
"Incremental installation of this package is not allowed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
if (params.mode == SessionParams.MODE_FULL_INSTALL) {
|
||||||
// Full installs must include a base package
|
// Full installs must include a base package
|
||||||
if (!stagedSplits.contains(null)) {
|
if (!stagedSplits.contains(null)) {
|
||||||
@@ -3212,6 +3220,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
|||||||
|
|
||||||
pw.printPair("userId", userId);
|
pw.printPair("userId", userId);
|
||||||
pw.printPair("mOriginalInstallerUid", mOriginalInstallerUid);
|
pw.printPair("mOriginalInstallerUid", mOriginalInstallerUid);
|
||||||
|
pw.printPair("mOriginalInstallerPackageName", mOriginalInstallerPackageName);
|
||||||
pw.printPair("installerPackageName", mInstallSource.installerPackageName);
|
pw.printPair("installerPackageName", mInstallSource.installerPackageName);
|
||||||
pw.printPair("installInitiatingPackageName", mInstallSource.initiatingPackageName);
|
pw.printPair("installInitiatingPackageName", mInstallSource.initiatingPackageName);
|
||||||
pw.printPair("installOriginatingPackageName", mInstallSource.originatingPackageName);
|
pw.printPair("installOriginatingPackageName", mInstallSource.originatingPackageName);
|
||||||
|
|||||||
Reference in New Issue
Block a user