Files
mr-liang2504 cfa4a56b11 Signed-off-by: mr-liang2504 <liangzhicheng10@huawei.com>
Co-Authored-By: Agent

Signed-off-by: mr-liang2504 <liangzhicheng10@huawei.com>
Change-Id: Ie24e29785e1d14e7318e7ffd1718e8c964811b6c
2026-08-11 20:04:27 +08:00
..
2025-02-13 10:00:30 +08:00
2026-04-13 16:27:40 +08:00
2026-04-13 16:27:40 +08:00

Power

Introduction

This repository contains the Power module HDI (Hardware Driver Interface) definitions and implementations, providing power management driver capability interfaces for upper-layer system services. The Power HDI interfaces mainly include:

  • Suspend/Resume: Responsible for system suspend and resume management, including active suspend, force suspend, stop suspend, etc.
  • RunningLock: Responsible for running lock management, including hold, release, timer handling, etc.
  • Hibernate: Responsible for system hibernation functionality.
  • PowerConfig: Responsible for power configuration management, supporting getting and setting power configuration items.

Directory

The source code directory structure is as follows:

/drivers/peripheral/power
├── etc                      # Power module configuration files
│   └── para                 # Parameter configuration files
├── interfaces              # Power module driver capability interfaces for upper-layer services
│   └── hdi_service          # HDI layer framework code
│       ├── profile          # Configuration files
│       └── src              # HDI layer source code
├── test                     # Power module test code
│   ├── unittest             # Unit tests
│   └── fuzztest             # Fuzz tests
└── utils                    # Utility code

Interface Description

The Power driver module provides interfaces to upper-layer system services through the HDI layer, with main functions including: system suspend/resume, running lock management, power configuration, etc. The provided interfaces are shown in Table1 Power HDI Interface List:

Table 1 Power HDI Interface List

Header File

Interface Name

Function Description

v1_3/ipower_interface.h

int32_t SetSuspendTag(const std::string &tag);

Set suspend tag

int32_t StartSuspend();

Start suspend

int32_t StopSuspend();

Stop suspend

int32_t ForceSuspend();

Force suspend

int32_t Hibernate();

System hibernate

int32_t SuspendBlock(const std::string &name);

Block suspend

int32_t SuspendUnblock(const std::string &name);

Unblock suspend

int32_t PowerDump(std::string &info);

Power state dump

int32_t GetWakeupReason(std::string &reason);

Get wakeup reason

int32_t SetPowerConfig(const std::string &sceneName, const std::string &value);

Set power config

int32_t GetPowerConfig(const std::string &sceneName, std::string &value);

Get power config

int32_t RegisterCallback(const sptr &ipowerHdiCallback);

Register power callback

int32_t RegisterPowerCallbackExt(const sptr &ipowerHdiCallback);

Register power extension callback

int32_t UnRegisterPowerCallbackExt(const sptr &ipowerHdiCallback);

Unregister power extension callback

v1_2/running_lock_types.h

int32_t HoldRunningLock(const RunningLockInfo &info);

Hold running lock

int32_t UnholdRunningLock(const RunningLockInfo &info);

Unhold running lock

int32_t HoldRunningLockExt(const RunningLockInfo &info, uint64_t lockid, const std::string &bundleName);

Hold extended running lock

int32_t UnholdRunningLockExt(const RunningLockInfo &info, uint64_t lockid, const std::string &bundleName);

Unhold extended running lock

int32_t RegisterRunningLockCallback(const sptr &iPowerRunningLockCallback);

Register running lock callback

int32_t UnRegisterRunningLockCallback();

Unregister running lock callback

Usage Instructions

The core function of this repository is to provide power management driver capability interfaces for upper-layer system services. The provided driver capability interfaces are unified as HDI interface layer.

The following sample code demonstrates how to use the Power HDI interface:

#include "v1_3/ipower_interface.h"
#include "v1_2/running_lock_types.h"
#include "ipower_hdi_callback.h"
#include "power_hdi_client.h"

using namespace OHOS::HDI::Power::V1_3;

static int32_t PowerHdiSample(void)
{
    int32_t ret;
    sptr<IPowerInterface> g_powerInterface = PowerHdiClient::GetInstance();

    if (g_powerInterface == nullptr) {
        HDF_LOGE("get power interface failed");
        return HDF_FAILURE;
    }

    // Set suspend tag
    ret = g_powerInterface->SetSuspendTag("test_tag");
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("set suspend tag failed");
        return ret;
    }

    // Start suspend
    ret = g_powerInterface->StartSuspend();
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("start suspend failed");
        return ret;
    }

    // Stop suspend
    ret = g_powerInterface->StopSuspend();
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("stop suspend failed");
        return ret;
    }

    // Hold running lock
    RunningLockInfo lockInfo;
    lockInfo.type = RunningLockType::RUNNINGLOCK_SCREEN;
    lockInfo.name = "screen_lock";
    lockInfo.timeoutMs = 5000;
    ret = g_powerInterface->HoldRunningLock(lockInfo);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("hold running lock failed");
        return ret;
    }

    // Unhold running lock
    ret = g_powerInterface->UnholdRunningLock(lockInfo);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("unhold running lock failed");
        return ret;
    }

    // Get wakeup reason
    std::string wakeupReason;
    ret = g_powerInterface->GetWakeupReason(wakeupReason);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("get wakeup reason failed");
        return ret;
    }

    // Get power config
    std::string value;
    ret = g_powerInterface->GetPowerConfig("screen_off_timeout", value);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("get power config failed");
        return ret;
    }

    // Set power config
    ret = g_powerInterface->SetPowerConfig("screen_off_timeout", "30000");
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("set power config failed");
        return ret;
    }

    return HDF_SUCCESS;
}

Driver Subsystem

drivers_framework

drivers_adapter

drivers_interface

drivers_peripheral