需求分析
投影息屏的功能说明
机器人在投影播放视频时,面部平板页面与投影页面保持一致,且处于常亮状态。若在比较暗的环境下观看,极大影响了观看投影的质量,同时也会分散观看人的注意力。解决方案是在开启投影后,可机器人面部平板可自定义息屏时间,在相应时间内屏幕无任何操作自动息屏,息屏后可通过点击屏幕或拍头重新点亮屏幕。
系统提供的接口
讨论后决定系统端提供三个接口给app:
- 开启投影模式
- 关闭投影模式
- 当前是否是投影息屏模式
接口定义如下:
/*
*开启投影模式
*int:息屏延时
*/
public void startProjectShutdownMode(int time)
/*
*关闭投影模式
*
*/
public void stopProjectShutdownMode()
/*
*
*当前是否是投影息屏模式
*return:true false
*
*/
public boolean currentProjectShutdownMode()
系统端代码提交
frameworks
framework的修改分为两部分
1.投影息屏功能的支持
其实功能实现就是如果处于投影息屏模式的话,每一次input事件
后启动一个延时关闭屏幕的息屏任务。如果期间无input事件
,则息屏;如果出现了新的input事件
,则刷新
息屏任务的延时时间。
具体判断input事件
的触发放到了userActivityFromNative
方法中,在persist.sys.evolver.projecttime中保存的是息屏的时间,app会通过startProjectShutdownMode
方法来设置该值。
2.增加面罩中间状态按键的支持。(原因见后面“遇到的问题”小结)
From ff765fc7046afa615c2ad54f647c2912c639f9be Mon Sep 17 00:00:00 2001
From: liuxiuquan <liuxiuquan@ren001.com>
Date: Wed, 21 Mar 2018 13:41:40 +0800
Subject: [PATCH] [liuxq]add for project shutdown screen
Change-Id: I9b7d71779fdbe0f3470dca20fdd18bb46dd4972f
---
base/core/java/android/os/IPowerManager.aidl | 5 +
base/core/java/android/os/PowerManager.java | 25 +++++
base/core/java/android/view/KeyEvent.java | 7 +-
base/core/res/res/values/attrs.xml | 5 +-
.../policy/impl/PhoneWindowManager.java | 48 +++++++--
.../server/power/PowerManagerService.java | 102 ++++++++++++++++++
native/include/android/keycodes.h | 1 +
native/include/input/KeycodeLabels.h | 1 +
native/libs/input/Input.cpp | 1 +
9 files changed, 183 insertions(+), 12 deletions(-)
diff --git a/base/core/java/android/os/IPowerManager.aidl b/base/core/java/android/os/IPowerManager.aidl
index 30d6b1c43..d2dde2d6e 100755
--- a/base/core/java/android/os/IPowerManager.aidl
+++ b/base/core/java/android/os/IPowerManager.aidl
@@ -59,4 +59,9 @@ interface IPowerManager
void bootFastWake(long time);
boolean isBootFastStatus();
boolean isBootFastWakeFromStandby();
+
+ //20180321 liuxq add for project shutdown screen
+ void startProjectShutdownMode(int time);
+ void stopProjectShutdownMode();
+ boolean currentProjectShutdownMode();
}
diff --git a/base/core/java/android/os/PowerManager.java b/base/core/java/android/os/PowerManager.java
index 6ec68f3f3..d21998a35 100755
--- a/base/core/java/android/os/PowerManager.java
+++ b/base/core/java/android/os/PowerManager.java
@@ -514,6 +514,31 @@ public final class PowerManager {
}
}
+ //20180321 liuxq add for project shutdown screen begin
+ public void startProjectShutdownMode(int time) {
+ try {
+ mService.startProjectShutdownMode(time);
+ } catch (RemoteException e) {
+ }
+ }
+
+ public void stopProjectShutdownMode() {
+ try {
+ mService.stopProjectShutdownMode();
+ } catch (RemoteException e) {
+ }
+ }
+
+ public boolean currentProjectShutdownMode() {
+ boolean retValue = false;
+ try {
+ retValue=mService.currentProjectShutdownMode();
+ } catch (RemoteException e) {
+ }
+ return retValue;
+ }
+ //20180321 liuxq add for project shutdown screen end
+
/**
* Forces the device to start napping.
* <p>
diff --git a/base/core/java/android/view/KeyEvent.java b/base/core/java/android/view/KeyEvent.java
index 8e2aa535d..b3f9ffd70 100644
--- a/base/core/java/android/view/KeyEvent.java
+++ b/base/core/java/android/view/KeyEvent.java
@@ -649,7 +649,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
public static final int KEYCODE_GESTURE_RIGHT = 230;
- private static final int LAST_KEYCODE = KEYCODE_GESTURE_RIGHT;
+ //private static final int LAST_KEYCODE = KEYCODE_GESTURE_RIGHT;
// NOTE: If you add a new keycode here you must also add it to:
// isSystem()
@@ -669,6 +669,11 @@ public class KeyEvent extends InputEvent implements Parcelable {
public static final int KEYCODE_MASK_OPEN = 231;
public static final int KEYCODE_MASK_CLOSE = 232;
public static final int KEYCODE_HEADTOUCH = 233;
+ //20180321 liuxq add for project shutdown screen begin
+ public static final int KEYCODE_MASK_ONPROGRESS = 234;
+ private static final int LAST_KEYCODE = KEYCODE_GESTURE_RIGHT;
+ //20180321 liuxq add for project shutdown screen end
+
// Symbolic names of all key codes.
private static final SparseArray<String> KEYCODE_SYMBOLIC_NAMES = new SparseArray<String>();
private static void populateKeycodeSymbolicNames() {
diff --git a/base/core/res/res/values/attrs.xml b/base/core/res/res/values/attrs.xml
index 19cf63384..478df4422 100644
--- a/base/core/res/res/values/attrs.xml
+++ b/base/core/res/res/values/attrs.xml
@@ -1342,7 +1342,9 @@
<eat-comment />
<!-- This enum provides the same keycode values as can be found in
- {@link android.view.KeyEvent}. -->
+ {@link android.view.KeyEvent}.
+ 20180321 liuxq add KEYCODE_MASK_ONPROGRESS for project shutdown screen
+ -->
<attr name="keycode">
<enum name="KEYCODE_UNKNOWN" value="0" />
<enum name="KEYCODE_SOFT_LEFT" value="1" />
@@ -1578,6 +1580,7 @@
<enum name="KEYCODE_MASK_OPEN" value="231" />
<enum name="KEYCODE_MASK_CLOSE" value="232" />
<enum name="KEYCODE_HEADTOUCH" value="233" />
+ <enum name="KEYCODE_MASK_ONPROGRESS" value="234" />
</attr>
<!-- ***************************************************************** -->
diff --git a/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 015fee8c5..1129f526f 100755
--- a/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -4560,17 +4560,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Log.d(TAG, "--KEYCODE_MASK_OPEN-- action="
+ (event.getAction() == KeyEvent.ACTION_UP ? "ACTION_UP" : "ACTION_DOWN"));
- if( (MASK_INIT_STATUS == 0||MASK_INIT_STATUS == 1) &&
+ /* if( (MASK_INIT_STATUS == 0||MASK_INIT_STATUS == 1) &&
event.getAction()==KeyEvent.ACTION_DOWN && MASK_INIT){
Log.d(TAG,"KEYCODE_MASK init status is open/close. skip ACTION_DOWN this time "+
" MASK_INIT_STATUS= "+MASK_INIT_STATUS+" MASK_INIT="+MASK_INIT);
MASK_INIT = false;
break;
- }
+ }*/
- if(event.getAction() == KeyEvent.ACTION_UP) {
- sendKeyBroadcast(2);
- } else {
+ //20180321 liuxq add for project shutdown screen
+ if(event.getAction() == KeyEvent.ACTION_DOWN) {
sendKeyBroadcast(0);
}
break;
@@ -4579,21 +4578,30 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Log.d(TAG, "--KEYCODE_MASK_CLOSE-- action="
+ (event.getAction() == KeyEvent.ACTION_UP ? "ACTION_UP" : "ACTION_DOWN"));
- if( (MASK_INIT_STATUS == 0||MASK_INIT_STATUS == 1) &&
+ /* if( (MASK_INIT_STATUS == 0||MASK_INIT_STATUS == 1) &&
event.getAction()==KeyEvent.ACTION_DOWN && MASK_INIT){
Log.d(TAG,"KEYCODE_MASK init status is OnProgress. skip ACTION_DOWN this time "+
" MASK_INIT_STATUS= "+MASK_INIT_STATUS+" MASK_INIT="+MASK_INIT);
MASK_INIT = false;
break;
- }
+ }*/
- if(event.getAction() == KeyEvent.ACTION_UP) {
- sendKeyBroadcast(2);
- } else {
+ //20180321 liuxq add for project shutdown screen
+ if(event.getAction() == KeyEvent.ACTION_DOWN) {
sendKeyBroadcast(1);
}
break;
}
+ //liuxq
+ case KeyEvent.KEYCODE_MASK_ONPROGRESS:{
+ Log.d(TAG, "KEYCODE_MASK_ONPROGRESS "+(down ? "down":"up")
+ +". send KEYCODE_MASK_ONPROGRESS broadcast.");
+ if(event.getAction() == KeyEvent.ACTION_DOWN) {
+ sendKeyBroadcast(2);
+ }
+
+ break;
+ }
case KeyEvent.KEYCODE_HEADTOUCH:{
Log.d(TAG, "KEYCODE_HEADTOUCH "+(down ? "down":"up")
+". send HEADTOUCH broadcast.");
@@ -4610,6 +4618,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
private void sendKeyBroadcast(int key) {
+ //20180321 liuxq add for project shutdown screen begin
+ int lcd_delay_timeout = SystemProperties.getInt("persist.sys.evolver.projecttime", -1);
+ int projectOn=SystemProperties.getInt("persist.sys.evolver.project", 0);
+ //20180321 liuxq add for project shutdown screen end
+
switch (key) {
case 0:
Intent intentO = new Intent(Intent.ACTION_EVOLVER_MASK_STATUS_CHANGE);
@@ -4617,6 +4630,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mContext.sendBroadcast(intentO);
MASK_CLOSE = false;
Log.d(TAG, "send KEYCODE_MASK_OPEN broadcast. MASK_CLOSE="+MASK_CLOSE);
+ //20180321 liuxq add for project shutdown screen begin
+ if(projectOn==1&&lcd_delay_timeout!=-1&&!mPowerManager.currentProjectShutdownMode()){
+ mPowerManager.startProjectShutdownMode(lcd_delay_timeout);
+ }
+ //20180321 liuxq add for project shutdown screen end
break;
case 1:
Intent intentC = new Intent(Intent.ACTION_EVOLVER_MASK_STATUS_CHANGE);
@@ -4625,6 +4643,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mContext.sendBroadcast(intentC);
MASK_CLOSE = true;
Log.d(TAG, "send KEYCODE_MASK_CLOSE broadcast. MASK_CLOSE="+MASK_CLOSE);
+ //20180321 liuxq add for project shutdown screen begin
+ if(mPowerManager.currentProjectShutdownMode()){
+ mPowerManager.stopProjectShutdownMode();
+ }
+ //20180321 liuxq add for project shutdown screen end
break;
case 2:
Intent intentP = new Intent(Intent.ACTION_EVOLVER_MASK_STATUS_CHANGE);
@@ -4632,6 +4655,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mContext.sendBroadcast(intentP);
MASK_CLOSE = false;
Log.d(TAG, "send KEYCODE_MASK_ONPROGRESS broadcast. MASK_CLOSE="+MASK_CLOSE);
+ //20180321 liuxq add for project shutdown screen begin
+ if(projectOn==1&&lcd_delay_timeout!=-1&&!mPowerManager.currentProjectShutdownMode()){
+ mPowerManager.startProjectShutdownMode(lcd_delay_timeout);
+ }
+ //20180321 liuxq add for project shutdown screen end
break;
default:
Log.e(TAG, "KEY error");
diff --git a/base/services/java/com/android/server/power/PowerManagerService.java b/base/services/java/com/android/server/power/PowerManagerService.java
index 614810a7e..75e161316 100755
--- a/base/services/java/com/android/server/power/PowerManagerService.java
+++ b/base/services/java/com/android/server/power/PowerManagerService.java
@@ -392,6 +392,9 @@ public final class PowerManagerService extends IPowerManager.Stub
// Time when we last logged a warning about calling userActivity() without permission.
private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE;
+ //20180321 liuxq add for project shutdown screen
+ private boolean mHdmiConnect;
+
private native void nativeInit();
private static native void nativeSetPowerState(boolean screenOn, boolean screenBright);
@@ -898,6 +901,89 @@ public final class PowerManagerService extends IPowerManager.Stub
}
}
+
+ //20180321 liuxq add for project shutdown screen begin
+ private void turnonScreen(){
+ boolean LOGABLE = Log.isLoggable(TAG, Log.VERBOSE);
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L917 enter turnonScreen");
+ }
+ mHandler1.removeCallbacks(mScreenTimeout);
+ if(mTimeout){
+ try {
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L925 enter turnOffLcdLight(false,mScreenBrightnessSetting)");//open the light
+ }
+ turnOffLcdLight(false,mScreenBrightnessSetting);
+ } catch (Exception e) {
+ Slog.e(TAG, "Exception"+e);
+ }
+ }
+ mTimeout=false;
+ lockScreenOff();
+ }
+
+ private void lockScreenOff() {
+ if(lcd_delay_timeout!=-1){
+ mHandler1.postAtTime(mScreenTimeout, SystemClock.uptimeMillis() + 1000 * lcd_delay_timeout);
+ }
+ }
+
+ @Override // Binder call
+ public void startProjectShutdownMode(int time) {
+ boolean LOGABLE = Log.isLoggable(TAG, Log.VERBOSE);
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L940 enter startProjectShutdownMode. time="+time);
+ }
+ lcd_delay_timeout=time;
+ mHdmiConnect=true;
+ turnonScreen();
+ }
+ @Override // Binder call
+ public void stopProjectShutdownMode() {
+ boolean LOGABLE = Log.isLoggable(TAG, Log.VERBOSE);
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L944 enter stopProjectShutdownMode.");
+ }
+ mHdmiConnect=false;
+ turnOffLcdLight(false, mScreenBrightnessSetting);
+ mHandler1.removeCallbacks(mScreenTimeout);
+ }
+
+ @Override // Binder call
+ public boolean currentProjectShutdownMode() {
+ boolean LOGABLE = Log.isLoggable(TAG, Log.VERBOSE);
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L949 enter currentProjectShutdownMode.mHdmiConnect="+mHdmiConnect);
+ }
+ return mHdmiConnect;
+ }
+
+ private int lcd_delay_timeout = -1;
+ private Handler mHandler1 = new Handler();
+ private boolean mTimeout=false;
+
+ Runnable mScreenTimeout = new Runnable() {
+ public void run() {
+ synchronized (this) {
+ if(mHdmiConnect==true){
+ try {
+ boolean LOGABLE = Log.isLoggable(TAG, Log.VERBOSE);
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L954 turnOffLcdLight(true, 0)");//shutdown light
+ }
+ turnOffLcdLight(true, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }finally{
+ mTimeout=true;
+ }
+ }
+ }
+ }
+ };
+ //20180321 liuxq add for project shutdown screen end
+
@Override // Binder call
public void userActivity(long eventTime, int event, int flags) {
@@ -935,6 +1021,22 @@ public final class PowerManagerService extends IPowerManager.Stub
// Called from native code.
private void userActivityFromNative(long eventTime, int event, int flags) {
+ //20180321 liuxq add for project shutdown screen begin
+ boolean LOGABLE = Log.isLoggable(TAG, Log.VERBOSE);
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L938 userActivityFromNative,eventTime"+eventTime+",event="+event+",flags="+flags);
+ }
+
+ synchronized (mLock) {
+ if(mHdmiConnect==true){
+ if(LOGABLE){
+ Slog.d(TAG,"liuxq L1005 userActivityFromNative turnonScreen");
+ }
+ turnonScreen();//liuxq turn on the screen,and post a screen off delay
+ }
+ }
+ //20180321 liuxq add for project shutdown screen end
+
if(!mBootFastStats){
userActivityInternal(eventTime, event, flags, Process.SYSTEM_UID);
}else{
diff --git a/native/include/android/keycodes.h b/native/include/android/keycodes.h
index 1f9a370a6..141f15d7d 100644
--- a/native/include/android/keycodes.h
+++ b/native/include/android/keycodes.h
@@ -280,6 +280,7 @@ enum {
AKEYCODE_MASK_OPEN = 231,
AKEYCODE_MASK_CLOSE = 232,
AKEYCODE_HEADTOUCH = 233,
+ AKEYCODE_MASK_ONPROGRESS = 234,//20180321 liuxq add for project shutdown screen
};
#ifdef __cplusplus
diff --git a/native/include/input/KeycodeLabels.h b/native/include/input/KeycodeLabels.h
index 5c3811513..d7af3f8e9 100644
--- a/native/include/input/KeycodeLabels.h
+++ b/native/include/input/KeycodeLabels.h
@@ -261,6 +261,7 @@ static const KeycodeLabel KEYCODES[] = {
{ "MASK_OPEN", 231 },
{ "MASK_CLOSE", 232 },
{ "HEADTOUCH", 233 },
+ { "MASK_ONPROGRESS", 234 },//20180321 liuxq add for project shutdown screen
{ NULL, 0 }
};
diff --git a/native/libs/input/Input.cpp b/native/libs/input/Input.cpp
index b0274528b..f4574fa32 100644
--- a/native/libs/input/Input.cpp
+++ b/native/libs/input/Input.cpp
@@ -122,6 +122,7 @@ bool KeyEvent::isSystemKey(int32_t keyCode) {
case AKEYCODE_MASK_OPEN:
case AKEYCODE_MASK_CLOSE:
case AKEYCODE_HEADTOUCH:
+ case AKEYCODE_MASK_ONPROGRESS://20180321 liuxq add for project shutdown screen
return true;
}
--
2.19.1
device
device的修改很简单:
1.增加property
支持
2.在kl
文件中增加面罩中间状态按键的支持。
From 0252364efa738104aa81872eb6e45ea6d86914de Mon Sep 17 00:00:00 2001
From: liuxiuquan <liuxiuquan@ren001.com>
Date: Wed, 21 Mar 2018 13:47:10 +0800
Subject: [PATCH] [liuxq]add for project shutdown screen
Change-Id: Iec229dda8e18179bb1f2aedd257fab5c7a70a590
---
softwinner/fabo/fabo.mk | 4 ++++
softwinner/kylin-p2/configs/sunxi-keyboard.kl | 2 ++
2 files changed, 6 insertions(+)
diff --git a/softwinner/fabo/fabo.mk b/softwinner/fabo/fabo.mk
index c9b34388..d899832a 100644
--- a/softwinner/fabo/fabo.mk
+++ b/softwinner/fabo/fabo.mk
@@ -208,6 +208,10 @@ PRODUCT_PROPERTY_OVERRIDES += \
PRODUCT_PROPERTY_OVERRIDES += \
ro.update.mobile_app=0
+#20180321 liuxq add for project shutdown screen
+PRODUCT_PROPERTY_OVERRIDES += \
+ persist.sys.evolver.projecttime=-1
+
$(call inherit-product-if-exists, device/softwinner/fabo/modules/modules.mk)
PRODUCT_AAPT_CONFIG := xlarge hdpi xhdpi
diff --git a/softwinner/kylin-p2/configs/sunxi-keyboard.kl b/softwinner/kylin-p2/configs/sunxi-keyboard.kl
index 46ea1d32..e17af17f 100644
--- a/softwinner/kylin-p2/configs/sunxi-keyboard.kl
+++ b/softwinner/kylin-p2/configs/sunxi-keyboard.kl
@@ -3,3 +3,5 @@ key 115 VOLUME_DOWN
key 249 MASK_OPEN
key 250 MASK_CLOSE
key 251 HEADTOUCH
+# 20180321 liuxq add for project shutdown screen
+key 252 MASK_ONPROGRESS
--
2.19.1
kernel
增加面罩中间状态按键的支持,具体原因见下面“遇到的问题”
From 8619feff2a77b4ea6049003ee259ccf519c30529 Mon Sep 17 00:00:00 2001
From: liuxiuquan <liuxiuquan@ren001.com>
Date: Wed, 21 Mar 2018 13:49:02 +0800
Subject: [PATCH] [liuxq]add for project shutdown screen
Change-Id: I57aa2dc6b83dda58f50ea9691a7064bf9d6cd712
---
.../drivers/input/keyboard/sun8i-keyboard.h | 4 +-
linux-3.4/drivers/input/keyboard/sunxi-vol.c | 68 ++++++++++++-------
linux-3.4/include/linux/input.h | 3 +
3 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/linux-3.4/drivers/input/keyboard/sun8i-keyboard.h b/linux-3.4/drivers/input/keyboard/sun8i-keyboard.h
index f24952b17..e417b4cc6 100755
--- a/linux-3.4/drivers/input/keyboard/sun8i-keyboard.h
+++ b/linux-3.4/drivers/input/keyboard/sun8i-keyboard.h
@@ -9,7 +9,8 @@
#define INPUT_DEV_NAME ("sunxi-keyboard")
-#define KEY_MAX_CNT (14)
+//20180321 liuxq add for project shutdown screen
+#define KEY_MAX_CNT (15)
#ifdef CONFIG_ARCH_SUN9IW1P1
#define KEY_BASSADDRESS (0xf6001800)
@@ -134,6 +135,7 @@ static unsigned int sunxi_scankeycodes[KEY_MAX_CNT] = {
[11] = KEY_MASKHIGH,
[12] = KEY_MASKLOW,
[13] = KEY_HEADTOUCH,
+ [14] = KEY_MASKPROGRESS,//20180321 liuxq add for project shutdown screen
};
#endif
diff --git a/linux-3.4/drivers/input/keyboard/sunxi-vol.c b/linux-3.4/drivers/input/keyboard/sunxi-vol.c
index 11929c7ea..e63c488e4 100644
--- a/linux-3.4/drivers/input/keyboard/sunxi-vol.c
+++ b/linux-3.4/drivers/input/keyboard/sunxi-vol.c
@@ -188,22 +188,32 @@ static void vol_check_func(struct work *work){
mask_init = 0;
printk("skip the first down. init status is open\n");
}else{
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[11], 1);
- input_sync(sunxikbd_dev);
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[11], 1);
+ input_sync(sunxikbd_dev);
+ //20180321 liuxq add for project shutdown screen begin
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[11], 0);
+ input_sync(sunxikbd_dev);
+ //20180321 liuxq add for project shutdown screen end
}
}else{//highkey open
if (val1_init==2){
- printk("evolve facemask init. val1= %d val1_init =%d !\n",val1,val1_init);
- //sc. action down event for init mask status
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[11], 1);
- input_sync(sunxikbd_dev);
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[11], 0);
- input_sync(sunxikbd_dev);
- val2_init=val1_init=0;
+ printk("evolve facemask init. val1= %d val1_init =%d !\n",val1,val1_init);
+ //sc. action down event for init mask status
+ //20180321 liuxq add for project shutdown screen begin
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 1);
+ input_sync(sunxikbd_dev);
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 0);
+ //20180321 liuxq add for project shutdown screen end
+ input_sync(sunxikbd_dev);
+ val2_init=val1_init=0;
}else{
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[11], 0);
- input_sync(sunxikbd_dev);
- }
+ //20180321 liuxq add for project shutdown screen begin
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 1);
+ input_sync(sunxikbd_dev);
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 0);
+ //20180321 liuxq add for project shutdown screen end
+ input_sync(sunxikbd_dev);
+ }
}
}
@@ -215,21 +225,31 @@ static void vol_check_func(struct work *work){
mask_init = 0;
printk("skip the first down. init status is closed\n");
}else{
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[12], 1);
- input_sync(sunxikbd_dev);
+ //20180321 liuxq add for project shutdown screen begin
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[12], 1);
+ input_sync(sunxikbd_dev);
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[12], 0);
+ input_sync(sunxikbd_dev);
+ //20180321 liuxq add for project shutdown screen end
}
}else{//lowkey open
if(val2_init==2){
- printk("evolve facemask init. val2= %d val2_init =%d !\n",val2,val2_init);
- //sc. action down event for init mask status
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[12], 1);
- input_sync(sunxikbd_dev);
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[12], 0);
- input_sync(sunxikbd_dev);
- val2_init=val1_init=0;
- }else{
- input_report_key(sunxikbd_dev,sunxi_scankeycodes[12], 0);
- input_sync(sunxikbd_dev);
+ printk("evolve facemask init. val2= %d val2_init =%d !\n",val2,val2_init);
+ //sc. action down event for init mask status
+ //20180321 liuxq add for project shutdown screen begin
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 1);
+ input_sync(sunxikbd_dev);
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 0);
+ //20180321 liuxq add for project shutdown screen end
+ input_sync(sunxikbd_dev);
+ val2_init=val1_init=0;
+ }else{
+ //20180321 liuxq add for project shutdown screen begin
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 1);
+ input_sync(sunxikbd_dev);
+ input_report_key(sunxikbd_dev,sunxi_scankeycodes[14], 0);
+ //20180321 liuxq add for project shutdown screen end
+ input_sync(sunxikbd_dev);
}
}
}
diff --git a/linux-3.4/include/linux/input.h b/linux-3.4/include/linux/input.h
index 60df515f6..d455d5514 100644
--- a/linux-3.4/include/linux/input.h
+++ b/linux-3.4/include/linux/input.h
@@ -479,6 +479,9 @@ struct input_keymap_entry {
#define KEY_HEADTOUCH 251
/* end */
+//20180321 liuxq add for project shutdown screen
+#define KEY_MASKPROGRESS 252
+
/* Code 255 is reserved for special needs of AT keyboard driver */
--
2.19.1
app端调用
因为不想再提供新的android.jar给app了,所以给他们使用反射
调用的方法,尽管效率可能慢点,不过确实方便了很多。
调用方法:
IPowerManager iWindowManager= IPowerManager.Stub.asInterface(
ServiceManager.getService(Context.POWER_SERVICE));
//Class<?> cls=Class.forName("android.os.IPowerManager");
//开启
try {
Class<?> cls=Class.forName("android.os.IPowerManager");
int time=30;
Method startProjectShutdownMode=cls.getDeclaredMethod("startProjectShutdownMode",int.class);
startProjectShutdownMode.invoke(iWindowManager,time);
} catch (Exception e) {
e.printStackTrace();
}
//关闭
try {
Class<?> cls=Class.forName("android.os.IPowerManager");
Method stopProjectShutdownMode=cls.getDeclaredMethod("stopProjectShutdownMode");
stopProjectShutdownMode.invoke(iWindowManager);
} catch (Exception e) {
e.printStackTrace();
}
//当前是否投影息屏模式
try {
Class<?> cls=Class.forName("android.os.IPowerManager");
Method currentProjectShutdownMode=cls.getDeclaredMethod("currentProjectShutdownMode");
boolean res= (Boolean) currentProjectShutdownMode.invoke(iWindowManager);
Log.d(TAG, "liuxq L158 currentProjectShutdownMode res="+res);
} catch (Exception e) {
e.printStackTrace();
}
遇到的问题
开发的过程中发现当面罩连接的限位开关按下的情况下会一直上报按下的事件给userActivityFromNative
。
最后跟了下代码发现之前动的同学写面罩驱动时,kernel
中按键按下只上报了一次按下事件,因为一直没有再报按键弹起的事件,系统会判断当前一直处于长按导致按下事件不停的上报。讨论后决定将这块的逻辑改成限位开关按下分别上报按键按下和弹起的事件,相应的限位开关弹起也报一对按键按下和弹起的事件。因此当限位开关弹起的时候,需要额外加入一个新的type的按键。
具体来说明一下
目前面罩用了两组限位开关:
记为key1,key2吧
之前的按键事件:
key1 | key2 | |
---|---|---|
按下 | keycode[11], 1 | keycode[12], 1 |
弹起 | keycode[11], 0 | keycode[11], 0 |
修改之后的按键事件:
key1 | key2 | |
---|---|---|
按下 | (keycode[11], 1) and (keycode[11], 0) | (keycode[12], 1) and (keycode[12], 0) |
弹起 | (keycode[14], 1) and (keycode[14], 0) | (keycode[14], 1) and (keycode[14], 0) |
一些补充
- app组开启投影会把状态存在
SystemProperty
的persist.sys.evolver.project
中1
开启0
关闭 - 设置更新息屏延时的时候会把时间存在
SystemProperty
的persist.sys.evolver.projecttime
中(15,30,60,-1)
,其中-1
是禁止息屏 - 设置中更新的息屏时间,如果是
-1
调用stopProjectShutdownMode
方法,如果是其他值(15,30,60)
调用startProjectShutdownMode(int time)
方法 - 如果要屏蔽某个按键,可以在
PhoneWindowManager
中的interceptKeyBeforeQueueing
方法&= ~ACTION_PASS_TO_USER
来进行屏蔽操作 - 代码中有对面罩状态
MASK
的判断,这个根据实际情况来。我们定义的是当面罩关闭的时候退出投影息屏模式,如果需要重新进入由面罩关闭状态启动的app来控制。
代码基于kk