Android:控制按键灯亮灭【button-backlight】

/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

1.导包
import java.io.DataOutputStream;
import java.io.FileOutputStream;

Handler mHandler3;

2.新建handler对象

public void init(Context context, IWindowManager windowManager,
            WindowManagerFuncs windowManagerFuncs) {

 mHandler3 = new Handler();

3.延时处理方法

public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {


        // Basic policy based on interactive state.
        int result;
        boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
                || event.isWakeKey();
        //*/ 20210513. for backlight control
        if(interactive) {
            writeFile("/sys/class/leds/button-backlight/brightness", "1");
            mHandler3.removeMessages(0);
            mHandler3.postDelayed(new Runnable() {
                public void run() {
                    writeFile("/sys/class/leds/button-backlight/brightness", "0");
                }
            }, 5 * 1000);
        }
        //*/

        if (interactive || (isInjected && !isWakeKey)) {
            // When the device is interactive or the key is injected pass the
            // key to the application.
            result = ACTION_PASS_TO_USER;
            isWakeKey = false;

            if (interactive) {
                // If the screen is awake, but the button pressed was the one that woke the device
                // then don't pass it to the application
                if (keyCode == mPendingWakeKey && !down) {
                    result = 0;
                }
                // Reset the pending key
                mPendingWakeKey = PENDING_KEY_NULL;
            }
        } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) {
            // If we're currently dozing with the screen on and the keyguard showing, pass the key
            // to the application but preserve its wake key status to make sure we still move
            // from dozing to fully interactive if we would normally go from off to fully
            // interactive.
            result = ACTION_PASS_TO_USER;
            // Since we're dispatching the input, reset the pending key
            mPendingWakeKey = PENDING_KEY_NULL;
        } else {
            // When the screen is off and the key is not injected, determine whether
            // to wake the device but don't pass the key to the application.
            result = 0;
            if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
                isWakeKey = false;
            }
            // Cache the wake key on down event so we can also avoid sending the up event to the app
            if (isWakeKey && down) {
                mPendingWakeKey = keyCode;
            }
        }

4.屏灭时写0

 @Override
    public void screenTurningOff(ScreenOffListener screenOffListener) {
        mWindowManagerFuncs.screenTurningOff(screenOffListener);
        synchronized (mLock) {
            if (mKeyguardDelegate != null) {
                mKeyguardDelegate.onScreenTurningOff();
            }
        }
        //*/ 20231017 for backlight control
        writeFile("/sys/class/leds/button-backlight/brightness", "0");
        //*/

    }
 

5.写节点方法

//*/

private void writeFile(String filePath, String line) {
        File a = new File(filePath);
        if (a.exists()) {
            try {
                FileOutputStream fs = new FileOutputStream(a);
                DataOutputStream ds = new DataOutputStream(fs);
                ds.write(line.getBytes());
                ds.flush();
                ds.close();
                fs.close();
            } catch (Exception ex) {
                Log.e(TAG, "writeFile() Exception: " + filePath);
            }
        } else {
            Log.d(TAG, "writeFile() File not exist: " + filePath);
            try {
                if (a.createNewFile()) {
                    Log.d(TAG, "writeFile() File created: " + filePath);
                    try {
                        FileOutputStream fs = new FileOutputStream(a);
                        DataOutputStream ds = new DataOutputStream(fs);
                        ds.write(line.getBytes());
                        ds.flush();
                        ds.close();
                        fs.close();
                    } catch (Exception ex) {
                        Log.e(TAG, "writeFile() Exception: " + filePath);
                    }
                } else {
                    Log.d(TAG, "writeFile() Create file fail: " + filePath);
                }
            } catch (IOException e) {
                Log.e(TAG, "writeFile() creatFile Exception: " + filePath);
            }
        }
    }
    //*/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/166935.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

制作linux deb安装包

dpkg 命令命令详解 dpkg -i手动安装软件包(这个命令并不能解决软件包之前的依赖性问题),如果在安装某一个软件包的时候遇到了软件依赖的问题,可以用apt-get -f install在解决信赖性这个问题.     dpkg --info “软件包名” --列出软件包解包后的包名称. dpkg -l–列出当前…

java 基础面试题——问题+答案——第1期

一、问题 在Java基础面试中,面试官可能会问及一系列基础知识,以确保对Java语言的核心概念和基本特性有清晰的理解。以下是一些可能的问题: Java基础: 解释Java的基本特性。什么是Java虚拟机(JVM)&#xff…

2024深圳电子展,加快粤港澳电子信息发展,重点打造“湾区经济”

在“十四五”期间,中国电子信息产业面临着新形势和新特点。随着国家对5G、人工智能、工业互联网、物联网等“新基建”的加速推进,以及形成“双循环”新格局的形势,新型显示、集成电路等产业正在加速向国内转移。这一过程不仅带来了新的应用前…

主从复制读写分离?

主从复制和读写分离是常见的数据库架构策略,它们可以提高系统的性能和可靠性。下面是一个简单的实现方法: 主从复制: 配置主数据库:在主数据库上启用二进制日志(binary log),用于记录所有修改数…

【ES6.0】-详细模块化、export与Import详解

【ES6.0】-详细模块化、export与Import详解 文章目录 【ES6.0】-详细模块化、export与Import详解一、模块化概述二、ES6模块化的语法规范三、export导出模块3.1 单变量导出3.2 导出多个变量3.3 导出函数3.4 导出对象第一种第二种: 3.5 类的导出第一种第二种 四、imp…

FFNPEG编译脚本

下面是一个ffmpeg编译脚本: #!/bin/bash set -eu -o pipefail set eu o pipefailFFMPEG_TAGn4.5-dev build_path$1 git_repo"https://github.com/FFmpeg/FFmpeg.git" cache_tool"" sysroot"" c_compiler"gcc" cxx_compile…

2023年亚太地区数学建模大赛 C 题

我国新能源电动汽车的发展趋势 新能源汽车是指以先进技术原理、新技术、新结构的非常规汽车燃料为动力来源(非常规汽车燃料指汽油、柴油以外的燃料),将先进技术进行汽车动力控制和驱动相结合的汽车。新能源汽车主要包括四种类型:…

【mybatis注解实现条件查询】

文章目录 步骤1: 引入MyBatis依赖步骤2: 创建数据模型步骤3: 创建Mapper接口步骤4: 配置MyBatis步骤5: 执行条件查询 步骤1: 引入MyBatis依赖 <dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.x.…

MobaXterm连接节点一段时间后超时Session stopped

1、MobaXterm &#xff08;1&#xff09;设置ssh 超时时间 &#xff08;2&#xff09;设置保持连接 如果服务器端设置了超时时间&#xff0c;会以服务器为准&#xff0c;具体设置&#xff1a; 2、服务端 cat /etc/ssh/sshd_config | grep "ClientAlive" 可以把设置…

一穿一戴一世界 | 紫光展锐2023智能穿戴沙龙成功举办

11月23日&#xff0c;紫光展锐在深圳成功举办了以“一穿一戴一世界”为主题的2023智能穿戴沙龙。展锐智能穿戴沙龙已举办四届&#xff0c;旨在为行业提供启发性的观点和前瞻性的创新理念。本届沙龙吸引了终端厂商、行业翘楚、生态伙伴等行业各领域超过500人汇聚一堂&#xff0c…

【HTML5-webscoket实时通信(web)】

websocket是什么&#xff1f; 就是用来创建网络聊天室&#xff0c;实时通信websocket的方法有哪些&#xff1f; https://developer.mozilla.org/zh-CN/docs/Web/API/WebSockets如何实现&#xff1a;&#xff08;以下实现流程&#xff09; 前端&#xff1a; // 直播中// 聊天web…

机器篇——决策树(六) 细说 评估指标的交叉验证

本小节&#xff0c;细说 评估指标的交叉验证。 三. 评估指标 3. 交叉验证(cross validation) (1). 概念 交叉验证(cross validation, cv) 主要用于模型训练或建模应用中&#xff0c;如分类预测、PCR、PLS 回归建模等。在给定的样本空间中&#xff0c;拿出大部分…

HCIA-RS基础-静态路由协议

摘要&#xff1a;静态路由是一种在网络中广泛应用的路由选择方案&#xff0c;它以其简单的配置和低开销而备受青睐。本文将介绍静态路由的配置方法、默认路由的设置、路由的负载分担和备份策略。通过学习本文&#xff0c;希望可以你能够掌握静态路由的基本概念和在华为模拟器中…

贪心算法个人见解

目录 基本思想&#xff1a; 贪心算法的步骤&#xff1a; 示例&#xff1a; 贪心算法&#xff08;Greedy Algorithm&#xff09;是一种基于贪心策略的算法范式&#xff0c;它在每一步选择中都采取当前状态下的最优选择&#xff0c;而不考虑全局最优解。贪心算法通常适用于那些…

U-Boot 之九 详解 Pinctrl 子系统、命令、初始化流程、使用方法

嵌入式芯片中,引脚复用是一个非常常见的功能,U-Boot 提供一个类似 Linux Kernel 的 Pinctrl 子系统来处理引脚复用功能。正好最近用到了这部分功能,需要移植 Pinctrl 驱动,特此记录一下学习过程。 架构 U-Boot 提供一个类似 Linux Kernel 的 Pinctrl 子系统,用来统一各芯…

Double 4 VR智能互动教学系统在小语种课堂中的教学应用

小语种课堂一直是教育领域的一个难点。由于语言本身的复杂性和文化背景的差异&#xff0c;小语种教学一直是一个挑战。传统的课堂教学方法往往难以激发学生的学习兴趣和动力&#xff0c;教学效果不尽如人意。而Double 4 VR智能互动教学系统为小语种课堂带来了新的可能。 Double…

视频服务网关的三大部署(三)

视频网关是软硬一体的一款产品&#xff0c;可提供多协议&#xff08;RTSP/ONVIF/GB28181/海康ISUP/EHOME/大华、海康SDK等&#xff09;的设备视频接入、采集、处理、存储和分发等服务&#xff0c; 配合视频网关云管理平台&#xff0c;可广泛应用于安防监控、智能检测、智慧园区…

RK WiFi部分信道在部分地区无法使用的原因

不同国家支持的WiFi信道不一样&#xff0c;需要正确设置wificountrycode 修改路径&#xff1a; device\rockchip\common\BoardConfig.mk 修改内容&#xff1a;androidboot.wificountrycodeXX 该属性会被解析为 ro.boot.wificountrycode framework层会在&#xff1a; framewor…

用好语言模型:temperature、top-p等核心参数解析

编者按&#xff1a;我们如何才能更好地控制大模型的输出? 本文将介绍几个关键参数&#xff0c;帮助读者更好地理解和运用 temperature、top-p、top-k、frequency penalty 和 presence penalty 等常见参数&#xff0c;以优化语言模型的生成效果。 文章详细解释了这些参数的作用…

leetcode 343.整数拆分 198.打家劫舍(动态规划)

OJ链接 &#xff1a;leetcode 343.整数拆分 代码&#xff1a; class Solution {public int integerBreak(int n) {int[] dp new int[n1];//每个n&#xff0c;拆分多个整数乘积的最大值dp [0] 0;dp [1] 1; for(int i 2 ; i<n; i){for(int j 0 ; j < i; j){dp[i] Ma…