Merge changes from topic "b-186518774" into sc-v2-dev-plus-aosp

* changes:
  [automerge] DO NOT MERGE Re-restrict phone ops on user addition 2p: 7fac473e33
  DO NOT MERGE Re-restrict phone ops on user addition
diff --git a/src/com/android/server/telecom/RespondViaSmsSettings.java b/src/com/android/server/telecom/RespondViaSmsSettings.java
old mode 100644
new mode 100755
index 6d7c5c6..661038b
--- a/src/com/android/server/telecom/RespondViaSmsSettings.java
+++ b/src/com/android/server/telecom/RespondViaSmsSettings.java
@@ -99,7 +99,7 @@
         Log.d(this, "  preference = '%s'", preference);
         Log.d(this, "  newValue = '%s'", newValue);
 
-        EditTextPreference pref = (EditTextPreference) preference;
+        EditTextPreference pref = (EditTextPreference)findPreference(preference.getKey());
 
         // Copy the new text over to the title, just like in onCreate().
         // (Watch out: onPreferenceChange() is called *before* the
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() {
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothStateReceiver.java b/src/com/android/server/telecom/bluetooth/BluetoothStateReceiver.java
index 49489f4..17da806 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothStateReceiver.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothStateReceiver.java
@@ -184,6 +184,16 @@
                     return;
                 }
                 args.arg2 = device.getAddress();
+
+                if (deviceType == BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO) {
+                    /* In Le Audio case, once device got Active, the Telecom needs to make sure it
+                     * is set as communication device before we can say that BT_AUDIO_IS_ON
+                     */
+                    if (!mBluetoothDeviceManager.setLeAudioCommunicationDevice()) {
+                        Log.w(LOG_TAG, "Device %s cannot be use as communication device.", device);
+                        return;
+                    }
+                }
                 mBluetoothRouteManager.sendMessage(BT_AUDIO_IS_ON, args);
            }
         }