OpenHarmony开发者论坛

标题: DozeResume/DozeSuspend Resume/Suspend 的区别 [打印本页]

作者: 刘允礼    时间: 2024-6-3 16:17
标题: DozeResume/DozeSuspend Resume/Suspend 的区别
HdfTouch的驱动代码,发现只注册了DozeResume  /DozeSuspend ,没有使用 Resume /Suspend
static void HdfTouchDriverRegisterPowerListener(struct HdfDeviceObject *device)
{
    int ret;
    static struct IPowerEventListener powerListener = {0};
    HDF_LOGI("%s::enter!", __func__);
    powerListener.DozeResume = HdfTouchDriverDozeResume;
    powerListener.DozeSuspend = HdfTouchDriverDozeSuspend;
    powerListener.Resume = NULL;
    powerListener.Suspend = NULL;

    ret = HdfPmRegisterPowerListener(device, &powerListener);
    HDF_LOGI("%s:register power listener, ret = %d", __func__, ret);
}
检查IPowerEventListener 接口,并没有关于DozeSuspend  和 Suspend  区别的详细介绍。
struct IPowerEventListener {
    int (*DozeResume)(struct HdfDeviceObject *deviceObject);
    int (*DozeSuspend)(struct HdfDeviceObject *deviceObject);
    /** Wakes up the driver device. The driver developer implements the operation. */
    int (*Resume)(struct HdfDeviceObject *deviceObject);
    /** Hibernates the driver device. The driver developer implements the operation. */
    int (*Suspend)(struct HdfDeviceObject *deviceObject);
};
反查IPowerEventListener  代码
int PowerStateChange(struct PowerStateToken *stateToken, uint32_t pEvent)
{
    switch (pEvent) {
        case POWER_STATE_SUSPEND:
                return stateToken->listener->Suspend(stateToken->deviceObject);
        case POWER_STATE_RESUME:
                return stateToken->listener->Resume(stateToken->deviceObject);
        case POWER_STATE_DOZE_SUSPEND:
                return stateToken->listener->DozeSuspend(stateToken->deviceObject);
        case POWER_STATE_DOZE_RESUME:
                return stateToken->listener->DozeResume(stateToken->deviceObject);
    }
}
PowerStateChange根据 POWER_STATE 的不同调用不同的函数接口。
再继续查
static int32_t KernalSpacePmNotify(int32_t powerEvent)
{
    switch (powerEvent) {
        case KEVENT_POWER_SUSPEND:
            pmStatus = POWER_STATE_SUSPEND;
        case KEVENT_POWER_DISPLAY_OFF:
            pmStatus = POWER_STATE_DOZE_SUSPEND;
        case KEVENT_POWER_RESUME:
            pmStatus = POWER_STATE_RESUME;
        case KEVENT_POWER_DISPLAY_ON:
            pmStatus = POWER_STATE_DOZE_RESUME;
    }
    return devmgrClnt->devMgrSvcIf->PowerStateChange(devmgrClnt->devMgrSvcIf, pmStatus);
}
由KernalSpacePmNotify根据 KEVENT_POWER 走不同的分支。这里就能能看到 KEVENT_POWER_DISPLAY_OFF 走到了 POWER_STATE_DOZE_SUSPEND,KEVENT_POWER_SUSPEND 走到了 POWER_STATE_SUSPEND。

int32_t KeventFbNotifierFn(struct notifier_block *nb, unsigned long event, void *data)
{
    keventModule = CONTAINER_OF(nb, struct HdfKeventModule, fbNotifier);
    blank = fbEvent->data;
    if (*blank == FB_BLANK_UNBLANK) {
        powerEvent = KEVENT_POWER_DISPLAY_ON;
    } else {
        HDF_LOGI("%s:receive display off event", __func__);
        powerEvent = KEVENT_POWER_DISPLAY_OFF;

    ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync);
    return KernalSpacePmNotify(powerEvent);
}

static int32_t KeventPmNotifierFn(struct notifier_block *nb, unsigned long action, void *dummy)
{
      keventModule = CONTAINER_OF(nb, struct HdfKeventModule, keventPmNotifier);
    switch (action) {
        case PM_SUSPEND_PREPARE:
            powerEvent = KEVENT_POWER_SUSPEND;
        case PM_POST_SUSPEND:
            powerEvent = KEVENT_POWER_RESUME;
    }
    ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync);
    return KernalSpacePmNotify(powerEvent);
}







欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5