-
问题现象:我的一个系统级别的服务收不到亮灭屏广播了
-
刚开始怀疑广播没发出来,加了一些log之后发现广播是发出去了
再次怀疑系统挂了,但是我操作设置界面都正常
最后怀疑系统服务anr了。导出来anr目录下的log,证实了我的猜想,系统服务anr了,而且是一个比较经典的死锁
"main" prio=5 tid=1 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x718613c8 self=0x787fef0c00
| sysTid=10206 nice=-2 cgrp=default sched=0/0 handle=0x7881458ed0
| state=S schedstat=( 3115368842 2572364152 17598 ) utm=229 stm=82 core=3 HZ=100
| stack=0x7ffab44000-0x7ffab46000 stackSize=8192KB
| held mutexes=
at com.android.server.BatteryService$LocalService.forceUpdatebattery(BatteryService.java:1323)
- waiting to lock <0x0314588f> (a java.lang.Object) held by thread 108
at com.android.server.lights.jioLedMangerService.PowerStateChanged(jioLedMangerService.java:357)
at com.android.server.lights.jioLedMangerService.triggerLedEvent(jioLedMangerService.java:534)
- locked <0x003f771c> (a com.android.server.lights.jioLedMangerService)
at com.android.server.lights.jioLedMangerService$1.onReceive(jioLedMangerService.java:176)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1550)
at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(lambda:-1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at com.android.server.SystemServer.run(SystemServer.java:554)
at com.android.server.SystemServer.main(SystemServer.java:362)
at java.lang.reflect.Method.invoke(Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:913)
"HwBinder:10206_3" prio=5 tid=108 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x137c4a18 self=0x77312b8000
| sysTid=10492 nice=-2 cgrp=default sched=0/0 handle=0x7727e69d50
| state=S schedstat=( 80180773 149114941 443 ) utm=4 stm=3 core=0 HZ=100
| stack=0x7727d73000-0x7727d75000 stackSize=991KB
| held mutexes=
at com.android.server.lights.jioLedMangerService.updateBatteryLightsLocked(jioLedMangerService.java:223)
- waiting to lock <0x003f771c> (a com.android.server.lights.jioLedMangerService) held by thread 1
at invision.led.JioLedManger.updateBatteryLightsLocked(JioLedManger.java:122)
at invision.led.JioLedMangerGlobal.updateBatteryLightsLocked(JioLedMangerGlobal.java:191)
at com.android.server.BatteryService.processValuesLocked(BatteryService.java:669)
at com.android.server.BatteryService.update(BatteryService.java:441)
- locked <0x0314588f> (a java.lang.Object)
at com.android.server.BatteryService.access$1100(BatteryService.java:119)
at com.android.server.BatteryService$HealthHalCallback.healthInfoChanged(BatteryService.java:1145)
at android.hardware.health.V2_0.IHealthInfoCallback$Stub.onTransact(IHealthInfoCallback.java:440)
-
分析
tid=1 jioLedMangerService 调用triggerLedEvent 的时候获得 0x003f771c 锁,当执行到forceUpdatebattery的时候想要获取 0x0314588f 锁 发现被 tid=108 持有 只能等着
tid=108 BatteryService 调用update电量的时候获得 0x0314588f 锁, 当执行到 updateBatteryLightsLocked的时候想要获取 0x003f771c 锁 发现被tid=1 持有 只能等着 -
解决:
关闭一些没必要的锁
网友评论