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

Commit 304d2670 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge "Do not fail session.commit on current thread" into oc-mr1-dev

parents bc0c5882 32242a06
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;
                }
            }