From 0464c07a9e3f45091d1f9834788646bc8e4a217d Mon Sep 17 00:00:00 2001 From: Johan Redestig Date: Sat, 18 Jan 2014 22:46:56 +0100 Subject: [PATCH] Only send storage intents after boot complete It is not possible to send a broadcast before the system boot is completed. If you do it anyway you will get an IllegalStateException: Cannot broadcast before boot completed. If a memory card is inserted or removed while the phone is booting up, there is a risk that the MountService will try to broadcast a storage intent too early, and cause the device to crash. Use FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT to avoid problems with too early broadcasts. Change-Id: Ied36a13d235df37c9788e45a35de40d919ae0cd0 --- services/java/com/android/server/MountService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index 0d535cc7634a..816ae6967cfd 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -877,7 +877,7 @@ class MountService extends IMountService.Stub /* Send the media unmounted event first */ if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first"); updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED); - sendStorageIntent(Environment.MEDIA_UNMOUNTED, volume, UserHandle.ALL); + sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL); if (DEBUG_EVENTS) Slog.i(TAG, "Sending media removed"); updatePublicVolumeState(volume, Environment.MEDIA_REMOVED); @@ -1164,6 +1164,7 @@ class MountService extends IMountService.Stub private void sendStorageIntent(String action, StorageVolume volume, UserHandle user) { final Intent intent = new Intent(action, Uri.parse("file://" + volume.getPath())); intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, volume); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); Slog.d(TAG, "sendStorageIntent " + intent + " to " + user); mContext.sendBroadcastAsUser(intent, user); } -- 2.11.0