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

相关文章

遮罩,在指定元素上进行遮罩

废话不多说,直接上代码: ps:依赖 jquer.js 1.首先,定义一个 Overlay.js  代码如下: /*遮罩 Overlay js 对象*/function Overlay(options){//{targetId:'',viewHtml:'',viewWidth:'',viewHeight:''}try{this.state=false;//遮罩状态 true 激活,f

Jenkins构建Maven聚合工程,指定构建子模块

一、设置单独编译构建子模块 配置: 1、Root POM指向父pom.xml 2、Goals and options指定构建模块的参数: mvn -pl project1/project1-son -am clean package 单独构建project1-son项目以及它所依赖的其它项目。 说明: mvn clean package -pl 父级模块名/子模块名 -am参数

C#关闭指定时间段的Excel进程的方法

private DateTime beforeTime;            //Excel启动之前时间          private DateTime afterTime;               //Excel启动之后时间          //举例          beforeTime = DateTime.Now;          Excel.Applicat

struts2中的json返回指定的多个参数

要返回指定的多个参数,就必须在struts.xml中的配置如下: <action name="goodsType_*" class="goodsTypeAction" method="{1}"> <!-- 查询商品类别信息==分页 --> <result type="json" name="goodsType_findPgae"> <!--在这一行进行指定,其中lis是一个List集合,但

MFC中App,Doc,MainFrame,View各指针的互相获取

纸上得来终觉浅,为了熟悉获取方法,我建了个SDI。 首先说明这四个类的执行顺序是App->Doc->Main->View 另外添加CDialog类获得各个指针的方法。 多文档的获取有点小区别,有时间也总结一下。 //  App void CSDIApp::OnApp() {      //  App      //  Doc     CDocument *pD

Clion不识别C代码或者无法跳转C语言项目怎么办?

如果是中文会显示: 此时只需要右击项目,或者你的源代码目录,将这个项目或者源码目录标记为项目源和头文件即可。 英文如下:

[轻笔记] ubuntu Shell脚本实现监视指定进程的运行状态,并能在程序崩溃后重启动该程序

根据网上博客实现,发现只能监测进程离线,然后对其进行重启;然而,脚本无法打印程序正常状态的信息。自己通过不断修改测试,发现问题主要在重启程序的命令上(需要让重启的程序在后台运行,不然会影响监视脚本进程,使其无法正常工作)。具体程序如下: #!/bin/bashwhile [ 1 ] ; dosleep 3if [ $(ps -ef|grep exe_name|grep -v grep|

[轻笔记] jupyter notebook 指定conda虚拟环境

安装插件 conda install nb_conda 进入conda env conda activate ${env_name}conda install ipykernelconda deactivate #3. 运行jupyter notebook conda activate # 需要先进入conda环境,非常重要jupyter notebook 会发现,在ju

独立按键单击检测(延时消抖+定时器扫描)

目录 独立按键简介 按键抖动 模块接线 延时消抖 Key.h Key.c 定时器扫描按键代码 Key.h Key.c main.c 思考  MultiButton按键驱动 独立按键简介 ​ 轻触按键相当于一种电子开关,按下时开关接通,松开时开关断开,实现原理是通过轻触按键内部的金属弹片受力弹动来实现接通与断开。  ​ 按键抖动 由于按键内部使用的是机

ConstraintLayout布局里的一个属性app:layout_constraintDimensionRatio

ConstraintLayout 这是一个约束布局,可以尽可能的减少布局的嵌套。有一个属性特别好用,可以用来动态限制宽或者高app:layout_constraintDimensionRatio 关于app:layout_constraintDimensionRatio参数 app:layout_constraintDimensionRatio=“h,1:1” 表示高度height是动态变化