Catch exception for ConnectivityManager.unregisterNetworkCallback

It is possible ConnectivityManager.requestNetwork may fail silently due
to RemoteException. When that happens, we may get an invalid
NetworkCallback, which causes an IllegalArgumentexception when we try to
unregisterNetworkCallback. This exception in turn causes
MmsNetworkManager to skip the code to clean up states. Thus MMS service
would get stuck in the bad state until the device restarts. This fix
catches the exception so that state clean up can be executed.

b/24306554

Change-Id: I3c0df8dab9af0f7a7f2e647b38f5df29177b7ff8
diff --git a/src/com/android/mms/service/MmsNetworkManager.java b/src/com/android/mms/service/MmsNetworkManager.java
index ea2fa90..ed78258 100644
--- a/src/com/android/mms/service/MmsNetworkManager.java
+++ b/src/com/android/mms/service/MmsNetworkManager.java
@@ -185,7 +185,18 @@
     private void releaseRequestLocked(ConnectivityManager.NetworkCallback callback) {
         if (callback != null) {
             final ConnectivityManager connectivityManager = getConnectivityManager();
-            connectivityManager.unregisterNetworkCallback(callback);
+            try {
+                connectivityManager.unregisterNetworkCallback(callback);
+            } catch (IllegalArgumentException e) {
+                // It is possible ConnectivityManager.requestNetwork may fail silently due
+                // to RemoteException. When that happens, we may get an invalid
+                // NetworkCallback, which causes an IllegalArgumentexception when we try to
+                // unregisterNetworkCallback. This exception in turn causes
+                // MmsNetworkManager to skip resetLocked() in the below. Thus MMS service
+                // would get stuck in the bad state until the device restarts. This fix
+                // catches the exception so that state clean up can be executed.
+                LogUtil.w("Unregister network callback exception", e);
+            }
         }
         resetLocked();
     }