Android开机启动app导致电源管理无法启动

2019-07-13 23:03发布

一、问题现象:       公司app在开机的时候自启,但是屏幕超时后不会灭屏。如果返回主界面后,屏幕就能灭屏。 二、问题分析和问题解决:      利用usb打印调试log,对比装了app和不装app的区别,不装app会提示“android.intent.action.BOOT_COMPLETED”      开启WindowManager 里的调试模式可以看到更多的信息:
10-26 11:58:29.360: I/WindowManager(1563): enableScreenIfNeededLocked: mDisplayEnabled=true mForceDisplayEnabled=false mShowingBootMessages=false mSystemBooted=true 10-26 11:58:30.570: D/AlertReceiver(2215): onReceive: a=android.intent.action.BOOT_COMPLETED Intent { act=android.intent.action.BOOT_COMPLETED flg=0x8000010 cmp=com.android.calendar/.alerts.AlertReceiver (has extras) } 10-26 11:58:30.580: D/AlertService(2215): 0 Action = android.intent.action.BOOT_COMPLETED 10-26 11:58:30.905: V/AlarmClock(2235): AlarmInitReceiver android.intent.action.BOOT_COMPLETED 10-26 11:58:31.425: I/LauncherIconVisibilityManager(1706): Boot has been completed 10-26 11:58:31.475: I/ActivityManager(1563): Start proc com.googlecode.eyesfree.setorientation for broadcast com.googlecode.eyesfree.setorientation/.BootReceiver: pid=2285 uid=10047 gids={50047}
再分析公司app启动的两种方式:1、通过android.intent.action.BOOT_COMPLETED 来让app自启。 android:name=".StartReceiver">
2.通过usb设备接入检测,来达到自动启动的目的。我把BOOT_COMPLETED自启部分代码屏蔽掉,app还是可以自启;那么把usb接入检测屏蔽掉,app应该不会自启了吧 果然如此,原来app在系统启动的时候检测到有usb设备接入,就立即启动了app,然后没阻塞了系统BOOT_COMPLETED广播的传播,导致安卓系统一些服务没有正常的启动,电源管理也没启动,最终使得系统无法自动待机。 正常待机的调试信息如下: 10-23 15:51:50.031 1559-1584/system_process I/PowerManagerService: Going to sleep due to screen timeout... 10-23 15:51:59.836 1559-1588/system_process I/PowerManagerService: Waking up from sleep... 10-23 15:51:59.901 1559-1584/system_process D/DisplayPowerController: Unblocked screen on after 1237564 ms 10-23 15:52:00.736 1559-1625/system_process D/PowerManagerService-JNI: Excessive delay in autosuspend_disable() while turning screen on: 889ms