diff options
| author | Zim <zezeozue@google.com> | 2021-02-23 12:16:50 +0000 |
|---|---|---|
| committer | Zim <zezeozue@google.com> | 2021-02-24 09:34:03 +0000 |
| commit | 465e3b7115ac8974cae42cdf7b4e3896504ca9bc (patch) | |
| tree | d887ab5f1a9241add80e0f8765410282e63db87e /core/java/android/app/AnrController.java | |
| parent | 59536a1edb3c2746ca3a02131ca6139e79724d54 (diff) | |
Extend AnrController to improve ANR dialog controls
I5431d22bd8faa75e3deab1960a2f721784f98d42 introduced a basic ANR
controller interface to allow services within the system_server
register to delay the ANR dialog during an ANR.
Some limitations of that interface were:
1. No way to cancel the ANR dialog if the normal function of the app
resumed during the delay
2. The AnrController#getAnrDelay method was serving a dual purpose of
returning the delay and showing an interim UI
3. The interim UI might live within an updatable mainline
module, hence forcing the system_server to block (asynchronously) on
the 'getter' for the binder call.
This cl addresses the problems above with the following new
methods on AnrController: onAnrDelayStarted and onAnrDelayCompleted.
These methods provide a clearer interface for the following reasons:
1. onAnrDelayCompleted will return a boolean value to indicate whether
the ANR dialog should still be shown after the delay
2. onAnrDelayStarted is a more explicit API that can be called
asynchronously without blocking to notify external components to show
an interim UI
3. The existing getAnrDelay can be handled completely within the
system_server without blocking on an external binder call
See design (2a) in go/transcoding-anrs for more details
Test: Manual
Bug: 170486601
Change-Id: Idb9190a0e6014ce64bf1412c26f6ae03f97e922d
Diffstat (limited to 'core/java/android/app/AnrController.java')
| -rw-r--r-- | core/java/android/app/AnrController.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/core/java/android/app/AnrController.java b/core/java/android/app/AnrController.java index cfc9d2715720..a0d4b3a6a753 100644 --- a/core/java/android/app/AnrController.java +++ b/core/java/android/app/AnrController.java @@ -23,7 +23,29 @@ package android.app; public interface AnrController { /** * Returns the delay in milliseconds for an ANR dialog that is about to be shown for - * {@code packageName}. + * {@code packageName} with {@code uid}. + * + * Implementations should only return a positive value if they actually expect the + * {@code packageName} to be delayed due to them. + + * If there are multiple controllers registered, the controller with the max delay will + * be selected and will receive an {@link #onAnrDelayStarted} callback at the start of the + * delay and an {@link #onAnrDelayCompleted} at the end of the delay. */ long getAnrDelayMillis(String packageName, int uid); + + /** + * Notifies the controller at the start of the ANR dialog delay for {@code packageName} with + * {@code uid}. The controller can decide to show a progress UI after this notification. + */ + void onAnrDelayStarted(String packageName, int uid); + + /** + * Notifies the controller at the end of the ANR dialog delay for {@code packageName} with + * {@code uid}. + * + * @return whether the ANR dialog should be shown or cancelled. {@code true} if the + * ANR dialog should be shown, {@code false} if it should be cancelled. + */ + boolean onAnrDelayCompleted(String packageName, int uid); } |
