SipService: unset session listener if listener is gone.
Change-Id: I0b85ee7bcb32c24cf64dfc3edc40c0cad9717562
diff --git a/services/java/com/android/server/sip/SipSessionListenerProxy.java b/services/java/com/android/server/sip/SipSessionListenerProxy.java
index 7004204..7234196 100644
--- a/services/java/com/android/server/sip/SipSessionListenerProxy.java
+++ b/services/java/com/android/server/sip/SipSessionListenerProxy.java
@@ -19,6 +19,7 @@
import android.net.sip.ISipSession;
import android.net.sip.ISipSessionListener;
import android.net.sip.SipProfile;
+import android.os.DeadObjectException;
import android.util.Log;
/** Class to help safely run a callback in a different thread. */
@@ -49,7 +50,7 @@
try {
mListener.onCalling(session);
} catch (Throwable t) {
- Log.w(TAG, "onCalling()", t);
+ handle(t, "onCalling()");
}
}
});
@@ -63,7 +64,7 @@
try {
mListener.onRinging(session, caller, sessionDescription);
} catch (Throwable t) {
- Log.w(TAG, "onRinging()", t);
+ handle(t, "onRinging()");
}
}
});
@@ -76,7 +77,7 @@
try {
mListener.onRingingBack(session);
} catch (Throwable t) {
- Log.w(TAG, "onRingingBack()", t);
+ handle(t, "onRingingBack()");
}
}
});
@@ -90,7 +91,7 @@
try {
mListener.onCallEstablished(session, sessionDescription);
} catch (Throwable t) {
- Log.w(TAG, "onCallEstablished()", t);
+ handle(t, "onCallEstablished()");
}
}
});
@@ -103,7 +104,7 @@
try {
mListener.onCallEnded(session);
} catch (Throwable t) {
- Log.w(TAG, "onCallEnded()", t);
+ handle(t, "onCallEnded()");
}
}
});
@@ -116,7 +117,7 @@
try {
mListener.onCallBusy(session);
} catch (Throwable t) {
- Log.w(TAG, "onCallBusy()", t);
+ handle(t, "onCallBusy()");
}
}
});
@@ -130,7 +131,7 @@
try {
mListener.onCallChangeFailed(session, className, message);
} catch (Throwable t) {
- Log.w(TAG, "onCallChangeFailed()", t);
+ handle(t, "onCallChangeFailed()");
}
}
});
@@ -144,7 +145,7 @@
try {
mListener.onError(session, className, message);
} catch (Throwable t) {
- Log.w(TAG, "onError()", t);
+ handle(t, "onError()");
}
}
});
@@ -157,7 +158,7 @@
try {
mListener.onRegistering(session);
} catch (Throwable t) {
- Log.w(TAG, "onRegistering()", t);
+ handle(t, "onRegistering()");
}
}
});
@@ -171,7 +172,7 @@
try {
mListener.onRegistrationDone(session, duration);
} catch (Throwable t) {
- Log.w(TAG, "onRegistrationDone()", t);
+ handle(t, "onRegistrationDone()");
}
}
});
@@ -185,7 +186,7 @@
try {
mListener.onRegistrationFailed(session, className, message);
} catch (Throwable t) {
- Log.w(TAG, "onRegistrationFailed()", t);
+ handle(t, "onRegistrationFailed()");
}
}
});
@@ -198,9 +199,19 @@
try {
mListener.onRegistrationTimeout(session);
} catch (Throwable t) {
- Log.w(TAG, "onRegistrationTimeout()", t);
+ handle(t, "onRegistrationTimeout()");
}
}
});
}
+
+ private void handle(Throwable t, String message) {
+ if (t instanceof DeadObjectException) {
+ mListener = null;
+ // This creates race but it's harmless. Just don't log the error
+ // when it happens.
+ } else if (mListener != null) {
+ Log.w(TAG, message, t);
+ }
+ }
}