Skip to content

Commit eb9f7a0

Browse files
author
Jeff Brown
committed
Fix policy issues when screen is off. (DO NOT MERGE)
Rewrote interceptKeyBeforeQueueing to make the handling more systematic. Behavior should be identical except: - We never pass keys to applications when the screen is off and the keyguard is not showing (the proximity sensor turned off the screen). Previously we passed all non-wake keys through in this case which caused a bug on Crespo where the screen would come back on if a soft key was held at the time of power off because the resulting key up event would sneak in just before the keyguard was shown. It would then be passed through to the dispatcher which would poke user activity and wake up the screen. - We propagate the key flags when broadcasting media keys which ensures that recipients can tell when the key is canceled. - We ignore endcall or power if canceled (shouldn't happen anyways). Changed the input dispatcher to not poke user activity for canceled events since they are synthetic and should not wake the device. Changed the lock screen so that it does not poke the wake lock when the grab handle is released. This fixes a bug where the screen would come back on immediately if the power went off while the user was holding one of the grab handles because the sliding tab would receive an up event after screen turned off and release the grab handles. Bug: 3144874 Change-Id: Iebb91e10592b4ef2de4b1dd3a2e1e4254aacb697
1 parent 2bf89b2 commit eb9f7a0

8 files changed

Lines changed: 256 additions & 257 deletions

File tree

core/java/android/view/WindowManagerPolicy.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,18 @@ public int prepareAddWindowLw(WindowState win,
544544
* Generally, it's best to keep as little as possible in the queue thread
545545
* because it's the most fragile.
546546
* @param whenNanos The event time in uptime nanoseconds.
547+
* @param action The key event action.
548+
* @param flags The key event flags.
547549
* @param keyCode The key code.
548-
* @param down True if the key is down.
550+
* @param scanCode The key's scan code.
549551
* @param policyFlags The policy flags associated with the key.
550552
* @param isScreenOn True if the screen is already on
551553
*
552554
* @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
553555
* {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
554556
*/
555-
public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, int policyFlags,
556-
boolean isScreenOn);
557+
public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
558+
int keyCode, int scanCode, int policyFlags, boolean isScreenOn);
557559

558560
/**
559561
* Called from the input dispatcher thread before a key is dispatched to a window.
@@ -571,14 +573,15 @@ public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
571573
* @param action The key event action.
572574
* @param flags The key event flags.
573575
* @param keyCode The key code.
576+
* @param scanCode The key's scan code.
574577
* @param metaState bit mask of meta keys that are held.
575578
* @param repeatCount Number of times a key down has repeated.
576579
* @param policyFlags The policy flags associated with the key.
577580
* @return Returns true if the policy consumed the event and it should
578581
* not be further dispatched.
579582
*/
580583
public boolean interceptKeyBeforeDispatching(WindowState win, int action, int flags,
581-
int keyCode, int metaState, int repeatCount, int policyFlags);
584+
int keyCode, int scanCode, int metaState, int repeatCount, int policyFlags);
582585

583586
/**
584587
* Called when layout of the windows is about to start.

libs/ui/InputDispatcher.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,8 +1405,13 @@ String8 InputDispatcher::getApplicationWindowLabelLocked(const InputApplication*
14051405

14061406
void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
14071407
int32_t eventType = POWER_MANAGER_BUTTON_EVENT;
1408-
if (eventEntry->type == EventEntry::TYPE_MOTION) {
1408+
switch (eventEntry->type) {
1409+
case EventEntry::TYPE_MOTION: {
14091410
const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry);
1411+
if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) {
1412+
return;
1413+
}
1414+
14101415
if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
14111416
switch (motionEntry->action) {
14121417
case AMOTION_EVENT_ACTION_DOWN:
@@ -1424,6 +1429,15 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
14241429
break;
14251430
}
14261431
}
1432+
break;
1433+
}
1434+
case EventEntry::TYPE_KEY: {
1435+
const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry);
1436+
if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) {
1437+
return;
1438+
}
1439+
break;
1440+
}
14271441
}
14281442

14291443
CommandEntry* commandEntry = postCommandLocked(

policy/src/com/android/internal/policy/impl/LockScreen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,12 @@ public void onGrabbedStateChange(View v, int grabbedState) {
333333
mSelector.setRightHintText(mSilentMode ? R.string.lockscreen_sound_on_label
334334
: R.string.lockscreen_sound_off_label);
335335
}
336-
mCallback.pokeWakelock();
336+
// Don't poke the wake lock when returning to a state where the handle is
337+
// not grabbed since that can happen when the system (instead of the user)
338+
// cancels the grab.
339+
if (grabbedState != SlidingTab.OnTriggerListener.NO_HANDLE) {
340+
mCallback.pokeWakelock();
341+
}
337342
}
338343

339344
/**

0 commit comments

Comments
 (0)