Merge "Add death monitor to AsyncChannel Server." into nyc-dev

This commit is contained in:
Wei Wang
2016-03-31 23:13:33 +00:00
committed by Android (Google) Code Review

View File

@@ -402,7 +402,7 @@ public class AsyncChannel {
// Initialize destination fields // Initialize destination fields
mDstMessenger = dstMessenger; mDstMessenger = dstMessenger;
linkToDeathMonitor();
if (DBG) log("connected srcHandler to the dstMessenger X"); if (DBG) log("connected srcHandler to the dstMessenger X");
} }
@@ -844,22 +844,30 @@ public class AsyncChannel {
msg.arg1 = status; msg.arg1 = status;
msg.obj = this; msg.obj = this;
msg.replyTo = mDstMessenger; msg.replyTo = mDstMessenger;
if (!linkToDeathMonitor()) {
// Override status to indicate failure
msg.arg1 = STATUS_BINDING_UNSUCCESSFUL;
}
/* mSrcHandler.sendMessage(msg);
* Link to death only when bindService isn't used. }
/**
* 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(); mDeathMonitor = new DeathMonitor();
try { try {
mDstMessenger.getBinder().linkToDeath(mDeathMonitor, 0); mDstMessenger.getBinder().linkToDeath(mDeathMonitor, 0);
} catch (RemoteException e) { } catch (RemoteException e) {
mDeathMonitor = null; mDeathMonitor = null;
// Override status to indicate failure return false;
msg.arg1 = STATUS_BINDING_UNSUCCESSFUL;
} }
} }
return true;
mSrcHandler.sendMessage(msg);
} }
/** /**