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

Commit 328d07a3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Classifier: Ping the HAL from monitor() instead of dump()"

parents 4b8d6de8 d7740d68
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -331,20 +331,9 @@ void MotionClassifier::reset(const NotifyDeviceResetArgs& args) {
    enqueueEvent(std::make_unique<NotifyDeviceResetArgs>(args));
}

const char* MotionClassifier::getServiceStatus() REQUIRES(mLock) {
    if (!mService) {
        return "null";
    }

    if (AIBinder_ping(mService->asBinder().get()) == STATUS_OK) {
        return "running";
    }
    return "not responding";
}

void MotionClassifier::dump(std::string& dump) {
    std::scoped_lock lock(mLock);
    dump += StringPrintf(INDENT2 "mService status: %s\n", getServiceStatus());
    dump += StringPrintf(INDENT2 "mService connected: %s\n", mService ? "true" : "false");
    dump += StringPrintf(INDENT2 "mEvents: %zu element(s) (max=%zu)\n",
            mEvents.size(), MAX_EVENTS);
    dump += INDENT2 "mClassifications, mLastDownTimes:\n";
@@ -365,6 +354,18 @@ void MotionClassifier::dump(std::string& dump) {
    }
}

void MotionClassifier::monitor() {
    std::scoped_lock lock(mLock);
    if (mService) {
        // Ping the HAL service to ensure it is alive and not blocked.
        const binder_status_t status = AIBinder_ping(mService->asBinder().get());
        if (status != STATUS_OK) {
            ALOGW("IInputProcessor HAL is not responding; binder ping result: %s",
                  AStatus_getDescription(AStatus_fromStatus(status)));
        }
    }
}

// --- InputClassifier ---

InputClassifier::InputClassifier(InputListenerInterface& listener) : mQueuedListener(listener) {}
@@ -504,6 +505,7 @@ void InputClassifier::dump(std::string& dump) {

void InputClassifier::monitor() {
    std::scoped_lock lock(mLock);
    if (mMotionClassifier) mMotionClassifier->monitor();
}

InputClassifier::~InputClassifier() {
+9 −3
Original line number Diff line number Diff line
@@ -78,9 +78,14 @@ public:
    virtual void reset(const NotifyDeviceResetArgs& args) = 0;

    /**
     * Dump the state of the motion classifier
     * Dump the state of the motion classifier.
     */
    virtual void dump(std::string& dump) = 0;

    /**
     * Called by the heartbeat to ensure the HAL is still processing normally.
     */
    virtual void monitor() = 0;
};

/**
@@ -96,7 +101,7 @@ public:
     */
    virtual void dump(std::string& dump) = 0;

    /* Called by the heatbeat to ensures that the classifier has not deadlocked. */
    /** Called by the heartbeat to ensure that the classifier has not deadlocked. */
    virtual void monitor() = 0;

    InputClassifierInterface() { }
@@ -155,13 +160,14 @@ public:
    virtual void reset(const NotifyDeviceResetArgs& args) override;

    virtual void dump(std::string& dump) override;
    virtual void monitor() override;

private:
    friend class MotionClassifierTest; // to create MotionClassifier with a test HAL implementation
    explicit MotionClassifier(
            std::shared_ptr<aidl::android::hardware::input::processor::IInputProcessor> service);

    // The events that need to be sent to the HAL.
    /** The events that need to be sent to the HAL. */
    BlockingQueue<ClassifierEvent> mEvents;
    /**
     * Add an event to the queue mEvents.