Handle null bindings returned from ConnectionService. am: 410ce02600 am: 86f45ae8c0 am: df451bd586 am: f5efe09836 am: d1aeb51529

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/17104573

Change-Id: I81319f639cdd0fe12faecf60a1b7936d4df1ca49
diff --git a/src/com/android/server/telecom/ServiceBinder.java b/src/com/android/server/telecom/ServiceBinder.java
index aa2e2a2..7274993 100644
--- a/src/com/android/server/telecom/ServiceBinder.java
+++ b/src/com/android/server/telecom/ServiceBinder.java
@@ -150,7 +150,6 @@
                     Log.i(this, "Service bound %s", componentName);
 
                     Log.addEvent(mCall, LogUtils.Events.CS_BOUND, componentName);
-                    mCall = null;
 
                     // Unbind request was queued so unbind immediately.
                     if (mIsBindingAborted) {
@@ -192,6 +191,30 @@
                 Log.endSession();
             }
         }
+
+        /**
+         * Handles the case where the {@link ConnectionService} we bound to returned a null binding.
+         * We want to unbind from the service and cleanup and call resources at this time.
+         * @param componentName The component of the {@link ConnectionService}.
+         */
+        @Override
+        public void onNullBinding(ComponentName componentName) {
+            try {
+                Log.startSession("SBC.oNB");
+                synchronized (mLock) {
+                    Log.w(this, "Null binding %s", componentName);
+                    Log.addEvent(mCall, "NULL_BINDING", componentName);
+                    String componentStr = componentName == null ? "null" : componentName.toString();
+                    android.util.EventLog.writeEvent(0x534e4554, "211114016", -1, componentStr);
+                    logServiceDisconnected("onNullBinding");
+                    mContext.unbindService(this);
+                    clearAbort();
+                    handleFailedConnection();
+                }
+            } finally {
+                Log.endSession();
+            }
+        }
     }
 
     private void handleDisconnect() {