Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b04b9b8a authored by Peter Collingbourne's avatar Peter Collingbourne
Browse files

Add support for a hw_timeout_multiplier system property.

In order to test the platform in emulators that are orders of magnitude
slower than real hardware we need to be able to avoid hitting timeouts
that prevent it from coming up properly. For this purpose introduce
a system property, ro.hw_timeout_multiplier, which may be set to
an integer value that acts as a multiplier for various timeouts on
the system.

Bug: 178231152
Change-Id: I6d7710beed0c4c5b1720e74e7abe3a586778c678
Ignore-AOSP-First: The frameworks/base part of this change conflicts with AOSP so we need to land it internally first
parent 331822d6
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -20,7 +20,10 @@ package android.os;
/** @hide */
/** @hide */
interface IInputConstants
interface IInputConstants
{
{
    const int DEFAULT_DISPATCHING_TIMEOUT_MILLIS = 5000; // 5 seconds
    // This should be multiplied by the value of the system property ro.hw_timeout_multiplier before
    // use. A pre-multiplied constant is available in Java in
    // android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS.
    const int UNMULTIPLIED_DEFAULT_DISPATCHING_TIMEOUT_MILLIS = 5000; // 5 seconds


    // Compatibility changes.
    // Compatibility changes.
    /**
    /**
+5 −2
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ static constexpr bool DEBUG_TOUCH_OCCLUSION = true;
#define DEBUG_HOVER 0
#define DEBUG_HOVER 0


#include <android-base/chrono_utils.h>
#include <android-base/chrono_utils.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <android/os/IInputConstants.h>
#include <android/os/IInputConstants.h>
#include <binder/Binder.h>
#include <binder/Binder.h>
@@ -78,6 +79,7 @@ static constexpr bool DEBUG_TOUCH_OCCLUSION = true;
#define INDENT3 "      "
#define INDENT3 "      "
#define INDENT4 "        "
#define INDENT4 "        "


using android::base::HwTimeoutMultiplier;
using android::base::StringPrintf;
using android::base::StringPrintf;
using android::os::BlockUntrustedTouchesMode;
using android::os::BlockUntrustedTouchesMode;
using android::os::IInputConstants;
using android::os::IInputConstants;
@@ -89,8 +91,9 @@ namespace android::inputdispatcher {


// Default input dispatching timeout if there is no focused application or paused window
// Default input dispatching timeout if there is no focused application or paused window
// from which to determine an appropriate dispatching timeout.
// from which to determine an appropriate dispatching timeout.
constexpr std::chrono::duration DEFAULT_INPUT_DISPATCHING_TIMEOUT =
const std::chrono::duration DEFAULT_INPUT_DISPATCHING_TIMEOUT = std::chrono::milliseconds(
        std::chrono::milliseconds(android::os::IInputConstants::DEFAULT_DISPATCHING_TIMEOUT_MILLIS);
        android::os::IInputConstants::UNMULTIPLIED_DEFAULT_DISPATCHING_TIMEOUT_MILLIS *
        HwTimeoutMultiplier());


// Amount of time to allow for all pending events to be processed when an app switch
// Amount of time to allow for all pending events to be processed when an app switch
// key is on the way.  This is used to preempt input dispatch and drop input events
// key is on the way.  This is used to preempt input dispatch and drop input events
+1 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ Every dispatch cycle, InputDispatcher will check all connections to see if any a


When a dispatch entry is sent to the app, its `deliveryTime` and `timeoutTime` fields are populated. The `deliveryTime` is the time that the event is delivered to the app. This is simply the current time inside `publishMotionEvent`. The `timeoutTime` is the time when this entry would be considered overdue. At that time, the ANR process would start for this connection.
When a dispatch entry is sent to the app, its `deliveryTime` and `timeoutTime` fields are populated. The `deliveryTime` is the time that the event is delivered to the app. This is simply the current time inside `publishMotionEvent`. The `timeoutTime` is the time when this entry would be considered overdue. At that time, the ANR process would start for this connection.


Most connections are associated with a window, and each window may have a custom timeout time. To calculate the timeout time of a specific event, simply add the `window.dispatchingTimeout` to the current time. In case where there is no associated window, such as gesture monitors, use the default dispatching timeout which is defined in `IInputConstants::DEFAULT_DISPATCHING_TIMEOUT_MILLIS`.
Most connections are associated with a window, and each window may have a custom timeout time. To calculate the timeout time of a specific event, simply add the `window.dispatchingTimeout` to the current time. In case where there is no associated window, such as gesture monitors, use the default dispatching timeout which is defined in `android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS`.


The `timeoutTime` field of the `DispatchEntry` is needed because the window associated with a specific connection may change its timeout time. Therefore, entries sent prior to the timeout change would need to follow the previous timeout value. If a window timeout changes, it only affects new events being dispatched, and does not alter the timeout times of events already sent to the app.
The `timeoutTime` field of the `DispatchEntry` is needed because the window associated with a specific connection may change its timeout time. Therefore, entries sent prior to the timeout change would need to follow the previous timeout value. If a window timeout changes, it only affects new events being dispatched, and does not alter the timeout times of events already sent to the app.