Prevent Dropbox from crashing system server pre-boot.

Bug: 3362748
Change-Id: I3f94f22798eb4a6ef14dd9a418fd3c054637e16b
diff --git a/services/java/com/android/server/DropBoxManagerService.java b/services/java/com/android/server/DropBoxManagerService.java
index 4305c358..5c878c9 100644
--- a/services/java/com/android/server/DropBoxManagerService.java
+++ b/services/java/com/android/server/DropBoxManagerService.java
@@ -97,10 +97,18 @@
     // Ensure that all log entries have a unique timestamp
     private long mLastTimestamp = 0;
 
+    private volatile boolean mBooted = false;
+
     /** Receives events that might indicate a need to clean up files. */
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
+            if (intent != null && Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
+                mBooted = true;
+                return;
+            }
+
+            // Else, for ACTION_DEVICE_STORAGE_LOW:
             mCachedQuotaUptimeMillis = 0;  // Force a re-check of quota size
 
             // Run the initialization in the background (not this main thread).
@@ -132,7 +140,11 @@
         // Set up intent receivers
         mContext = context;
         mContentResolver = context.getContentResolver();
-        context.registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW));
+
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
+        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
+        context.registerReceiver(mReceiver, filter);
 
         mContentResolver.registerContentObserver(
             Settings.Secure.CONTENT_URI, true,
@@ -224,6 +236,9 @@
             Intent dropboxIntent = new Intent(DropBoxManager.ACTION_DROPBOX_ENTRY_ADDED);
             dropboxIntent.putExtra(DropBoxManager.EXTRA_TAG, tag);
             dropboxIntent.putExtra(DropBoxManager.EXTRA_TIME, time);
+            if (!mBooted) {
+                dropboxIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+            }
             mContext.sendBroadcast(dropboxIntent, android.Manifest.permission.READ_LOGS);
 
         } catch (IOException e) {