Skip to content

Commit 0abe556

Browse files
committed
Handle SCREEN_ON/OFF broadcasts without blocking.
NetworkPolicy currently uses a single background thread to process various broadcasts. When processing other broadcasts, this thread can block our handling of SCREEN_ON/OFF, which are sent as ordered broadcasts. This change moves SCREEN_ON/OFF handling to the main thread, and dispatches a one-way message to the background thread, allowing the ordered broadcast to always proceed. Bug: 6677047 Change-Id: I52de2c7b75beb8059bb87e123689ba4a9c4ae349
1 parent fe54cb6 commit 0abe556

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

services/java/com/android/server/net/NetworkPolicyManagerService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
225225
private static final int MSG_LIMIT_REACHED = 5;
226226
private static final int MSG_RESTRICT_BACKGROUND_CHANGED = 6;
227227
private static final int MSG_ADVISE_PERSIST_THRESHOLD = 7;
228+
private static final int MSG_SCREEN_ON_CHANGED = 8;
228229

229230
private final Context mContext;
230231
private final IActivityManager mActivityManager;
@@ -349,7 +350,7 @@ public void systemReady() {
349350
final IntentFilter screenFilter = new IntentFilter();
350351
screenFilter.addAction(Intent.ACTION_SCREEN_ON);
351352
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
352-
mContext.registerReceiver(mScreenReceiver, screenFilter, null, mHandler);
353+
mContext.registerReceiver(mScreenReceiver, screenFilter);
353354

354355
// watch for network interfaces to be claimed
355356
final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION_IMMEDIATE);
@@ -411,7 +412,7 @@ public void onReceive(Context context, Intent intent) {
411412
synchronized (mRulesLock) {
412413
// screen-related broadcasts are protected by system, no need
413414
// for permissions check.
414-
updateScreenOn();
415+
mHandler.obtainMessage(MSG_SCREEN_ON_CHANGED).sendToTarget();
415416
}
416417
}
417418
};
@@ -1878,6 +1879,10 @@ public boolean handleMessage(Message msg) {
18781879
}
18791880
return true;
18801881
}
1882+
case MSG_SCREEN_ON_CHANGED: {
1883+
updateScreenOn();
1884+
return true;
1885+
}
18811886
default: {
18821887
return false;
18831888
}

0 commit comments

Comments
 (0)