diff options
| author | Dianne Hackborn <hackbod@google.com> | 2017-06-14 17:30:15 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2017-06-14 17:33:41 -0700 |
| commit | cb01563d7efa5689abb98fe4e5d8cc86bfc2b6fc (patch) | |
| tree | 25ab0816698a39d33c70dbca3a060f64b3940e94 /core/java | |
| parent | d27d5d9ea8cd50d82d0cc9d332439535da1c1962 (diff) | |
Work on issue #36891897: Need to ensure foreground services...
...can't hide themselves
Tune the policies for when we tell about apps running in the
background after their services have stopped.
- If it ran while the screen was on, the time we require for it
to be running is much shorter (a couple seconds) as well as the
time we tell about it having run (with another tunable for the
minimum time we tell about this).
- If it has only run while the screen is off and stops a sufficient
amount of time before the screen goes on (currently a second) then
we will not show anything when the screen goes on.
- If it stops when the screen turns on, we will make sure the user
sees about it for a short period of time (currently 5 seconds).
Also includes some improved debug output about handler message
queues.
Test: manual
Change-Id: Iab438410d7182b2dfe4f9c1cce7069b26b34834c
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/os/Handler.java | 20 | ||||
| -rw-r--r-- | core/java/android/os/Looper.java | 15 | ||||
| -rw-r--r-- | core/java/android/os/MessageQueue.java | 23 | ||||
| -rwxr-xr-x | core/java/android/provider/Settings.java | 5 |
4 files changed, 59 insertions, 4 deletions
diff --git a/core/java/android/os/Handler.java b/core/java/android/os/Handler.java index 8678d95db17d..b69a23aa5854 100644 --- a/core/java/android/os/Handler.java +++ b/core/java/android/os/Handler.java @@ -696,6 +696,14 @@ public class Handler { } /** + * Return whether there are any messages or callbacks currently scheduled on this handler. + * @hide + */ + public final boolean hasMessagesOrCallbacks() { + return mQueue.hasMessages(this); + } + + /** * Check if there are any pending posts of messages with code 'what' and * whose obj is 'object' in the message queue. */ @@ -728,6 +736,18 @@ public class Handler { } } + /** + * @hide + */ + public final void dumpMine(Printer pw, String prefix) { + pw.println(prefix + this + " @ " + SystemClock.uptimeMillis()); + if (mLooper == null) { + pw.println(prefix + "looper uninitialized"); + } else { + mLooper.dump(pw, prefix + " ", this); + } + } + @Override public String toString() { return "Handler (" + getClass().getName() + ") {" diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java index 44dbcfb09582..04cceb8e80ba 100644 --- a/core/java/android/os/Looper.java +++ b/core/java/android/os/Looper.java @@ -310,7 +310,20 @@ public final class Looper { */ public void dump(@NonNull Printer pw, @NonNull String prefix) { pw.println(prefix + toString()); - mQueue.dump(pw, prefix + " "); + mQueue.dump(pw, prefix + " ", null); + } + + /** + * Dumps the state of the looper for debugging purposes. + * + * @param pw A printer to receive the contents of the dump. + * @param prefix A prefix to prepend to each line which is printed. + * @param handler Only dump messages for this Handler. + * @hide + */ + public void dump(@NonNull Printer pw, @NonNull String prefix, Handler handler) { + pw.println(prefix + toString()); + mQueue.dump(pw, prefix + " ", handler); } /** @hide */ diff --git a/core/java/android/os/MessageQueue.java b/core/java/android/os/MessageQueue.java index 2a8c52e92c60..624e28a67ae6 100644 --- a/core/java/android/os/MessageQueue.java +++ b/core/java/android/os/MessageQueue.java @@ -620,6 +620,23 @@ public final class MessageQueue { } } + boolean hasMessages(Handler h) { + if (h == null) { + return false; + } + + synchronized (this) { + Message p = mMessages; + while (p != null) { + if (p.target == h) { + return true; + } + p = p.next; + } + return false; + } + } + void removeMessages(Handler h, int what, Object object) { if (h == null) { return; @@ -759,12 +776,14 @@ public final class MessageQueue { } } - void dump(Printer pw, String prefix) { + void dump(Printer pw, String prefix, Handler h) { synchronized (this) { long now = SystemClock.uptimeMillis(); int n = 0; for (Message msg = mMessages; msg != null; msg = msg.next) { - pw.println(prefix + "Message " + n + ": " + msg.toString(now)); + if (h == null || h == msg.target) { + pw.println(prefix + "Message " + n + ": " + msg.toString(now)); + } n++; } pw.println(prefix + "(Total messages: " + n + ", polling=" + isPollingLocked() diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index f1ce9d52e920..65669ee70216 100755 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -9029,7 +9029,10 @@ public final class Settings { * <pre> * max_cached_processes (int) * background_settle_time (long) - * foreground_service_ui_min_time (long) + * fgservice_min_shown_time (long) + * fgservice_min_report_time (long) + * fgservice_screen_on_before_time (long) + * fgservice_screen_on_after_time (long) * content_provider_retain_time (long) * gc_timeout (long) * gc_min_interval (long) |
