Reorder USB_STATE updates so config_changed is not replaced.

Because of flag INTENT.ACTION_REPLACE_PENDING, intents
sent in rapid succession could replace previous intents
that have not been processed, and it is unreliable when
or whether this happens. Since CONFIG_CHANGED cannot afford
to be lost, make sure it is sent last, so it is always
processed.

Bug: 34873000
Test: lots of unplugging/plugging
Change-Id: I9264d5129139cf3f433bbcd068e8b292fec6cd31
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index a597b12..7737340 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -909,18 +909,20 @@
 
                     updateUsbNotification(false);
                     updateAdbNotification(false);
+                    if (mBootCompleted) {
+                        Slog.i(TAG, "update state " + mConnected + " " + mConfigured);
+                        updateUsbStateBroadcastIfNeeded(false);
+                    }
                     if (UsbManager.containsFunction(mCurrentFunctions,
                             UsbManager.USB_FUNCTION_ACCESSORY)) {
                         updateCurrentAccessory();
                     }
                     if (mBootCompleted) {
-                        Slog.i(TAG, "update state " + mConnected + " " + mConfigured);
                         if (!mConnected) {
                             // restore defaults when USB is disconnected
                             Slog.i(TAG, "Disconnect, setting usb functions to null");
                             setEnabledFunctions(null, false, false);
                         }
-                        updateUsbStateBroadcastIfNeeded(false);
                         updateUsbFunctions();
                     } else {
                         mPendingBootBroadcast = true;