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

Commit b4f4da3b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "charger: process hall_sensor event to show charging animation" am: c02e04b9 am: 9174d6c2

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1867820

Change-Id: Iee80d69fb15cd954b2d1154bf5628ce5a56cdca7
parents e500a01d 9174d6c2
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -348,6 +348,14 @@ void Charger::UpdateScreenState(int64_t now) {

    disp_time = batt_anim_.frames[batt_anim_.cur_frame].disp_time;

    /* turn off all screen */
    if (screen_switch_ == SCREEN_SWITCH_ENABLE) {
        healthd_draw_->blank_screen(true, 0 /* drm */);
        healthd_draw_->blank_screen(true, 1 /* drm */);
        screen_blanked_ = true;
        screen_switch_ = SCREEN_SWITCH_DISABLE;
    }

    if (screen_blanked_) {
        healthd_draw_->blank_screen(false, static_cast<int>(drm_));
        screen_blanked_ = false;
@@ -452,7 +460,26 @@ int Charger::SetKeyCallback(int code, int value) {
    return 0;
}

int Charger::SetSwCallback(int code, int value) {
    if (code > SW_MAX) return -1;
    if (code == SW_LID) {
        if ((screen_switch_ == SCREEN_SWITCH_DEFAULT) || ((value != 0) && (drm_ == DRM_INNER)) ||
            ((value == 0) && (drm_ == DRM_OUTER))) {
            screen_switch_ = SCREEN_SWITCH_ENABLE;
            drm_ = (value != 0) ? DRM_OUTER : DRM_INNER;
            keys_[code].pending = true;
        }
    }

    return 0;
}

void Charger::UpdateInputState(input_event* ev) {
    if (ev->type == EV_SW && ev->code == SW_LID) {
        SetSwCallback(ev->code, ev->value);
        return;
    }

    if (ev->type != EV_KEY) return;
    SetKeyCallback(ev->code, ev->value);
}
@@ -511,10 +538,26 @@ void Charger::ProcessKey(int code, int64_t now) {
    key->pending = false;
}

void Charger::ProcessHallSensor(int code) {
    key_state* key = &keys_[code];

    if (code == SW_LID) {
        if (key->pending) {
            reset_animation(&batt_anim_);
            kick_animation(&batt_anim_);
            RequestDisableSuspend();
        }
    }

    key->pending = false;
}

void Charger::HandleInputState(int64_t now) {
    ProcessKey(KEY_POWER, now);

    if (next_key_check_ != -1 && now > next_key_check_) next_key_check_ = -1;

    ProcessHallSensor(SW_LID);
}

void Charger::HandlePowerSupplyState(int64_t now) {
@@ -744,9 +787,13 @@ void Charger::OnInit(struct healthd_config* config) {
        }
    }
    drm_ = DRM_INNER;
    screen_switch_ = SCREEN_SWITCH_DEFAULT;
    ev_sync_key_state(std::bind(&Charger::SetKeyCallback, this, std::placeholders::_1,
                                std::placeholders::_2));

    (void)ev_sync_sw_state(
            std::bind(&Charger::SetSwCallback, this, std::placeholders::_1, std::placeholders::_2));

    next_screen_transition_ = -1;
    next_key_check_ = -1;
    next_pwr_check_ = -1;
+9 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@ enum DirectRenderManager {
    DRM_OUTER,
};

enum SrceenSwitch {
    SCREEN_SWITCH_DEFAULT,
    SCREEN_SWITCH_DISABLE,
    SCREEN_SWITCH_ENABLE,
};

// Configuration interface for charger. This includes:
// - HalHealthLoop APIs that interests charger.
// - configuration values that used to be provided by sysprops
@@ -90,9 +96,11 @@ class Charger {
    void InitDefaultAnimationFrames();
    void UpdateScreenState(int64_t now);
    int SetKeyCallback(int code, int value);
    int SetSwCallback(int code, int value);
    void UpdateInputState(input_event* ev);
    void SetNextKeyCheck(key_state* key, int64_t timeout);
    void ProcessKey(int code, int64_t now);
    void ProcessHallSensor(int code);
    void HandleInputState(int64_t now);
    void HandlePowerSupplyState(int64_t now);
    int InputCallback(int fd, unsigned int epevents);
@@ -108,6 +116,7 @@ class Charger {
    int64_t wait_batt_level_timestamp_ = 0;

    DirectRenderManager drm_;
    SrceenSwitch screen_switch_;

    key_state keys_[KEY_MAX + 1] = {};