Configure Mtp once on boot.

It is possible that UsbDeviceManager ends up
sending USB_STATE intents during a time when
MtpReceiver cannot start to process them.
In these cases, mtp will never be configured.

To fix, configure once on boot regardless. This
will be harmless if Mtp is already configured
since the additional configure will do nothing,
or if Mtp is not enabled.

Bug: 64197549
Test: set require pass on boot -> reboot -> unlock -> plug in -> verify
Test: unset require pass on boot -> reboot -> unlock -> plug in ->
Test: above two tests with usb debugging on/off
Change-Id: I5a96078c2ebb6517e226adedd0f0ca8fb09c15c2
(cherry picked from commit a21c1f467f3b5b535add6f7249fa0c28a7758e55)
diff --git a/src/com/android/providers/media/ b/src/com/android/providers/media/
index 0895c5e..5f38018 100644
--- a/src/com/android/providers/media/
+++ b/src/com/android/providers/media/
@@ -36,6 +36,10 @@
     public void onReceive(Context context, Intent intent) {
         final String action = intent.getAction();
         if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
+            // If we somehow fail to configure after boot, it becomes difficult to
+            // recover usb state. Thus we always configure once on boot, but it
+            // has no effect if Mtp is disabled or already configured.
+            MtpServer.configure(false);
             final Intent usbState = context.registerReceiver(
                     null, new IntentFilter(UsbManager.ACTION_USB_STATE));
             if (usbState != null) {