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

Commit 32242a06 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Do not fail session.commit on current thread

The adb install command calls session.commit() requires the failure to
be delivered on a different thread than the one that calls
session.commit().

Test: Tried to install invalid package via adb install
Change-Id: I8b616c750afa81f126fa3d3576d21df8274b1432
Fixes: 65555295
parent c6e9bb9d
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private static final String REMOVE_SPLIT_MARKER_EXTENSION = ".removed";

    private static final int MSG_COMMIT = 0;
    private static final int MSG_SESSION_FINISHED_WITH_EXCEPTION = 1;

    /** XML constants used for persisting a session */
    static final String TAG_SESSION = "session";
@@ -274,17 +275,29 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private final Handler.Callback mHandlerCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_COMMIT:
                    synchronized (mLock) {
                        try {
                            commitLocked();
                        } catch (PackageManagerException e) {
                            final String completeMsg = ExceptionUtils.getCompleteMessage(e);
                    Slog.e(TAG, "Commit of session " + sessionId + " failed: " + completeMsg);
                            Slog.e(TAG,
                                    "Commit of session " + sessionId + " failed: " + completeMsg);
                            destroyInternal();
                            dispatchSessionFinished(e.error, completeMsg, null);
                        }
                    }

                    break;
                case MSG_SESSION_FINISHED_WITH_EXCEPTION:
                    PackageManagerException e = (PackageManagerException) msg.obj;

                    dispatchSessionFinished(e.error, ExceptionUtils.getCompleteMessage(e),
                            null);
                    break;
            }

            return true;
        }
    };
@@ -705,9 +718,13 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                } catch (IOException e) {
                    throw new IllegalArgumentException(e);
                } catch (PackageManagerException e) {
                    // Do now throw an exception here to stay compatible with O and older
                    destroyInternal();
                    dispatchSessionFinished(e.error, ExceptionUtils.getCompleteMessage(e), null);

                    // Cannot call dispatchFinal synchronous as this might be called from inside the
                    // system server on the main thread. Hence the call back scheduled in
                    // dispachFinal has to be scheduled on a different thread.
                    mHandler.obtainMessage(MSG_SESSION_FINISHED_WITH_EXCEPTION, e).sendToTarget();

                    return;
                }
            }