harmony 鸿蒙Default Hibernation Behavior Customization

  • 2023-06-24
  • 浏览 (394)

Default Hibernation Behavior Customization

Overview

Introduction

By default, after a device screen is turned off, OpenHarmony starts the running lock loop detection thread and then enters the hibernation state. For different devices, the mode of turning off the screen is different, which can be closing the lid, setting a timeout, or pressing the power button. Besides, the default hibernation behavior is also different, which can be performing no action, powering off the screen, or entering the hibernation state. To address this issue, OpenHarmony provides the default hibernation behavior customization function, allowing you to customize the default hibernation behavior depending on your hardware specifications.

Constraints

The configuration paths for battery level customization are subject to the configuration policy. The configuration path for battery level customization is subject to the configuration policy. In this development guide, /vendor is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.

How to Develop

Setting Up the Environment

Hardware requirements:

Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.

Environment requirements:

For details about the requirements on the Linux environment, see Quick Start.

Getting Started with Development

The following uses DAYU200 as an example to illustrate default hibernation behavior customization.

  1. Create the power_manager folder in the product directory /vendor/hihope/rk3568.

  2. Create a target folder by referring to the default folder of hibernation behavior configuration, and install it in /vendor/hihope/rk3568/power_manager. The content is as follows:

    profile
    ├── BUILD.gn
    ├── power_suspend.json
    
  3. Write the custom power_suspend.json file that contains the custom default hibernation behavior. The following is an example of hibernation behavior configuration:

    {
        "powerkey": {
            "action": 1,
            "delayMs": 0
        },
        "timeout": {
            "action": 1,
            "delayMs": 0
        },
        "lid": {
            "action": 1,
            "delayMs": 0
        },
        "switch": {
            "action": 1,
            "delayMs": 0
        }
    }
    

    Table 1 Description of hibernation sources

|Hibernation Source|Description| |——–|——–| |powerkey|Hibernation by power button| |timeout|Hibernation by timeout| |lid|Hibernation by lid| |switch|Hibernation by switch|

**Table 2** Description of the hibernation source configuration

|Item|Description| |——–|——–| |action|Action to take after the screen is turned off. Set this parameter to an enumerated value. For details, see Table 3.| |delayMs|Delay, in ms.|

**Table 3** Description of action

|action|Value|Description| |——–|——–|——–| |ACTION_NONE|0|No action.| |ACTION_AUTO_SUSPEND|1|Automatically entering the sleep mode.| |ACTION_FORCE_SUSPEND|2|Forcibly entering the sleep mode.| |ACTION_HIBERNATE|3|Entering the hibernation state.| |ACTION_SHUTDOWN|4|Shutting down the system.|

  1. Write the BUILD.gn file by referring to the BUILD.gn file in the default folder of hibernation behavior configuration to pack the power_suspend.json file to the /vendor/etc/power_config directory. The configuration is as follows:

    import("//build/ohos.gni")               # Reference build/ohos.gni.
    
    
    ohos_prebuilt_etc("suspend_config") {
        source = "power_suspend.json"
        relative_install_dir = "power_config"
        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
    }
    
  2. Add the build target to module_list in ohos.build in the /vendor/hihope/rk3568 directory. For example:

    {
        "parts": {
            "product_rk3568": {
                "module_list": [
                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
                    "//vendor/hihope/rk3568/etc:product_etc_conf",
                    "//vendor/hihope/rk3568/power_manager/profile:wakeup_config" // Add the configuration for building of suspend_config.
                ]
            }
        },
        "subsystem": "product_hihope"
    }
    

    In the preceding code, //vendor/hihope/rk3568/power_manager/ is the folder path, profile is the folder name, and suspend_config is the build target.

  3. Build the customized version by referring to Quick Start.

    ./build.sh --product-name rk3568 --ccache
    
  4. Burn the customized version to the DAYU200 development board.

Debugging and Verification

  1. Customize hibernation sources in the power_suspend.json file.

    {
        "powerkey": {
            "action": 4,
            "delayMs": 0
        },
        "timeout": {
            "action": 1,
            "delayMs": 0
        },
        "lid": {
            "action": 1,
            "delayMs": 0
        },
        "switch": {
            "action": 1,
            "delayMs": 0
        }
    }
    
  2. Power on the device, and then press the power button.

    The device is powered off.

  3. Power on the device again, and then wait for a while.

    The device screen is turned off.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Subsystems

harmony 鸿蒙AI Framework Development Guide

harmony 鸿蒙NNRt Access Adaptation

harmony 鸿蒙Application Privilege Configuration

harmony 鸿蒙Development Example

harmony 鸿蒙Setting Up a Development Environment

harmony 鸿蒙Development Guidelines

harmony 鸿蒙Application Framework Overview

harmony 鸿蒙ArkCompiler Development

harmony 鸿蒙Custom Window Title Bar Development

0  赞