Why mScreenReceiver in NetworkPolicyManagerService not running in its HandlerThread?

已查看 42 次
跳至第一个未读帖子

sharon.hou

未读,
2012年12月2日 12:43:282012/12/2
收件人 android-...@googlegroups.com
Hi,

Does anyone know why mScreenReceiver in NetworkPolicyManagerService is not running in its HandlerThread?  Instead it is running in SystemServer server  thread.  I can see some SystemServer watchdog trigger since this receiver stuck on waiting the mRulesLock which was occasionally held by other api call. 

Do you see any impact if remove the mRulesLock from below code part?

    private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            synchronized (mRulesLock) {     // ANY IMPACT from  REMOVED this LOCK here ??
                // screen-related broadcasts are protected by system, no need
                // for permissions check.
                mHandler.obtainMessage(MSG_SCREEN_ON_CHANGED).sendToTarget();
            }
        }
    };

The trace:
"android.server.ServerThread" prio=5 tid=11 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x41680f00 self=0x50d3c4e8
  | sysTid=20115 nice=-2 sched=0/0 cgrp=apps handle=1326678472
  | schedstat=( 0 0 0 ) utm=552 stm=131 core=1
  at com.android.server.net.NetworkPolicyManagerService$2.onReceive(NetworkPolicyManagerService.java:~412)
  - waiting to lock <0x41a25018> (a java.lang.Object) held by tid=46 (NetworkPolicy)
  at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:757)
  at android.os.Handler.handleCallback(Handler.java:615)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:137)
  at com.android.server.ServerThread.run(SystemServer.java:1054)

Regards
Sharon

Jeff Sharkey

未读,
2012年12月3日 15:40:562012/12/3
收件人 android-...@googlegroups.com
Screen broadcasts are special since they are ordered. If
registerReceiver() pushed them directly onto mHandler, the screen
broadcasts could be held up by other mHandler messages. This is why
it's sending MSG_SCREEN_ON_CHANGED and allowing the broadcast to
finish quickly.

You're absolutely right that it doesn't need to acquire the lock just
to send the message; I'll submit a fix.

j
> --
> You received this message because you are subscribed to the Google Groups
> "android-platform" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-platform/-/bPR2kYWzHgsJ.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-platfo...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-platform?hl=en.



--
Jeff Sharkey
jsha...@android.com

sharon.hou

未读,
2012年12月4日 00:59:592012/12/4
收件人 android-...@googlegroups.com
Got your point. Thanks for the quick update.

Sharon
回复全部
回复作者
转发
0 个新帖子