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

Commit b19810da authored by Felka Chang's avatar Felka Chang
Browse files

Throw appropriate exception for session transferring

If the parameter "packageName" is invalid, such as null or
empty string for package name, an IllegalArgumentException is thrown.

In PackageInstallerSession.transfer(packageName), in order to let
the throwing exception more close to the real situation, we throw
IllegalStateException rather than IllegalArgumentException when
one file isn't closed or the state is wrong.

Test: atest InstallSessionTransferTest
Bug: 158804946
Change-Id: Ib0a3e8dc19b829c7382791e622e0b86ee8b387e8
parent 68a95956
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -53,10 +53,12 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.system.ErrnoException;
import android.system.Os;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.ExceptionUtils;

import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.internal.util.function.pooled.PooledLambda;

import java.io.Closeable;
@@ -1349,12 +1351,13 @@ 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 IllegalArgumentException if streams opened through
         * @throws IllegalStateException if streams opened through
         *                                  {@link #openWrite(String, long, long) are still open.
         * @throws IllegalArgumentException if {@code packageName} is invalid.
         */
        public void transfer(@NonNull String packageName)
                throws PackageManager.NameNotFoundException {
            Objects.requireNonNull(packageName);
            Preconditions.checkArgument(!TextUtils.isEmpty(packageName));

            try {
                mSession.transfer(packageName);
+2 −2
Original line number Diff line number Diff line
@@ -1805,7 +1805,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {

    @Override
    public void transfer(String packageName) {
        Objects.requireNonNull(packageName);
        Preconditions.checkArgument(!TextUtils.isEmpty(packageName));

        ApplicationInfo newOwnerAppInfo = mPm.getApplicationInfo(packageName, 0, userId);
        if (newOwnerAppInfo == null) {
@@ -1831,7 +1831,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            try {
                sealLocked();
            } catch (PackageManagerException e) {
                throw new IllegalArgumentException("Package is not valid", e);
                throw new IllegalStateException("Package is not valid", e);
            }

            mInstallerUid = newOwnerAppInfo.uid;