Why mScreenReceiver in NetworkPolicyManagerService not running in its HandlerThread?

42 views
Skip to first unread message

sharon.hou

unread,
Dec 2, 2012, 12:43:28 PM12/2/12
to 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

unread,
Dec 3, 2012, 3:40:56 PM12/3/12
to 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

unread,
Dec 4, 2012, 12:59:59 AM12/4/12
to android-...@googlegroups.com
Got your point. Thanks for the quick update.

Sharon
Reply all
Reply to author
Forward
0 new messages