RK3588 遥控器按键长按 0、1、2、3 键跳转指定 APP

2024-04-11 22:44

本文主要是介绍RK3588 遥控器按键长按 0、1、2、3 键跳转指定 APP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

diff --git a/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index b090d47679f…6805d065ad6 100755
— a/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

@@ -733,6 +733,23 @@ public class PhoneWindowManager implements WindowManagerPolicy {case MSG_RINGER_TOGGLE_CHORD:handleRingerChordGesture();break;
+                //cczheng add for KEYCODE_0 KEYCODE_1 KEYCODE_2 KEYCODE_3 longpress  
+                case MSG_KEY0_LONG_PRESS:
+                    mKey0Handled = true;
+                    customKeyLongPress(pkgName0);
+                    break;
+                case MSG_KEY1_LONG_PRESS:
+                    mKey1Handled = true;
+                    customKeyLongPress(pkgName1);
+                    break;
+                case MSG_KEY2_LONG_PRESS:
+                    mKey2Handled = true;
+                    customKeyLongPress(pkgName2);
+                    break;
+                case MSG_KEY3_LONG_PRESS:
+                    mKey3Handled = true;
+                    customKeyLongPress(pkgName3);
+                    break;//end}}}@@ -3508,6 +3545,102 @@ public class PhoneWindowManager implements WindowManagerPolicy {}}+    //cczheng add for KEYCODE_0 KEYCODE_1 KEYCODE_2 KEYCODE_3 longpress
+    private static final int MSG_KEY0_LONG_PRESS = 133;
+    private static final int MSG_KEY1_LONG_PRESS = 130;
+    private static final int MSG_KEY2_LONG_PRESS = 131;
+    private static final int MSG_KEY3_LONG_PRESS = 132;
+       
+    private final String pkgName0 = "com.android.tv.settings";
+    private final String pkgName1 = "com.liskovsoft.smarttubetv.beta";
+    private final String pkgName2 = "org.xbmc.kodi";
+    private final String pkgName3 = "com.ss.android.ugc.trill";
+    volatile boolean mKey0Handled;
+    volatile boolean mKey1Handled;
+    volatile boolean mKey2Handled;
+    volatile boolean mKey3Handled;
+   
+    private void handleKey0Button(KeyEvent event) {
+        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+        if (down) {
+            Message msg = mHandler.obtainMessage(MSG_KEY0_LONG_PRESS);
+            msg.setAsynchronous(true);
+            mHandler.sendMessageDelayed(msg, 3000);
+            mKey0Handled = false;
+            Log.d(TAG, "handleKey0Button delayed=");
+        }else{
+            if (!mKey0Handled) {
+                mKey0Handled = true;
+                mHandler.removeMessages(MSG_KEY0_LONG_PRESS);
+                Log.i(TAG, "handleKey0Button removeMessages=");
+            }
+        }
+    }
+
+    private void handleKey1Button(KeyEvent event) {
+        final int repeatCount = event.getRepeatCount();
+        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+        final boolean canceled = event.isCanceled();
+        Log.d(TAG, "repeatCount="+repeatCount+" canceled="+canceled+" down="+down);
+        if (down) {
+            Message msg = mHandler.obtainMessage(MSG_KEY1_LONG_PRESS);
+            msg.setAsynchronous(true);
+            mHandler.sendMessageDelayed(msg, 3000);
+            mKey1Handled = false;
+        }else{
+            if (!mKey1Handled) {
+                mKey1Handled = true;
+                mHandler.removeMessages(MSG_KEY1_LONG_PRESS);
+            }
+        }
+    }
+
+    private void handleKey2Button(KeyEvent event) {
+        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+        if (down) {
+            Message msg = mHandler.obtainMessage(MSG_KEY2_LONG_PRESS);
+            msg.setAsynchronous(true);
+            mHandler.sendMessageDelayed(msg, 3000);
+            mKey2Handled = false;
+        }else{
+            if (!mKey2Handled) {
+                mKey2Handled = true;
+                mHandler.removeMessages(MSG_KEY2_LONG_PRESS);
+            }
+        }
+    }
+    private void handleKey3Button(KeyEvent event) {
+        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+        if (down) {
+            Message msg = mHandler.obtainMessage(MSG_KEY3_LONG_PRESS);
+            msg.setAsynchronous(true);
+            mHandler.sendMessageDelayed(msg, 3000);
+            mKey3Handled = false;
+        }else{
+            if (!mKey3Handled) {
+                mKey3Handled = true;
+                mHandler.removeMessages(MSG_KEY3_LONG_PRESS);
+            }
+        }
+    }
+
+    private void customKeyLongPress(String pkgName){
+        Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(pkgName);
+        if (intent != null) {
+             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+             try {
+                 mContext.startActivity(intent);
+             } catch (Exception e) {
+                 e.printStackTrace();
+             }
+         }
+        Log.i(TAG, "customKeyLongPress done ....");
+    }//end
+
+    
+void initializeHdmiStateInternal() {boolean plugged = false;// watch for HDMI plug messages if the hdmi switch exists
@@ -3588,7 +3721,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {final int displayId = event.getDisplayId();final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;-        if (DEBUG_INPUT) {
+        //if (DEBUG_INPUT) {// If screen is off then we treat the case where the keyguard is open but hidden// the same as if it were open and in front.// This will prevent any keys other than the power button from waking the screen
@@ -3599,7 +3732,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {Log.d(TAG, "interceptKeyTq keycode=" + keyCode+ " interactive=" + interactive + " keyguardActive=" + keyguardActive+ " policyFlags=" + Integer.toHexString(policyFlags));
-        }
+        //}// Basic policy based on interactive state.int result;
@@ -3700,6 +3833,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {// Handle special keys.switch (keyCode) {
+            //cczheng add for KEYCODE_0 KEYCODE_1 KEYCODE_2 KEYCODE_3 longpress
+            case KeyEvent.KEYCODE_0: {
+                handleKey0Button(event);
+                break;
+            }
+            case KeyEvent.KEYCODE_1: {
+                handleKey1Button(event);
+                break;
+            }
+            case KeyEvent.KEYCODE_2: {
+                handleKey2Button(event);
+                break;
+            }
+            case KeyEvent.KEYCODE_3: {
+                handleKey3Button(event);
+                break;
+            }//end
+case KeyEvent.KEYCODE_BACK: {if (down) {mBackKeyHandled = false;

这篇关于RK3588 遥控器按键长按 0、1、2、3 键跳转指定 APP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/895370

相关文章

Golang如何对cron进行二次封装实现指定时间执行定时任务

《Golang如何对cron进行二次封装实现指定时间执行定时任务》:本文主要介绍Golang如何对cron进行二次封装实现指定时间执行定时任务问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录背景cron库下载代码示例【1】结构体定义【2】定时任务开启【3】使用示例【4】控制台输出总结背景

springboot项目打jar制作成镜像并指定配置文件位置方式

《springboot项目打jar制作成镜像并指定配置文件位置方式》:本文主要介绍springboot项目打jar制作成镜像并指定配置文件位置方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录一、上传jar到服务器二、编写dockerfile三、新建对应配置文件所存放的数据卷目录四、将配置文

python3如何找到字典的下标index、获取list中指定元素的位置索引

《python3如何找到字典的下标index、获取list中指定元素的位置索引》:本文主要介绍python3如何找到字典的下标index、获取list中指定元素的位置索引问题,具有很好的参考价值,... 目录enumerate()找到字典的下标 index获取list中指定元素的位置索引总结enumerat

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

Python pip下载包及所有依赖到指定文件夹的步骤说明

《Pythonpip下载包及所有依赖到指定文件夹的步骤说明》为了方便开发和部署,我们常常需要将Python项目所依赖的第三方包导出到本地文件夹中,:本文主要介绍Pythonpip下载包及所有依... 目录步骤说明命令格式示例参数说明离线安装方法注意事项总结要使用pip下载包及其所有依赖到指定文件夹,请按照以

python如何生成指定文件大小

《python如何生成指定文件大小》:本文主要介绍python如何生成指定文件大小的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python生成指定文件大小方法一(速度最快)方法二(中等速度)方法三(生成可读文本文件–较慢)方法四(使用内存映射高效生成

python如何下载网络文件到本地指定文件夹

《python如何下载网络文件到本地指定文件夹》这篇文章主要为大家详细介绍了python如何实现下载网络文件到本地指定文件夹,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下...  在python中下载文件到本地指定文件夹可以通过以下步骤实现,使用requests库处理HTTP请求,并结合o

Python如何调用指定路径的模块

《Python如何调用指定路径的模块》要在Python中调用指定路径的模块,可以使用sys.path.append,importlib.util.spec_from_file_location和exe... 目录一、sys.path.append() 方法1. 方法简介2. 使用示例3. 注意事项二、imp

Pandas利用主表更新子表指定列小技巧

《Pandas利用主表更新子表指定列小技巧》本文主要介绍了Pandas利用主表更新子表指定列小技巧,通过创建主表和子表的DataFrame对象,并使用映射字典进行数据关联和更新,实现了从主表到子表的同... 目录一、前言二、基本案例1. 创建主表数据2. 创建映射字典3. 创建子表数据4. 更新子表的 zb

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n