Skip to content

Commit c5c33c3

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Add support for using the lid switch to turn off the screen." into jb-dev
2 parents 6da9cf7 + c458ce9 commit c5c33c3

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;
@@ -897,6 +898,8 @@ public void init(Context context, IWindowManager windowManager,
897898
com.android.internal.R.integer.config_lidKeyboardAccessibility);
898899
mLidNavigationAccessibility = mContext.getResources().getInteger(
899900
com.android.internal.R.integer.config_lidNavigationAccessibility);
901+
mLidControlsSleep = mContext.getResources().getBoolean(
902+
com.android.internal.R.bool.config_lidControlsSleep);
900903
// register for dock events
901904
IntentFilter filter = new IntentFilter();
902905
filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
@@ -1274,10 +1277,15 @@ private int determineHiddenState(int mode, int hiddenValue, int visibleValue) {
12741277
return visibleValue;
12751278
}
12761279

1280+
private boolean isKeyboardVisible() {
1281+
return determineHiddenState(mLidKeyboardAccessibility, 0, 1) == 1
1282+
|| determineHiddenState(mLidNavigationAccessibility, 0, 1) == 1;
1283+
}
1284+
12771285
/** {@inheritDoc} */
12781286
public void adjustConfigurationLw(Configuration config) {
12791287
readLidState();
1280-
updateKeyboardVisibility();
1288+
applyLidSwitchState();
12811289

12821290
if (config.keyboard == Configuration.KEYBOARD_NOKEYS) {
12831291
config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
@@ -2852,33 +2860,26 @@ public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
28522860
if (mHeadless) return;
28532861

28542862
// lid changed state
2855-
mLidState = lidOpen ? LID_OPEN : LID_CLOSED;
2856-
updateKeyboardVisibility();
2863+
final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
2864+
if (newLidState == mLidState) {
2865+
return;
2866+
}
28572867

2858-
boolean awakeNow = mKeyguardMediator.doLidChangeTq(lidOpen);
2868+
mLidState = newLidState;
2869+
applyLidSwitchState();
28592870
updateRotation(true);
2860-
if (awakeNow) {
2861-
// If the lid is opening and we don't have to keep the
2862-
// keyguard up, then we can turn on the screen
2863-
// immediately.
2864-
mKeyguardMediator.pokeWakelock();
2865-
} else if (keyguardIsShowingTq()) {
2866-
if (lidOpen) {
2867-
// If we are opening the lid and not hiding the
2868-
// keyguard, then we need to have it turn on the
2869-
// screen once it is shown.
2871+
2872+
if (lidOpen) {
2873+
if (keyguardIsShowingTq()) {
28702874
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(
28712875
KeyEvent.KEYCODE_POWER, mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
2872-
}
2873-
} else {
2874-
// Light up the keyboard if we are sliding up.
2875-
if (lidOpen) {
2876-
mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2877-
LocalPowerManager.BUTTON_EVENT);
28782876
} else {
28792877
mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2880-
LocalPowerManager.OTHER_EVENT);
2878+
LocalPowerManager.BUTTON_EVENT);
28812879
}
2880+
} else if (!mLidControlsSleep) {
2881+
mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2882+
LocalPowerManager.OTHER_EVENT);
28822883
}
28832884
}
28842885

@@ -3927,13 +3928,15 @@ private void updateLockScreenTimeout() {
39273928
/** {@inheritDoc} */
39283929
public void enableScreenAfterBoot() {
39293930
readLidState();
3930-
updateKeyboardVisibility();
3931-
3931+
applyLidSwitchState();
39323932
updateRotation(true);
39333933
}
39343934

3935-
private void updateKeyboardVisibility() {
3936-
mPowerManager.setKeyboardVisibility(mLidState == LID_OPEN);
3935+
private void applyLidSwitchState() {
3936+
mPowerManager.setKeyboardVisibility(isKeyboardVisible());
3937+
if (mLidState == LID_CLOSED && mLidControlsSleep) {
3938+
mPowerManager.goToSleep(SystemClock.uptimeMillis());
3939+
}
39373940
}
39383941

39393942
void updateRotation(boolean alwaysSendConfiguration) {
@@ -4219,6 +4222,7 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args
42194222
pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
42204223
pw.print(mLidKeyboardAccessibility);
42214224
pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
4225+
pw.print(" mLidControlsSleep="); pw.print(mLidControlsSleep);
42224226
pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
42234227
pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
42244228
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)