OSDN Git Service

Defer broadcasts to slow-handling apps
authorChristopher Tate <ctate@google.com>
Fri, 18 Jan 2019 00:58:31 +0000 (16:58 -0800)
committerChristopher Tate <ctate@google.com>
Mon, 28 Jan 2019 20:32:41 +0000 (12:32 -0800)
commit2f558d2659cf1c13c1672f93e7dd420cb887e8d3
tree114b85c0e66da27465cd4d4e013a2348d38f5e41
parent97bd994bb02a52de40725c09c14f62f6ed1bfaeb
Defer broadcasts to slow-handling apps

When an app takes a long time to handle broadcasts, we start deferring
further broadcasts to it to make sure that other broadcast traffic in
the system can continue to make progress.  Global delivery order is
technically rearranged, but delivery order from the point of view of any
given app remains consistent with issuance order.

When alarm broadcasts are issued, we prioritize delivery of deferred
alarms to the alarm recipients (i.e. we suspend the deferral policy and
catch up as promptly as possible) in order to minimize wake time spent
waiting for the alarm broadcast to be delivered.  Once an app with a
deferred broadcast backlog is no longer the target of an in-flight
alarm, we re-impose deferral policy on it.

This policy intentionally trades off increased broadcast delivery
latency to apps that take a "long" time to handle broadcasts, in
exchange for lowering delivery latency to all other apps in the system
that would previously have had to wait behind the slow app.

In addition, broadcast dispatch policy parameters can now be overlaid
via the usual global Settings mechanism.  In particular, configuring the
"bcast_slow_time" parameter to a value in milliseconds higher than the
queue's broadcast timeout period will disable the new slow-receiver
policies.

Bug: 111404343
Test: device boots & runs
Test: tests/ActivityTests
Change-Id: I76ac79bdf41ca3cfcc48515bca779ea0f5744c0b
15 files changed:
core/java/android/app/IActivityManager.aidl
core/java/android/app/PendingIntent.java
core/java/android/provider/Settings.java
core/tests/coretests/src/android/provider/SettingsBackupTest.java
services/core/java/com/android/server/AlarmManagerInternal.java
services/core/java/com/android/server/AlarmManagerService.java
services/core/java/com/android/server/am/ActivityManagerDebugConfig.java
services/core/java/com/android/server/am/ActivityManagerService.java
services/core/java/com/android/server/am/BroadcastConstants.java [new file with mode: 0644]
services/core/java/com/android/server/am/BroadcastDispatcher.java [new file with mode: 0644]
services/core/java/com/android/server/am/BroadcastQueue.java
services/core/java/com/android/server/am/BroadcastRecord.java
tests/ActivityTests/AndroidManifest.xml
tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
tests/ActivityTests/src/com/google/android/test/activity/SlowReceiver.java [new file with mode: 0644]