Within axp202 device driver, the driver sends KEY_POWER to Android when user press POWER button on board, no matter what a long OR short press.
But Android responds differently:
long press: pop up a POWER OFF dialogue box.
Enable DEBUG in driver:
short press: interrupt -- short press -- rising edge -- falling edge -- timer handler
long press: interrupt -- long press -- falling edge -- timer handler
The difference lies in there is no rising edge within 'long press' procedure,
And,
In Android, (frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java)
public int interceptKeyBeforeQueueing(KeyEvent event,
int policyFlags,
boolean isScreenOn) {
......
switch (keyCode) {
......
case KeyEvent.KEYCODE_POWER: {
if (down) { // 如果是按下键
if (isScreenOn && !mPowerKeyTriggered
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
mPowerKeyTriggered = true; // 按键触发为true
mPowerKeyTime = event.getDownTime(); // 记录事件时间
cancelPendingRingerChordAction(); // 结束音量长按事件
interceptScreenshotChord(); // 判断是否是截屏处理
}
// 当电话铃响起时,则会静音,而正在通话时,则会挂掉电话
ITelephony telephonyService = getTelephonyService();
boolean hungUp = false;
if (telephonyService != null) {
......
}
......
// 延迟固定时间触发长按事件,长按事件主要是弹出全局对话框
interceptPowerKeyDown(!isScreenOn || hungUp
|| mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
}
else { //进入sleep模式
mPowerKeyTriggered = false;
cancelPendingScreenshotChordAction();
if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
}
CONCLUSION: The dirver always sends KEY_POWER to system no matter what
the user's activity (long/short press) is. The system will
handle the event according to key code (KEY_POWER) as well
as key status (up/down).
But Android responds differently:
long press: pop up a POWER OFF dialogue box.
short press: go to sleep directly.
WHY?
Enable DEBUG in driver:
short press: interrupt -- short press -- rising edge -- falling edge -- timer handler
long press: interrupt -- long press -- falling edge -- timer handler
The difference lies in there is no rising edge within 'long press' procedure,
And,
In Android, (frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java)
public int interceptKeyBeforeQueueing(KeyEvent event,
int policyFlags,
boolean isScreenOn) {
......
switch (keyCode) {
......
case KeyEvent.KEYCODE_POWER: {
if (down) { // 如果是按下键
if (isScreenOn && !mPowerKeyTriggered
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
mPowerKeyTriggered = true; // 按键触发为true
mPowerKeyTime = event.getDownTime(); // 记录事件时间
cancelPendingRingerChordAction(); // 结束音量长按事件
interceptScreenshotChord(); // 判断是否是截屏处理
}
// 当电话铃响起时,则会静音,而正在通话时,则会挂掉电话
ITelephony telephonyService = getTelephonyService();
boolean hungUp = false;
if (telephonyService != null) {
......
}
......
// 延迟固定时间触发长按事件,长按事件主要是弹出全局对话框
interceptPowerKeyDown(!isScreenOn || hungUp
|| mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
}
else { //进入sleep模式
mPowerKeyTriggered = false;
cancelPendingScreenshotChordAction();
if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
}
CONCLUSION: The dirver always sends KEY_POWER to system no matter what
the user's activity (long/short press) is. The system will
handle the event according to key code (KEY_POWER) as well
as key status (up/down).