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

Commit 9dacbf71 authored by Wei Wang's avatar Wei Wang Committed by android-build-merger
Browse files

Merge "Add death monitor to AsyncChannel Server." into nyc-dev am: 3054d010

am: 613eac8d

* commit '613eac8d':
  Add death monitor to AsyncChannel Server.

Change-Id: I8a73ae84aad856e85147e381a89d7609ef426a27
parents 6a45a333 613eac8d
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -402,7 +402,7 @@ public class AsyncChannel {

        // Initialize destination fields
        mDstMessenger = dstMessenger;

        linkToDeathMonitor();
        if (DBG) log("connected srcHandler to the dstMessenger X");
    }

@@ -844,22 +844,30 @@ public class AsyncChannel {
        msg.arg1 = status;
        msg.obj = this;
        msg.replyTo = mDstMessenger;
        if (!linkToDeathMonitor()) {
            // Override status to indicate failure
            msg.arg1 = STATUS_BINDING_UNSUCCESSFUL;
        }

        /*
         * Link to death only when bindService isn't used.
        mSrcHandler.sendMessage(msg);
    }

    /**
     * Link to death monitor for destination messenger. Returns true if successfully binded to
     * destination messenger; false otherwise.
     */
        if (mConnection == null) {
    private boolean linkToDeathMonitor() {
        // Link to death only when bindService isn't used and not already linked.
        if (mConnection == null && mDeathMonitor == null) {
            mDeathMonitor = new DeathMonitor();
            try {
                mDstMessenger.getBinder().linkToDeath(mDeathMonitor, 0);
            } catch (RemoteException e) {
                mDeathMonitor = null;
                // Override status to indicate failure
                msg.arg1 = STATUS_BINDING_UNSUCCESSFUL;
                return false;
            }
        }

        mSrcHandler.sendMessage(msg);
        return true;
    }

    /**