summaryrefslogtreecommitdiff
path: root/core/java/android/os/MessageQueue.java
Commit message (Collapse)AuthorAgeFilesLines
* Add maxTargetSdk restriction to unused APIs.Mathew Inwood2020-10-291-2/+2
| | | | | | | | | | | | | | | | | | | These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. This is a resubmit of ag/12929664 with some APIs excluded that caused test failures; see bugs 171886397, 171888296, 171864568. APIs excluded: Landroid/bluetooth/le/ScanRecord;->parseFromBytes([B)Landroid/bluetooth/le/ScanRecord; Landroid/os/Process;->myPpid()I Landroid/os/SharedMemory;->getFd()I Landroid/hardware/input/InputManager;->INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH:I Bug: 170729553 Test: Treehugger Change-Id: I8285daa8530260251ecad6f3f38f98e263629ca7
* Revert "Add maxTargetSdk restriction to unused APIs."Hongwei Wang2020-10-281-2/+2
| | | | | | | | | This reverts commit 72f07d6a8a32db4a0dedd7682a0b3385be2b9cd6. Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?testMethod=testAppZygotePreload&testClass=android.app.cts.ServiceTest&atpConfigName=suite%2Ftest-mapping-presubmit-retry_cloud-tf&testModule=CtsAppTestCases&fkbb=6936597&lkbb=6936969&lkgb=6936551&testResults=true&branch=git_master&target=cf_x86_phone-userdebug>, bug b/171886397 Bug: 171886397 Change-Id: Ibe0f0430a3451477c1ee8ef56a596e91ea1e7672
* Add maxTargetSdk restriction to unused APIs.Mathew Inwood2020-10-271-2/+2
| | | | | | | | | | These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. Bug: 170729553 Test: Treehugger Change-Id: I4c8fd0006f950de9955242e93968fb0996ceb372
* Merge "Add method in Handler to remove messages with equal object" am: ↵Automerger Merge Worker2020-03-171-0/+119
|\ | | | | | | | | | | 36216f6f23 am: ed0ddab0d7 am: f5344975fc am: 68adad7bff am: f41a6ffe30 Change-Id: I41c15086f2c747115547f84ddc22d5d0d7bd677c
| * Merge "Add method in Handler to remove messages with equal object" am: ↵Automerger Merge Worker2020-03-171-0/+119
| |\ | | | | | | | | | | | | | | | 36216f6f23 am: ed0ddab0d7 Change-Id: I36e853e01d6e9f657a931b1a64eadf1e0d82c456
| | * Add method in Handler to remove messages with equal objectfengjinlan2020-03-171-0/+119
| | | | | | | | | | | | | | | Change-Id: Ibae80f5008df54f4ac8544abb4cc5863ea3db86d Signed-off-by: fengjinlan <fengjinlan@xiaomi.com>
| | * Use new UnsupportedAppUsage annotation.Artur Satayev2020-01-131-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I534e3fd1305e2f4af076986770033478448a665c Merged-In: I534e3fd1305e2f4af076986770033478448a665c
| | * Add @UnsupportedAppUsage to test apis that are known to be used by apps.Artur Satayev2019-11-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | go/testapi-enforcement Bug: 133832325 Test: m Change-Id: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6 Merged-In: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
* | | Check the isInUse with the lock held in MessageQueueJing Ji2020-03-041-3/+4
|/ / | | | | | | | | | | | | | | | | Fix a potential race condtion when the same message object is being enqueued by two threads. Bug: 150263007 Test: atest android.os.cts.MessageQueueTest Change-Id: Id79448ba8719479cbdb054f2cdd172fdcbe86d47
* | Use new UnsupportedAppUsage annotation.Artur Satayev2019-12-181-2/+1
| | | | | | | | | | | | | | | | Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I534e3fd1305e2f4af076986770033478448a665c
* | Rename writeToProto to be dumpDebugJeffrey Huang2019-12-051-2/+2
| | | | | | | | | | | | | | | | | | We want to eventually migrate some of these APIs to be @SystemApi for mainline modules. The #dumpDebug name is more appropriate than #writeToProto. Bug: 142279786 Test: Manual Change-Id: I60793e91cedf6b720d4ecef6a8484f4fed4ff30f
* | Add @UnsupportedAppUsage to test apis that are known to be used by apps.Artur Satayev2019-11-131-0/+2
|/ | | | | | | | | go/testapi-enforcement Bug: 133832325 Test: m Change-Id: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6 Merged-In: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
* Add @UnsupportedAppUsage annotationsAndrei Onea2019-03-151-0/+10
| | | | | | | | | | | | | | | | For packages: android.os This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: I4ece0a3f37f88fc2508cb965092aed7cabc61819
* Get android.os tests running against real APIs.Jeff Sharkey2018-06-291-0/+3
| | | | | | | | | Combination of moving to existing public API, tagging things as @TestApi, and bringing utility methods into tests. Bug: 13282254 Test: atest cts/tests/tests/os/ Change-Id: Ifd24c0d048d200e8595e194890cc1dc53ddc2b3e
* Merge "MessageQueue: explicitly remove FD event listeners." am: b43daf5f7bDavid Pursell2018-03-281-0/+1
|\ | | | | | | | | | | am: 040587641b Change-Id: Ia4537ab0db75eabe8b3bf3fc07585a36769727f8
| * MessageQueue: explicitly remove FD event listeners.David Pursell2018-03-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When removing an FD listener from a MessageQueue, the MessageQueue waits until the next event callback on that FD to remove it from the underlying native Looper. This works as expected most of the time, but due to the epoll rebuild logic in the native Looper, there is a rare condition where FDs can get stuck in the Looper: 1. Register two or more FD listeners. 2. Unregister FD1 listener and close FD1. 3. Before the Looper processes FD1, get an event on FD2 and close it. (3) will trigger a rebuild of the epoll set but as FD1 is no longer valid it cannot be added back to the epoll set, and the MessageQueue will never get the final callback to clean it up. Each time this happens: * There is a small memory leak (24-32 bytes) in native Looper * Rebuilding the epoll set incurs slightly more processing * An error is logged for each lost FD on each epoll rebuild This is fairly minimal, and does get cleaned up if the lost FDs is re-opened during an epoll rebuild (since it can now be added back in), but worst-case if a process somehow triggers this on a large number of FDs it might be noticeable. It seems worth it to just remove the FD explicitly right away to avoid this case altogether. Bug: 64083817 Test: [aosp_x86-userdebug emulator] adb shell am instrument -w \ -e class android.os.cts.MessageQueueTest \ android.os.cts/android.support.test.runner.AndroidJUnitRunner Change-Id: I33faca37678439f4b28a4138efcdd80ea8952ab2
* | Add more IntDef prefixes for auto-documenting.Jeff Sharkey2017-12-131-1/+5
|/ | | | | | | Test: builds, boots Bug: 70177949 Exempt-From-Owner-Approval: annotation-only changes Change-Id: I76dde6054e06f52240bd4b1a0f196dcb74623608
* Work on issue #36891897: Need to ensure foreground services...Dianne Hackborn2017-06-141-2/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | ...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
* Protobufferize PowerManager dumpsysNetta P2017-02-231-1/+15
| | | | | | Bug: 34230125 Test: cts-tradefed run cts-dev -m CtsIncidentHostTestCase -t com.android.server.cts.PowerIncidentTest Change-Id: Ib71563cfc9ca95c297111430d8bbe2ce88d7a41d
* Rename file descriptor listener API.Jeff Brown2015-05-151-60/+55
| | | | | Bug: 21039493 Change-Id: I506c429e99528eb04dbda5b28da2ad000d10b467
* Add support for non-blocking I/O with Looper.Jeff Brown2015-03-111-6/+253
| | | | | Bug: 10349083 Change-Id: I4a94b1eac53df57c05103913bd593d92b1e062d7
* Move sync barrier methods into MessageQueue.Jeff Brown2015-03-111-2/+39
| | | | | | | | | The methods were previously defined on Looper but on reflection they actually make more sense on the MessageQueue instead since the Looper class is primarily concerned with thread lifecycle rather than the actual messages themselves. Change-Id: Iff356b94754fc9960774fa17e3eec9604229cba6
* Rename Looper::isIdling() to isPolling() to resolve confusion.Jeff Brown2015-03-111-46/+73
| | | | | | | | | | | The loop isn't technically idle at this time, it's just checking whether any file descriptors have pending events. However it's still a good signal as to whether the loop is alive. Added a real isIdle() function. Bug: 19532373 Change-Id: Idd273e8774f469ccafb00d560818cf279dfd6ba6
* Detect invalid uses of Message.Jeff Brown2014-03-031-17/+18
| | | | | | | Throw an exception when an application attempts to recycle or resend messages that are still in-use. Change-Id: I7096e8b7bd5bec41b7b8ef0c798c55ce3db6827e
* Track AArch64 changes from AOSP.Narayan Kamath2014-01-161-1/+1
| | | | | | mPtr is now long, not int. Change-Id: I75297cbef3571f8f0cc02a35a06c1bc1f4fbe416
* am 275586aa: am 7471dfc4: am 42defa02: am faa62aac: am 84ee7930: Merge ↵Narayan Kamath2014-01-161-6/+6
|\ | | | | | | | | | | | | "AArch64: Use long for pointers in android/os/MessageQueue" * commit '275586aa53889a851e0b739e408896861d76e3a8': AArch64: Use long for pointers in android/os/MessageQueue
| * AArch64: Use long for pointers in android/os/MessageQueueAshok Bhat2014-01-101-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Long is used in android/os/MessageQueue class to store pointers as native pointers can be 64-bit. In addition, some minor changes have been done to conform with standard JNI practice (e.g. use of jint instead of int in JNI function prototypes) Change-Id: I7e901b8515a5b5e3afe1dadaaf3e5c186955c2a0 Signed-off-by: Ashok Bhat <ashok.bhat@arm.com> Signed-off-by: Kévin PETIT <kevin.petit@arm.com>
* | am 83bf4404: am 3e3296e5: am 82f31701: Merge "Log view root, input and ↵Jeff Brown2013-10-171-3/+22
|\| | | | | | | | | | | | | looper state in bug reports." into klp-dev * commit '83bf440440309a394f792e3d8a6acb98197d9d7c': Log view root, input and looper state in bug reports.
| * Log view root, input and looper state in bug reports.Jeff Brown2013-10-151-3/+22
| | | | | | | | | | Bug: 10948648 Change-Id: I956cce2a0fb516c02f9bbbc021f6238bcb226891
* | Fix crash when Looper used after quit.Jeff Brown2013-09-091-3/+9
|/ | | | | | | | Calling Looper.loop() after quit() isn't supported but it shouldn't crash either. Bug: 8808624 Change-Id: I73ea54444ed908c2e8964645f4a8cd08b842baac
* Fix native crash when message queue quits.Jeff Brown2013-09-061-16/+31
| | | | | | | | | | | | | Fix a race when quitting the looper's message queue that could cause the mPtr field to be zeroed out and the native object to be destroyed while still in use. This happened due to an optimization that was intended to release the native looper's file descriptor as soon as the last message was processed rather than waiting for the finalizer to run. Bug: 9726217 Change-Id: I695a9a657acfdb3ce65a5737ff20cd11113d15fa
* Cleanup some of the thread merging.Dianne Hackborn2013-05-071-0/+5
| | | | | | | | | | | | | | | Adds an optimization for checking whether a looper is stuck, with a new Looper method to see if its thread is currently idle. This will allow us to put a large number of loopers in the monitor efficiently, since we generally won't have to do a context switch on each of them (since most looper threads spend most of their time idle waiting for work). Also change things so the system process's main thread is actually running on the main thread. Because Jeff asked for this, and who am I to argue? :) Change-Id: I12999e6f9c4b056c22dd652cb78c2453c391061f
* Fix change of behavior in Looper.quit().Jeff Brown2013-04-181-1/+45
| | | | | | | | | | | | | | | | | It seems some applications rely on Looper.quit() terminating the loop immediately without processing all messages. Rather than risk breaking them, make the safer behavior optional. Also take care to properly drain the message queue before quitting so that all of the Message instances are recycled. This may help release storage sooner in case the Looper doesn't get GC'd promptly and its remaining queue of undelivered messages sticks around. Improve docs on runWithScissors. Bug: 8596303 Change-Id: I8cbeb6f7a5f6b8e618b5109f87a03defc1486b9f
* Ensure looper quits after all other messages are handled.Jeff Brown2013-04-111-5/+6
| | | | | Bug: 8596303 Change-Id: Ie8bfbbe810f5ade2afd870c8e675ce1353a80e5d
* Make MessageQueue and Looper final.Jeff Brown2013-04-011-13/+13
| | | | | | | Applications already cannot subclass these classes because their constructors are not visible. Change-Id: Id979d86dd05f7bcc888fe4ea499ab9b95d3d5dde
* Optimize Looper JNI code.Jeff Brown2013-01-281-6/+14
| | | | | | | | | Use static native methods. Release the native looper objects as soon as the Looper quits instead of waiting until the GC finalizer to take care of it. Change-Id: I02783e48782a8f972ec2138862f700ade33d8e78
* Prevent WebView from crashing when detached from the windowRomain Guy2012-04-231-0/+17
| | | | | | | | | | | | | Bug #6365056 WebView enqueues a functor in the hardware renderer to handle animations and this functor is called at a later time by the hardware renderer. However, the functor was not removed from the queue when WebView was removed from the window. This could cause the hardware renderer to attempt to execute an invalid functor and lead to a crash. Change-Id: I9d38e80f3fdc5e29d4d0cdfa1e893c251a954508
* Improve MessageQueue sync barrier implementation.Jeff Brown2012-02-161-115/+149
| | | | | | | | | | | | | | | | | Instead of acquiring and releasing a barrier using an up/down counter, we post a message to the queue that represents the barrier. This is a more natural representation of the barrier and better matches what we want to do with it: stall messages behind the barrier in the queue while allowing messages earlier in the queue to run as usual. Refactored the MessageQueue a little bit to simplify the quit logic and to better encapsulate the invariant that all messages within the queue must have a valid target. Messages without targets are used to represent barriers. Bug: 5721047 Change-Id: Id297d9995474b5e3f17d24e302c58168e0a00394
* Add a barrier mechanism to the MessageQueue.Jeff Brown2012-02-141-14/+90
| | | | | | | | | | | | | | | | | | | | | | | | The synchronization barrier enables selectively blocking execution of synchronous messages until the barrier is released. Asynchronous messages may continue running in the meantime. The barrier is intended to be used to implement more sophisticated scheduling policies related to view hierarchy traversals. While traversals are pending, most messages posted to the message queue must be held up. This is to satisfy the invariant that traversals will occur before subsequently posted messages are handled. The exception to this rule are "asynchronous" messages that represent external events or interrupts that come from other components such as VSYNC pulses, input events or sensor events. Because these messages are typically delivered at arbitrary times, they are independent of traversals or other typical synchronization boundaries. Messages can now be flagged as asynchronous to indicate that they are weakly ordered. Bug: 5721047 Change-Id: I1446dcfbc896f33b48355adc28967ace8c8c9b9b
* Remove the deprecated things from Config.java. These haven't been working ↵Joe Onorato2011-04-071-2/+1
| | | | | | since before 1.0. Change-Id: Ic2e8fa68797ea9d486f4117f3d82c98233cdab1e
* am 22cb4ef8: am d577cfd7: Merge "Switch Looper back to using poll() instead ↵Jeff Brown2010-10-101-5/+16
|\ | | | | | | | | | | | | | | | | of epoll()." into gingerbread Merge commit '22cb4ef8ce9c4d5536ac5cee5c40b82bfa56ccc5' * commit '22cb4ef8ce9c4d5536ac5cee5c40b82bfa56ccc5': Switch Looper back to using poll() instead of epoll().
| * Switch Looper back to using poll() instead of epoll().Jeff Brown2010-10-071-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | Added a couple of micro-optimizations to avoid calling wake() unnecessarily and reduce JNI overhead slightly. Fixed a minor issue where we were not clearing the "next" field of Messages returned by the MessageQueue so the Message would hold on to its successor and potentially prevent the GC from collecting it if the message were leaked somehow. Change-Id: I488d29417ce0cdd7d0e447cda76ec978ef7f811c
* | resolved conflicts for merge of aa522ac8 to masterJeff Brown2010-09-211-70/+55
|\| | | | | | | Change-Id: Ib17ff201e770abc6b9edb58e01f3bb483dc8fa56
| * Simplify and optimize MessageQueue loop.Jeff Brown2010-09-211-69/+54
| | | | | | | | | | | | | | | | | | | | Avoids allocating new idle handler arrays on each iteration since we only need one to copy into. Coalesced the synchronized blocks. Hoisted the call to Binder.flushPendingCommands() outside of the synchronized block. Change-Id: Iabb6b633627954564bdd5d09e696663223407f47
* | am 0f0541e4: am b88102f5: Input dispatcher ANR handling enhancements.Jeff Brown2010-09-121-1/+1
|\| | | | | | | | | | | | | Merge commit '0f0541e40cfef51eb5c3769e53c1aa853b53aaf6' * commit '0f0541e40cfef51eb5c3769e53c1aa853b53aaf6': Input dispatcher ANR handling enhancements.
| * Input dispatcher ANR handling enhancements.Jeff Brown2010-09-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change is essentially a rewrite of the main input dispatcher loop with the target identification folded in. Since the input dispatcher now has all of the window state, it can make better decisions about when to ANR. Added a .5 second deadline for processing app switch keys. This behavior predates Gingerbread but had not previously been ported. Fixed some timing inaccuracies in the ANR accounting that could cause applications to ANR sooner than they should have. Added a mechanism for tracking key and motion events that have been dispatched to a window so that appropriate cancelation events can be synthesized when recovering from ANR. This change helps to keep applications in sync so they don't end up with stuck buttons upon recovery from ANRs. Added more comments to describe the tricky parts of PollLoop. Change-Id: I13dffca27acb436fc383980db536abc4d8b9e6f1
* | Allow reliable detection of a message that is in use.Wink Saville2010-08-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because the standard Looper.loop code calls Message#recycle it is imperative that Handler#handleMessage code not attempt to resue a message it receives. If allowed to do so it will cause bugs that could be difficult to diagnois. This change adds Message#flags and uses one bit to reliably detect a message is in use and throws an error in MessageQueue#enqueueMessage. This allows early detection of this bug. Note: This is not new functionality, but the current implementation does not detect messages that are in use because it uses Message#when != 0 as the detection mechanism. The problem is that a Message#when value of 0 is valid value used to place a message at the front of the queue and is thus unreliable. Another option is to change the setting of Message#when in Message#enqueueMessage so that it is never 0, although that does change subtly a publicly accessible field. Yet another option would be to use other fields but all candidates have similar problems as when in that they are publicly accessible or even settable such as Message#target. Change-Id: I040d6e546376f7b1ed1e4daa0d5644cce8bf333a
* | Revert "Allow reliable detection of a message that is in use."Jaikumar Ganesh2010-08-231-2/+1
| | | | | | | | | | | | | | | | This reverts commit 6083d81ce4d67ec632962270fda64ebb9db0d5b1. Reverting this because it causes runtime to reboot in a loop if connected to a Bluetooth Headset. copyFrom() needs to check for the introduced bit too.
* | Allow reliable detection of a message that is in use.Wink Saville2010-08-211-1/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | Because the standard Looper.loop code calls Message#recycle it is imperative that Handler#handleMessage code not attempt to resue a message it receives. If allowed to do so it will cause bugs that could be difficult to diagnois. This change adds Message#flags and uses one bit to reliably detect a message is in use and throws an error in MessageQueue#enqueueMessage. This allows early detection of this bug. Note: This is not new functionality, but the current implementation does not detect messages that are in use because it uses Message#when != 0 as the detection mechanism. The problem is that a Message#when value of 0 is valid value used to place a message at the front of the queue and is thus unreliable. Another option is to change the setting of Message#when in Message#enqueueMessage so that it is never 0, although that does change subtly a publicly accessible field. Yet another option would be to use other fields but all candidates have similar problems as when in that they are publicly accessible or even settable such as Message#target. Change-Id: I2df600537700a3fe206678f38bcae7329751c4e5
* More native input event dispatching.Jeff Brown2010-06-211-7/+0
| | | | | | | | | | | Added ANRs handling. Added event injection. Fixed a NPE ActivityManagerServer writing ANRs to the drop box. Fixed HOME key interception. Fixed trackball reporting. Fixed pointer rotation in landscape mode. Change-Id: I50340f559f22899ab924e220a78119ffc79469b7