Skip to content

Commit c458ce9

Browse files
author
Jeff Brown
committed
Add support for using the lid switch to turn off the screen.
Added a config option to allow the lid switch to turn off the screen. This is a closer match to what a lid switch should be doing. Removed an old feature to bypass keyguard when keyboard is visible because the way it was plumbed in made bad assumptions about the meaning of the lid switch. Also, the last product we shipped that had a physical keyboard turned this config option off. So away it goes. We can bring it back someday if we really want it. It's questionable how useful the feature is anyhow, since it only works when the keyguard is unsecure and when the lid switch is unlikely to be jostled in the user's pocket. Fixed a bug where we would tell the power manager that the keyboard was visible even if the lid switch did not control the keyboard. This used to cause the power manager to try to set the keyboard brightness, which doesn't work. Bug: 6377115 Bug: 6406726 Change-Id: Ic84b71d09563d51c92cd1cf132fa8bdee6509103
1 parent 3ea8761 commit c458ce9

File tree

12 files changed

+54
-92
lines changed

12 files changed

+54
-92
lines changed

core/res/res/values/config.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@
287287
Default value is 2 minutes. -->
288288
<integer translatable="false" name="config_wifi_driver_stop_delay">120000</integer>
289289

290-
<!-- Flag indicating whether the keyguard should be bypassed when
291-
the slider is open. This can be set or unset depending how easily
292-
the slider can be opened (for example, in a pocket or purse). -->
293-
<bool name="config_bypass_keyguard_if_slider_open">true</bool>
294-
295290
<!-- Flag indicating whether the we should enable the automatic brightness in Settings.
296291
Software implementation will be used if config_hardware_auto_brightness_available is not set -->
297292
<bool name="config_automatic_brightness_available">false</bool>
@@ -374,11 +369,16 @@
374369
<integer name="config_lidKeyboardAccessibility">0</integer>
375370

376371
<!-- Indicate whether the lid state impacts the accessibility of
377-
the physical keyboard. 0 means it doesn't, 1 means it is accessible
372+
the navigation buttons. 0 means it doesn't, 1 means it is accessible
378373
when the lid is open, 2 means it is accessible when the lid is
379374
closed. The default is 0. -->
380375
<integer name="config_lidNavigationAccessibility">0</integer>
381376

377+
<!-- Indicate whether closing the lid causes the device to go to sleep and opening
378+
it causes the device to wake up.
379+
The default is false. -->
380+
<bool name="config_lidControlsSleep">false</bool>
381+
382382
<!-- Control the behavior when the user long presses the power button.
383383
0 - Nothing
384384
1 - Global actions menu

core/res/res/values/public.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,12 +1174,13 @@
11741174
<java-symbol type="attr" name="dialogTitleDecorLayout" />
11751175
<java-symbol type="attr" name="dialogTitleIconsDecorLayout" />
11761176
<java-symbol type="bool" name="config_allowAllRotations" />
1177-
<java-symbol type="bool" name="config_bypass_keyguard_if_slider_open" />
1177+
<java-symbol type="bool" name="config_annoy_dianne" />
11781178
<java-symbol type="bool" name="config_carDockEnablesAccelerometer" />
11791179
<java-symbol type="bool" name="config_deskDockEnablesAccelerometer" />
11801180
<java-symbol type="bool" name="config_disableMenuKeyInLockScreen" />
11811181
<java-symbol type="bool" name="config_enableLockBeforeUnlockScreen" />
11821182
<java-symbol type="bool" name="config_enableLockScreenRotation" />
1183+
<java-symbol type="bool" name="config_lidControlsSleep" />
11831184
<java-symbol type="bool" name="config_reverseDefaultRotation" />
11841185
<java-symbol type="bool" name="config_showNavigationBar" />
11851186
<java-symbol type="bool" name="target_honeycomb_needs_options_menu" />

core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/OverlayBaseTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public void testBooleanOverlay() throws Throwable {
6464
}
6565

6666
public void testBoolean() throws Throwable {
67-
// config_bypass_keyguard_if_slider_open has no overlay
68-
final int resId = com.android.internal.R.bool.config_bypass_keyguard_if_slider_open;
67+
// config_annoy_dianne has no overlay
68+
final int resId = com.android.internal.R.bool.config_annoy_dianne;
6969
assertResource(resId, true, true);
7070
}
7171

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public class KeyguardUpdateMonitor {
7272

7373
private IccCard.State mSimState = IccCard.State.READY;
7474

75-
private boolean mKeyguardBypassEnabled;
76-
7775
private boolean mDeviceProvisioned;
7876

7977
private BatteryStatus mBatteryStatus;
@@ -217,9 +215,6 @@ public void handleMessage(Message msg) {
217215
}
218216
};
219217

220-
mKeyguardBypassEnabled = context.getResources().getBoolean(
221-
com.android.internal.R.bool.config_bypass_keyguard_if_slider_open);
222-
223218
mDeviceProvisioned = Settings.Secure.getInt(
224219
mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
225220

@@ -660,10 +655,6 @@ public void reportSimUnlocked() {
660655
handleSimStateChange(new SimArgs(IccCard.State.READY));
661656
}
662657

663-
public boolean isKeyguardBypassEnabled() {
664-
return mKeyguardBypassEnabled;
665-
}
666-
667658
public boolean isDevicePluggedIn() {
668659
return isPluggedIn(mBatteryStatus);
669660
}

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
121121
*/
122122
protected static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
123123

124-
125-
/**
126-
* The default amount of time we stay awake (used for all key input) when
127-
* the keyboard is open
128-
*/
129-
protected static final int AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS = 10000;
130-
131124
/**
132125
* How long to wait after the screen turns off due to timeout before
133126
* turning on the keyguard (i.e, the user has this much time to turn
@@ -237,8 +230,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
237230

238231
private KeyguardUpdateMonitor mUpdateMonitor;
239232

240-
private boolean mKeyboardOpen = false;
241-
242233
private boolean mScreenOn = false;
243234

244235
// last known state of the cellular connection
@@ -589,22 +580,6 @@ public boolean isInputRestricted() {
589580
return mShowing || mNeedToReshowWhenReenabled || !mUpdateMonitor.isDeviceProvisioned();
590581
}
591582

592-
/**
593-
* Returns true if the change is resulting in the keyguard beign dismissed,
594-
* meaning the screen can turn on immediately. Otherwise returns false.
595-
*/
596-
public boolean doLidChangeTq(boolean isLidOpen) {
597-
mKeyboardOpen = isLidOpen;
598-
599-
if (mUpdateMonitor.isKeyguardBypassEnabled() && mKeyboardOpen
600-
&& !mKeyguardViewProperties.isSecure() && mKeyguardViewManager.isShowing()) {
601-
if (DEBUG) Log.d(TAG, "bypassing keyguard on sliding open of keyboard with non-secure keyguard");
602-
mHandler.sendEmptyMessage(KEYGUARD_DONE_AUTHENTICATING);
603-
return true;
604-
}
605-
return false;
606-
}
607-
608583
/**
609584
* Enable the keyguard if the settings are appropriate. Return true if all
610585
* work that will happen is done; returns false if the caller can wait for
@@ -955,8 +930,7 @@ public boolean onWakeMotionWhenKeyguardShowingTq() {
955930

956931
/** {@inheritDoc} */
957932
public void pokeWakelock() {
958-
pokeWakelock(mKeyboardOpen ?
959-
AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS : AWAKE_INTERVAL_DEFAULT_MS);
933+
pokeWakelock(AWAKE_INTERVAL_DEFAULT_MS);
960934
}
961935

962936
/** {@inheritDoc} */

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
6969
private boolean mEnableRingSilenceFallback = false;
7070

7171
// current configuration state of keyboard and display
72-
private int mKeyboardHidden;
7372
private int mCreationOrientation;
7473

7574
private boolean mSilentMode;
@@ -404,7 +403,6 @@ private boolean shouldEnableMenuKey() {
404403
mCallback = callback;
405404
mEnableMenuKeyInLockScreen = shouldEnableMenuKey();
406405
mCreationOrientation = configuration.orientation;
407-
mKeyboardHidden = configuration.hardKeyboardHidden;
408406

409407
if (LockPatternKeyguardView.DEBUG_CONFIGURATION) {
410408
Log.v(TAG, "***** CREATING LOCK SCREEN", new RuntimeException());
@@ -506,12 +504,6 @@ void updateConfiguration() {
506504
Configuration newConfig = getResources().getConfiguration();
507505
if (newConfig.orientation != mCreationOrientation) {
508506
mCallback.recreateMe(newConfig);
509-
} else if (newConfig.hardKeyboardHidden != mKeyboardHidden) {
510-
mKeyboardHidden = newConfig.hardKeyboardHidden;
511-
final boolean isKeyboardOpen = mKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
512-
if (mUpdateMonitor.isKeyguardBypassEnabled() && isKeyboardOpen) {
513-
mCallback.goToUnlockScreen();
514-
}
515507
}
516508
}
517509

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

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
353353
boolean mDeskDockEnablesAccelerometer;
354354
int mLidKeyboardAccessibility;
355355
int mLidNavigationAccessibility;
356+
boolean mLidControlsSleep;
356357
int mLongPressOnPowerBehavior = -1;
357358
boolean mScreenOnEarly = false;
358359
boolean mScreenOnFully = false;
@@ -891,6 +892,8 @@ public void init(Context context, IWindowManager windowManager,
891892
com.android.internal.R.integer.config_lidKeyboardAccessibility);
892893
mLidNavigationAccessibility = mContext.getResources().getInteger(
893894
com.android.internal.R.integer.config_lidNavigationAccessibility);
895+
mLidControlsSleep = mContext.getResources().getBoolean(
896+
com.android.internal.R.bool.config_lidControlsSleep);
894897
// register for dock events
895898
IntentFilter filter = new IntentFilter();
896899
filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
@@ -1268,10 +1271,15 @@ private int determineHiddenState(int mode, int hiddenValue, int visibleValue) {
12681271
return visibleValue;
12691272
}
12701273

1274+
private boolean isKeyboardVisible() {
1275+
return determineHiddenState(mLidKeyboardAccessibility, 0, 1) == 1
1276+
|| determineHiddenState(mLidNavigationAccessibility, 0, 1) == 1;
1277+
}
1278+
12711279
/** {@inheritDoc} */
12721280
public void adjustConfigurationLw(Configuration config) {
12731281
readLidState();
1274-
updateKeyboardVisibility();
1282+
applyLidSwitchState();
12751283

12761284
if (config.keyboard == Configuration.KEYBOARD_NOKEYS) {
12771285
config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
@@ -2809,33 +2817,26 @@ public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
28092817
if (mHeadless) return;
28102818

28112819
// lid changed state
2812-
mLidState = lidOpen ? LID_OPEN : LID_CLOSED;
2813-
updateKeyboardVisibility();
2820+
final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
2821+
if (newLidState == mLidState) {
2822+
return;
2823+
}
28142824

2815-
boolean awakeNow = mKeyguardMediator.doLidChangeTq(lidOpen);
2825+
mLidState = newLidState;
2826+
applyLidSwitchState();
28162827
updateRotation(true);
2817-
if (awakeNow) {
2818-
// If the lid is opening and we don't have to keep the
2819-
// keyguard up, then we can turn on the screen
2820-
// immediately.
2821-
mKeyguardMediator.pokeWakelock();
2822-
} else if (keyguardIsShowingTq()) {
2823-
if (lidOpen) {
2824-
// If we are opening the lid and not hiding the
2825-
// keyguard, then we need to have it turn on the
2826-
// screen once it is shown.
2828+
2829+
if (lidOpen) {
2830+
if (keyguardIsShowingTq()) {
28272831
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(
28282832
KeyEvent.KEYCODE_POWER, mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
2829-
}
2830-
} else {
2831-
// Light up the keyboard if we are sliding up.
2832-
if (lidOpen) {
2833-
mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2834-
LocalPowerManager.BUTTON_EVENT);
28352833
} else {
28362834
mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2837-
LocalPowerManager.OTHER_EVENT);
2835+
LocalPowerManager.BUTTON_EVENT);
28382836
}
2837+
} else if (!mLidControlsSleep) {
2838+
mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2839+
LocalPowerManager.OTHER_EVENT);
28392840
}
28402841
}
28412842

@@ -3884,13 +3885,15 @@ private void updateLockScreenTimeout() {
38843885
/** {@inheritDoc} */
38853886
public void enableScreenAfterBoot() {
38863887
readLidState();
3887-
updateKeyboardVisibility();
3888-
3888+
applyLidSwitchState();
38893889
updateRotation(true);
38903890
}
38913891

3892-
private void updateKeyboardVisibility() {
3893-
mPowerManager.setKeyboardVisibility(mLidState == LID_OPEN);
3892+
private void applyLidSwitchState() {
3893+
mPowerManager.setKeyboardVisibility(isKeyboardVisible());
3894+
if (mLidState == LID_CLOSED && mLidControlsSleep) {
3895+
mPowerManager.goToSleep(SystemClock.uptimeMillis());
3896+
}
38943897
}
38953898

38963899
void updateRotation(boolean alwaysSendConfiguration) {
@@ -4176,6 +4179,7 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args
41764179
pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
41774180
pw.print(mLidKeyboardAccessibility);
41784181
pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
4182+
pw.print(" mLidControlsSleep="); pw.print(mLidControlsSleep);
41794183
pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
41804184
pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
41814185
pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,6 @@ void updateConfiguration() {
304304
mCallback.recreateMe(newConfig);
305305
} else if (newConfig.hardKeyboardHidden != mKeyboardHidden) {
306306
mKeyboardHidden = newConfig.hardKeyboardHidden;
307-
final boolean isKeyboardOpen =
308-
(mKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO);
309-
if (mUpdateMonitor.isKeyguardBypassEnabled() && isKeyboardOpen) {
310-
mCallback.goToUnlockScreen();
311-
}
312307
}
313308

314309
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ void updateConfiguration() {
282282
mCallback.recreateMe(newConfig);
283283
} else if (newConfig.hardKeyboardHidden != mKeyboardHidden) {
284284
mKeyboardHidden = newConfig.hardKeyboardHidden;
285-
final boolean isKeyboardOpen = mKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
286-
if (mUpdateMonitor.isKeyguardBypassEnabled() && isKeyboardOpen) {
287-
mCallback.goToUnlockScreen();
288-
}
289285
}
290286
}
291287

services/java/com/android/server/PowerManagerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,8 @@ private int getAutoBrightnessValue(int sensorValue, int[] values) {
25212521
return val;
25222522
} catch (Exception e) {
25232523
// guard against null pointer or index out of bounds errors
2524-
Slog.e(TAG, "getAutoBrightnessValue", e);
2524+
Slog.e(TAG, "Values array must be non-empty and must be the same length "
2525+
+ "as the auto-brightness levels array. Check config.xml.", e);
25252526
return 255;
25262527
}
25272528
}

0 commit comments

Comments
 (0)