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

Commit 6c9b2699 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11753769 from 900ee7c0 to 24Q3-release

Change-Id: Idc91a41aa6ff7f65fbd180dfbe3e8d95cce38b7c
parents fbcdbe64 900ee7c0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <algorithm>

#include <binder/Binder.h>
#include <binder/BpBinder.h>
+0 −26
Original line number Diff line number Diff line
@@ -4732,7 +4732,6 @@ void InputDispatcher::notifySwitch(const NotifySwitchArgs& args) {
}

void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
    // TODO(b/308677868) Remove device reset from the InputListener interface
    if (debugInboundEventDetails()) {
        ALOGD("notifyDeviceReset - eventTime=%" PRId64 ", deviceId=%d", args.eventTime,
              args.deviceId);
@@ -4883,30 +4882,6 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev
            }

            mLock.lock();

            if (policyFlags & POLICY_FLAG_FILTERED) {
                // The events from InputFilter impersonate real hardware devices. Check these
                // events for consistency and print an error. An inconsistent event sent from
                // InputFilter could cause a crash in the later stages of dispatching pipeline.
                auto [it, _] =
                        mInputFilterVerifiersByDisplay
                                .try_emplace(displayId,
                                             StringPrintf("Injection on %" PRId32, displayId));
                InputVerifier& verifier = it->second;

                Result<void> result =
                        verifier.processMovement(resolvedDeviceId, motionEvent.getSource(),
                                                 motionEvent.getAction(),
                                                 motionEvent.getPointerCount(),
                                                 motionEvent.getPointerProperties(),
                                                 motionEvent.getSamplePointerCoords(), flags);
                if (!result.ok()) {
                    logDispatchStateLocked();
                    LOG(ERROR) << "Inconsistent event: " << motionEvent
                               << ", reason: " << result.error();
                }
            }

            const nsecs_t* sampleEventTimes = motionEvent.getSampleEventTimes();
            const size_t pointerCount = motionEvent.getPointerCount();
            const std::vector<PointerProperties>
@@ -6970,7 +6945,6 @@ void InputDispatcher::displayRemoved(int32_t displayId) {
        // Remove the associated touch mode state.
        mTouchModePerDisplay.erase(displayId);
        mVerifiersByDisplay.erase(displayId);
        mInputFilterVerifiersByDisplay.erase(displayId);
    } // release lock

    // Wake up poll loop since it may need to make new input dispatching choices.
+1 −2
Original line number Diff line number Diff line
@@ -298,8 +298,7 @@ private:
    void transformMotionEntryForInjectionLocked(MotionEntry&,
                                                const ui::Transform& injectedTransform) const
            REQUIRES(mLock);
    // Per-display correction of injected events
    std::map</*displayId*/ int32_t, InputVerifier> mInputFilterVerifiersByDisplay GUARDED_BY(mLock);

    std::condition_variable mInjectionSyncFinished;
    void incrementPendingForegroundDispatches(const EventEntry& entry);
    void decrementPendingForegroundDispatches(const EventEntry& entry);
+21 −3
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@
#define LOG_TAG "BackgroundExecutor"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS

#include <processgroup/sched_policy.h>
#include <pthread.h>
#include <sched.h>
#include <utils/Log.h>
#include <mutex>

@@ -26,14 +29,24 @@

namespace android {

ANDROID_SINGLETON_STATIC_INSTANCE(BackgroundExecutor);
namespace {

BackgroundExecutor::BackgroundExecutor() : Singleton<BackgroundExecutor>() {
void set_thread_priority(bool highPriority) {
    set_sched_policy(0, highPriority ? SP_FOREGROUND : SP_BACKGROUND);
    struct sched_param param = {0};
    param.sched_priority = highPriority ? 2 : 0 /* must be 0 for non-RT */;
    sched_setscheduler(gettid(), highPriority ? SCHED_FIFO : SCHED_NORMAL, &param);
}

} // anonymous namespace

BackgroundExecutor::BackgroundExecutor(bool highPriority) {
    // mSemaphore must be initialized before any calls to
    // BackgroundExecutor::sendCallbacks. For this reason, we initialize it
    // within the constructor instead of within mThread.
    LOG_ALWAYS_FATAL_IF(sem_init(&mSemaphore, 0, 0), "sem_init failed");
    mThread = std::thread([&]() {
    mThread = std::thread([&, highPriority]() {
        set_thread_priority(highPriority);
        while (!mDone) {
            LOG_ALWAYS_FATAL_IF(sem_wait(&mSemaphore), "sem_wait failed (%d)", errno);
            auto callbacks = mCallbacksQueue.pop();
@@ -45,6 +58,11 @@ BackgroundExecutor::BackgroundExecutor() : Singleton<BackgroundExecutor>() {
            }
        }
    });
    if (highPriority) {
        pthread_setname_np(mThread.native_handle(), "BckgrndExec HP");
    } else {
        pthread_setname_np(mThread.native_handle(), "BckgrndExec LP");
    }
}

BackgroundExecutor::~BackgroundExecutor() {
+14 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@

#include <ftl/small_vector.h>
#include <semaphore.h>
#include <utils/Singleton.h>
#include <thread>

#include "LocklessQueue.h"
@@ -26,10 +25,20 @@
namespace android {

// Executes tasks off the main thread.
class BackgroundExecutor : public Singleton<BackgroundExecutor> {
class BackgroundExecutor {
public:
    BackgroundExecutor();
    ~BackgroundExecutor();

    static BackgroundExecutor& getInstance() {
        static BackgroundExecutor instance(true);
        return instance;
    }

    static BackgroundExecutor& getLowPriorityInstance() {
        static BackgroundExecutor instance(false);
        return instance;
    }

    using Callbacks = ftl::SmallVector<std::function<void()>, 10>;
    // Queues callbacks onto a work queue to be executed by a background thread.
    // This is safe to call from multiple threads.
@@ -37,6 +46,8 @@ public:
    void flushQueue();

private:
    BackgroundExecutor(bool highPriority);

    sem_t mSemaphore;
    std::atomic_bool mDone = false;