Skip to content

Commit 4b72463

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Add factory test feature to shut off on long press power." into jb-mr1-dev
2 parents c2cb8d2 + 9a538ee commit 4b72463

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.os;
18+
19+
/**
20+
* Provides support for in-place factory test functions.
21+
*
22+
* This class provides a few properties that alter the normal operation of the system
23+
* during factory testing.
24+
*
25+
* {@hide}
26+
*/
27+
public final class FactoryTest {
28+
/**
29+
* When true, long-press on power should immediately cause the device to
30+
* shut down, without prompting the user.
31+
*/
32+
public static boolean isLongPressOnPowerOffEnabled() {
33+
return SystemProperties.getInt("factory.long_press_power_off", 0) != 0;
34+
}
35+
}

core/java/android/view/WindowManagerPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ public FakeWindow addFakeWindow(Looper looper,
390390
*/
391391
public void switchKeyboardLayout(int deviceId, int direction);
392392

393-
public void shutdown();
394-
public void rebootSafeMode();
393+
public void shutdown(boolean confirm);
394+
public void rebootSafeMode(boolean confirm);
395395
}
396396

397397
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ public boolean showBeforeProvisioning() {
209209

210210
public void onPress() {
211211
// shutdown by making sure radio and power are handled accordingly.
212-
mWindowManagerFuncs.shutdown();
212+
mWindowManagerFuncs.shutdown(true);
213213
}
214214

215215
public boolean onLongPress() {
216-
mWindowManagerFuncs.rebootSafeMode();
216+
mWindowManagerFuncs.rebootSafeMode(true);
217217
return true;
218218
}
219219

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import android.media.IAudioService;
4343
import android.os.BatteryManager;
4444
import android.os.Bundle;
45+
import android.os.FactoryTest;
4546
import android.os.Handler;
4647
import android.os.IBinder;
4748
import android.os.IRemoteCallback;
@@ -172,6 +173,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
172173
static final int LONG_PRESS_POWER_NOTHING = 0;
173174
static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
174175
static final int LONG_PRESS_POWER_SHUT_OFF = 2;
176+
static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
175177

176178
// These need to match the documentation/constant in
177179
// core/res/res/values/config.xml
@@ -716,8 +718,12 @@ private void cancelPendingScreenshotChordAction() {
716718
public void run() {
717719
// The context isn't read
718720
if (mLongPressOnPowerBehavior < 0) {
719-
mLongPressOnPowerBehavior = mContext.getResources().getInteger(
720-
com.android.internal.R.integer.config_longPressOnPowerBehavior);
721+
if (FactoryTest.isLongPressOnPowerOffEnabled()) {
722+
mLongPressOnPowerBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
723+
} else {
724+
mLongPressOnPowerBehavior = mContext.getResources().getInteger(
725+
com.android.internal.R.integer.config_longPressOnPowerBehavior);
726+
}
721727
}
722728
switch (mLongPressOnPowerBehavior) {
723729
case LONG_PRESS_POWER_NOTHING:
@@ -729,10 +735,12 @@ public void run() {
729735
showGlobalActionsDialog();
730736
break;
731737
case LONG_PRESS_POWER_SHUT_OFF:
738+
case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
732739
mPowerKeyHandled = true;
733740
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
734741
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
735-
mWindowManagerFuncs.shutdown();
742+
mWindowManagerFuncs.shutdown(
743+
mLongPressOnPowerBehavior == LONG_PRESS_POWER_SHUT_OFF);
736744
break;
737745
}
738746
}

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5257,14 +5257,14 @@ public void switchKeyboardLayout(int deviceId, int direction) {
52575257

52585258
// Called by window manager policy. Not exposed externally.
52595259
@Override
5260-
public void shutdown() {
5261-
ShutdownThread.shutdown(mContext, true);
5260+
public void shutdown(boolean confirm) {
5261+
ShutdownThread.shutdown(mContext, confirm);
52625262
}
52635263

52645264
// Called by window manager policy. Not exposed externally.
52655265
@Override
5266-
public void rebootSafeMode() {
5267-
ShutdownThread.rebootSafeMode(mContext, true);
5266+
public void rebootSafeMode(boolean confirm) {
5267+
ShutdownThread.rebootSafeMode(mContext, confirm);
52685268
}
52695269

52705270
public void setInputFilter(IInputFilter filter) {

0 commit comments

Comments
 (0)