am 1612e298: Merge "AsyncChannel to support remote death notification and post a disconnect message to the source handler."
* commit '1612e29826dfe55f8deca27374046c5931ce5335': AsyncChannel to support remote death notification and post a disconnect message to the source handler.
This commit is contained in:
@@ -180,6 +180,9 @@ public class AsyncChannel {
|
||||
/** CMD_FULLY_CONNECTED refused because a connection already exists*/
|
||||
public static final int STATUS_FULL_CONNECTION_REFUSED_ALREADY_CONNECTED = 3;
|
||||
|
||||
/** Error indicating abnormal termination of destination messenger */
|
||||
public static final int STATUS_REMOTE_DISCONNECTION = 4;
|
||||
|
||||
/** Service connection */
|
||||
private AsyncChannelConnection mConnection;
|
||||
|
||||
@@ -195,6 +198,9 @@ public class AsyncChannel {
|
||||
/** Messenger for destination */
|
||||
private Messenger mDstMessenger;
|
||||
|
||||
/** Death Monitor for destination messenger */
|
||||
private DeathMonitor mDeathMonitor;
|
||||
|
||||
/**
|
||||
* AsyncChannel constructor
|
||||
*/
|
||||
@@ -434,6 +440,7 @@ public class AsyncChannel {
|
||||
mSrcHandler = null;
|
||||
mSrcMessenger = null;
|
||||
mDstMessenger = null;
|
||||
mDeathMonitor = null;
|
||||
mConnection = null;
|
||||
}
|
||||
|
||||
@@ -457,6 +464,10 @@ public class AsyncChannel {
|
||||
if (mSrcHandler != null) {
|
||||
replyDisconnected(STATUS_SUCCESSFUL);
|
||||
}
|
||||
// Unlink only when bindService isn't used
|
||||
if (mConnection == null && mDstMessenger != null && mDeathMonitor!= null) {
|
||||
mDstMessenger.getBinder().unlinkToDeath(mDeathMonitor, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -832,6 +843,21 @@ public class AsyncChannel {
|
||||
msg.arg1 = status;
|
||||
msg.obj = this;
|
||||
msg.replyTo = mDstMessenger;
|
||||
|
||||
/*
|
||||
* Link to death only when bindService isn't used.
|
||||
*/
|
||||
if (mConnection == 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;
|
||||
}
|
||||
}
|
||||
|
||||
mSrcHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@@ -877,4 +903,15 @@ public class AsyncChannel {
|
||||
private static void log(String s) {
|
||||
Slog.d(TAG, s);
|
||||
}
|
||||
|
||||
private final class DeathMonitor implements IBinder.DeathRecipient {
|
||||
|
||||
DeathMonitor() {
|
||||
}
|
||||
|
||||
public void binderDied() {
|
||||
replyDisconnected(STATUS_REMOTE_DISCONNECTION);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user