hal: Update output device to speaker on USB disconnect

If USB device is disconnected and reconnected quickly and
music playback is started, there is a race condition where
sound device and audio route for USB are not being disabled
and reenabled. This results in no audio on USB.

Unplugging and replugging the USB device without disabling
USB sound device leaves the driver in a bad state.

AudioPolicyManager sends routing to speaker on a disconnect
which causes a device switch. USB sound device is disabled in
audio HAL and reference count is set to zero.

In failure scenario, audio HAL does not receive routing to
speaker. Policy manager sends routing to USB as the device is
now available. Since USB sound device is already active, it is
not reenabled.

Fix this problem by selecting speaker on receiving a USB device
disconnect. This results in a device switch as soon as USB is
disconnected and USB sound device is disabled.

Bug: 111315812
Test: repro steps in bug.
Change-Id: I7fb0813792ea95f9d47da96a57ab3b3895a47776
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 2caad10..7300906 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2528,10 +2528,13 @@
         // otherwise audio is no longer played on the new usb devices.
         // By forcing the stream in standby, the usb stack refcount drops to 0
         // and the driver is closed.
-        if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD && val == AUDIO_DEVICE_NONE &&
+        if (val == AUDIO_DEVICE_NONE &&
                 audio_is_usb_out_device(out->devices)) {
-            ALOGD("%s() putting the usb device in standby after disconnection", __func__);
-            out_standby_l(&out->stream.common);
+            if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
+                ALOGD("%s() putting the usb device in standby after disconnection", __func__);
+                out_standby_l(&out->stream.common);
+            }
+            val = AUDIO_DEVICE_OUT_SPEAKER;
         }
 
         pthread_mutex_lock(&adev->lock);