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

Commit 893849ba authored by Patrick Baumann's avatar Patrick Baumann Committed by android-build-merger
Browse files

Merge "Adds sanity checks to session commit and abandon" into qt-dev

am: 116ca5db

Change-Id: I2be2b6bdf8fded0689522bcd3f288ac9d01ef0c6
parents b5b7677a 116ca5db
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -1222,7 +1222,7 @@ public class PackageInstaller {
            try {
            try {
                mSession.addChildSessionId(sessionId);
                mSession.addChildSessionId(sessionId);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
                e.rethrowFromSystemServer();
            }
            }
        }
        }


@@ -1236,7 +1236,7 @@ public class PackageInstaller {
            try {
            try {
                mSession.removeChildSessionId(sessionId);
                mSession.removeChildSessionId(sessionId);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
                e.rethrowFromSystemServer();
            }
            }
        }
        }
    }
    }
+19 −11
Original line number Original line Diff line number Diff line
@@ -841,6 +841,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {


    @Override
    @Override
    public void commit(@NonNull IntentSender statusReceiver, boolean forTransfer) {
    public void commit(@NonNull IntentSender statusReceiver, boolean forTransfer) {
        if (hasParentSessionId()) {
            throw new IllegalStateException(
                    "Session " + sessionId + " is a child of multi-package session "
                            + mParentSessionId +  " and may not be committed directly.");
        }
        if (!markAsCommitted(statusReceiver, forTransfer)) {
        if (!markAsCommitted(statusReceiver, forTransfer)) {
            return;
            return;
        }
        }
@@ -2037,6 +2042,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {


    @Override
    @Override
    public void abandon() {
    public void abandon() {
        if (hasParentSessionId()) {
            throw new IllegalStateException(
                    "Session " + sessionId + " is a child of multi-package session "
                            + mParentSessionId +  " and may not be abandoned directly.");
        }
        synchronized (mLock) {
        synchronized (mLock) {
            assertCallerIsOwnerOrRootLocked();
            assertCallerIsOwnerOrRootLocked();


@@ -2079,13 +2089,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    }
    }


    @Override
    @Override
    public void addChildSessionId(int childSessionId) throws RemoteException {
    public void addChildSessionId(int childSessionId) {
        final PackageInstallerSession childSession = mSessionProvider.getSession(childSessionId);
        final PackageInstallerSession childSession = mSessionProvider.getSession(childSessionId);
        if (childSession == null) {
        if (childSession == null
            throw new RemoteException("Unable to add child.",
                || (childSession.hasParentSessionId() && childSession.mParentSessionId != sessionId)
                    new PackageManagerException("Child session " + childSessionId
                || childSession.mCommitted
                            + " does not exist"),
                || childSession.mDestroyed) {
                    false, true).rethrowAsRuntimeException();
            throw new IllegalStateException("Unable to add child session " + childSessionId
                            + " as it does not exist or is in an invalid state.");
        }
        }
        synchronized (mLock) {
        synchronized (mLock) {
            assertCallerIsOwnerOrRootLocked();
            assertCallerIsOwnerOrRootLocked();
@@ -2124,11 +2135,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        synchronized (mLock) {
        synchronized (mLock) {
            if (parentSessionId != SessionInfo.INVALID_ID
            if (parentSessionId != SessionInfo.INVALID_ID
                    && mParentSessionId != SessionInfo.INVALID_ID) {
                    && mParentSessionId != SessionInfo.INVALID_ID) {
                throw new RemoteException("Unable to set parent session.",
                throw new IllegalStateException("The parent of " + sessionId + " is" + " already"
                        new PackageManagerException(
                        + "set to " + mParentSessionId);
                                "The parent of " + sessionId + " is" + " already set to "
                                        + mParentSessionId), false,
                        true).rethrowAsRuntimeException();
            }
            }
            this.mParentSessionId = parentSessionId;
            this.mParentSessionId = parentSessionId;
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -487,7 +487,7 @@ public class StagingManager {
                }
                }
                try {
                try {
                    apkParentSession.addChildSessionId(apkChildSession.sessionId);
                    apkParentSession.addChildSessionId(apkChildSession.sessionId);
                } catch (RemoteException e) {
                } catch (IllegalStateException e) {
                    Slog.e(TAG, "Failed to add a child session for installing the APK files", e);
                    Slog.e(TAG, "Failed to add a child session for installing the APK files", e);
                    return false;
                    return false;
                }
                }