java.lang.IllegalStateException: Cannot broadcast before boot completed
出现该错误的一个操作时,开机时多次插拔耳机,表现为关机动画重复播放。详细的错误信息为:
02-05 19:13:50.219 V/HeadsetObserver( 170): Headset UEVENT: {SUBSYSTEM=switch, SWITCH_STATE=0, DEVPATH=/devices/virtual/switch/h2w, SEQNUM=1390, ACTION=change, SWITCH_NAME=No Device}
02-05 19:13:50.219 E/ActivityManager( 170): Attempt to launch receivers of broadcast intent Intent { act=android.media.AUDIO_BECOMING_NOISY } before boot completion
02-05 19:13:50.219 W/Vold ( 90): Ignoring unknown switch 'No Device'
02-05 19:13:50.229 E/AndroidRuntime( 170): *** FATAL EXCEPTION IN SYSTEM PROCESS: UEventObserver
02-05 19:13:50.229 E/AndroidRuntime( 170): java.lang.IllegalStateException: Cannot broadcast before boot completed
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.am.ActivityManagerService.verifyBroadcastLocked(ActivityManagerService.java:10549)
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:10566)
02-05 19:13:50.229 E/AndroidRuntime( 170): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:663)
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.HeadsetObserver.update(HeadsetObserver.java:132)
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.HeadsetObserver.onUEvent(HeadsetObserver.java:85)
02-05 19:13:50.229 E/AndroidRuntime( 170): at android.os.UEventObserver$UEventThread.run(UEventObserver.java:108)
02-05 19:13:50.219 E/ActivityManager( 170): Attempt to launch receivers of broadcast intent Intent { act=android.media.AUDIO_BECOMING_NOISY } before boot completion
02-05 19:13:50.219 W/Vold ( 90): Ignoring unknown switch 'No Device'
02-05 19:13:50.229 E/AndroidRuntime( 170): *** FATAL EXCEPTION IN SYSTEM PROCESS: UEventObserver
02-05 19:13:50.229 E/AndroidRuntime( 170): java.lang.IllegalStateException: Cannot broadcast before boot completed
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.am.ActivityManagerService.verifyBroadcastLocked(ActivityManagerService.java:10549)
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:10566)
02-05 19:13:50.229 E/AndroidRuntime( 170): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:663)
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.HeadsetObserver.update(HeadsetObserver.java:132)
02-05 19:13:50.229 E/AndroidRuntime( 170): at com.android.server.HeadsetObserver.onUEvent(HeadsetObserver.java:85)
02-05 19:13:50.229 E/AndroidRuntime( 170): at android.os.UEventObserver$UEventThread.run(UEventObserver.java:108)
可见是android.media.AUDIO_BECOMING_NOISY的广播出现在boot completed前,并且没有注册FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT的标签,打印出该处信息的代码为am的如下方法:
final Intent verifyBroadcastLocked(Intent intent) {
// Refuse possible leaked file descriptors
if (intent != null && intent.hasFileDescriptors() == true) {
throw new IllegalArgumentException("File descriptors passed in Intent");
}
int flags = intent.getFlags();
if (!mProcessesReady) {
// if the caller really truly claims to know what they're doing, go
// ahead and allow the broadcast without launching any receivers
if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT) != 0) {
intent = new Intent(intent);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
} else if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) {
Slog.e(TAG, "Attempt to launch receivers of broadcast intent " + intent
+ " before boot completion");
throw new IllegalStateException("Cannot broadcast before boot completed");
}
}
if ((flags&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
throw new IllegalArgumentException(
"Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
}
return intent;
}
// Refuse possible leaked file descriptors
if (intent != null && intent.hasFileDescriptors() == true) {
throw new IllegalArgumentException("File descriptors passed in Intent");
}
int flags = intent.getFlags();
if (!mProcessesReady) {
// if the caller really truly claims to know what they're doing, go
// ahead and allow the broadcast without launching any receivers
if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT) != 0) {
intent = new Intent(intent);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
} else if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) {
Slog.e(TAG, "Attempt to launch receivers of broadcast intent " + intent
+ " before boot completion");
throw new IllegalStateException("Cannot broadcast before boot completed");
}
}
if ((flags&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
throw new IllegalArgumentException(
"Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
}
return intent;
}
评论:9