关闭休眠仅熄屏

Platform:RK3399
OS:Android:7.1.2
参考:
1. https://ask.csdn.net/questions/673694
2. https://www.optbbs.com/thread-4216693-1-1.html

概述

产品需求:在熄屏状态下也可以随时响应语音唤醒.而且主要功能可以使用.由于早期设计的时候全部采用了低功耗硬件设计,所以在真实修休眠下许多功能都不可用.所以只有临时采用只熄屏不休眠的方式实现,后续迭代再修改硬件电路设计.

关闭休眠

关闭系统休眠有两步操作:1.关闭power键的休眠功能,关闭系统自带的超时休眠.

按键休眠

去掉dts中power键的wakeup功能

 power-key {
   gpios = <&gpio0 5 1>;
   linux,code = <116>;
   label = "power";
-  gpio-key,wakeup;
  };

关闭power按键的短按休眠功能

diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index c63eb68a..d84c9948 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -828,7 +828,7 @@
    
-    1
+    0
 
     
 
     true
-    2147483647
+    -1
     -1
     false

方法二:

修改frameworks\base\packages\SettingsProvider\res\values\defaults.xml

 
     true
     2147483647
     -1
     false

将def_screen_off_timeout改为2147483647,默认为60000

device/rockchip/common/devices.mk

ifeq ($(strip $(TARGET_BOARD_PLATFORM_PRODUCT)), box)
include device/rockchip/common/samba/rk31_samba.mk
PRODUCT_PROPERTY_OVERRIDES += \
    ro.rk.screenoff_time=2147483647
else ifeq ($(strip $(TARGET_BOARD_PLATFORM_PRODUCT)), tablet)
PRODUCT_PROPERTY_OVERRIDES += \
    ro.rk.screenoff_time=2147483647
else
PRODUCT_PROPERTY_OVERRIDES += \
    ro.rk.screenoff_time=60000
endif

将else下面改为:2147483647

熄屏操作

单独熄屏

走Android系统调用会进入休眠.所有需要单独熄屏.

可以通过JNI来控制背光实现.

/*LCD backlight*/
static int set_screen(u32 arg)
{
    char *path = "/sys/class/backlight/backlight/brightness";
    char brightness[3] = {'1','7','9'};
    int ret = 0;

    if((arg != SCREEN_ON) && (arg != SCREEN_OFF)){
        LOGE("Command is err,arg is %d.",arg);
        return -EINVAL;
    }

    int fd = open(path,O_RDWR);
    if(fd < 0){
        LOGE("Cannot open brightness.");
        return fd;
    }

   if(arg == SCREEN_ON){
        ret = write(fd,&brightness,(size_t)3);
    }
    else{
        brightness[0] = '0';
        ret = write(fd,&brightness,(size_t)1);
    }
    if(ret < 0){
        printf("Cannot write brightness.ret is %d,errno is %d.\n",ret,errno);
        return ret;
    }


    close(fd);
    LOGI("Set LCD backlight success.");
    return 0;
}

获取屏幕状态

操作背光之后,通过系统API无法获取真实的背光值,从而无法判断背光的开关.可以通过JNI来获取.

static int get_backlight(void)
{
     char *path = "/sys/class/backlight/backlight/brightness";
     char brightness[3] = {0};
     int ret = 0;

     int fd = open(path,O_RDONLY);
     if(fd < 0){
          LOGE("Cannot open brightness.");
          return fd;
     }

     ret = read(fd,&brightness,3);
     if(ret <= 0){
        LOGE("read brightness fail.");
        return -133;
     }

     close(fd);
     return (ret == 3) ? 179 : 0;

}

这里简单处理了返回值;因为只需要获取状态即可.

按键模拟

关闭熄屏之后按键或者其他模拟按键是无法唤醒设备的,所以需要监听到按键.

diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index c0a9b31f..02488199 100755
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -6111,12 +6111,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                 } catch (RemoteException e) {
 
                 }
-                result &= ~ACTION_PASS_TO_USER;
+                result |= ACTION_PASS_TO_USER;
                 isWakeKey = false; // wake-up will be handled separately
                 if (down) {
                     interceptPowerKeyDown(event, interactive);
+                   mContext.sendBroadcast(new Intent("com.qxzn.keycode.power.down"));
                 } else {
                     interceptPowerKeyUp(event, interactive, canceled);
+                   mContext.sendBroadcast(new Intent("com.qxzn.keycode.power.up"));
                 }
                 break;
             }

你可能感兴趣的:(关闭休眠仅熄屏)