Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a538ee7 authored by Jeff Brown's avatar Jeff Brown
Browse files

Add factory test feature to shut off on long press power.

Bug: 6847329
Change-Id: I2f4f975c3af2d13ccc06812a5a42e79032700862
parent 5f47ba4d
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

/**
 * Provides support for in-place factory test functions.
 *
 * This class provides a few properties that alter the normal operation of the system
 * during factory testing.
 *
 * {@hide}
 */
public final class FactoryTest {
    /**
     * When true, long-press on power should immediately cause the device to
     * shut down, without prompting the user.
     */
    public static boolean isLongPressOnPowerOffEnabled() {
        return SystemProperties.getInt("factory.long_press_power_off", 0) != 0;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -390,8 +390,8 @@ public interface WindowManagerPolicy {
         */
        public void switchKeyboardLayout(int deviceId, int direction);

        public void shutdown();
        public void rebootSafeMode();
        public void shutdown(boolean confirm);
        public void rebootSafeMode(boolean confirm);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -209,11 +209,11 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

                public void onPress() {
                    // shutdown by making sure radio and power are handled accordingly.
                    mWindowManagerFuncs.shutdown();
                    mWindowManagerFuncs.shutdown(true);
                }

                public boolean onLongPress() {
                    mWindowManagerFuncs.rebootSafeMode();
                    mWindowManagerFuncs.rebootSafeMode(true);
                    return true;
                }

+11 −3
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.media.AudioManager;
import android.media.IAudioService;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.FactoryTest;
import android.os.Handler;
import android.os.IBinder;
import android.os.IRemoteCallback;
@@ -172,6 +173,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    static final int LONG_PRESS_POWER_NOTHING = 0;
    static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
    static final int LONG_PRESS_POWER_SHUT_OFF = 2;
    static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;

    // These need to match the documentation/constant in
    // core/res/res/values/config.xml
@@ -716,9 +718,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        public void run() {
            // The context isn't read
            if (mLongPressOnPowerBehavior < 0) {
                if (FactoryTest.isLongPressOnPowerOffEnabled()) {
                    mLongPressOnPowerBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
                } else {
                    mLongPressOnPowerBehavior = mContext.getResources().getInteger(
                            com.android.internal.R.integer.config_longPressOnPowerBehavior);
                }
            }
            switch (mLongPressOnPowerBehavior) {
            case LONG_PRESS_POWER_NOTHING:
                break;
@@ -729,10 +735,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                showGlobalActionsDialog();
                break;
            case LONG_PRESS_POWER_SHUT_OFF:
            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
                mPowerKeyHandled = true;
                performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
                mWindowManagerFuncs.shutdown();
                mWindowManagerFuncs.shutdown(
                        mLongPressOnPowerBehavior == LONG_PRESS_POWER_SHUT_OFF);
                break;
            }
        }
+4 −4
Original line number Diff line number Diff line
@@ -5257,14 +5257,14 @@ public class WindowManagerService extends IWindowManager.Stub

    // Called by window manager policy.  Not exposed externally.
    @Override
    public void shutdown() {
        ShutdownThread.shutdown(mContext, true);
    public void shutdown(boolean confirm) {
        ShutdownThread.shutdown(mContext, confirm);
    }

    // Called by window manager policy.  Not exposed externally.
    @Override
    public void rebootSafeMode() {
        ShutdownThread.rebootSafeMode(mContext, true);
    public void rebootSafeMode(boolean confirm) {
        ShutdownThread.rebootSafeMode(mContext, confirm);
    }

    public void setInputFilter(IInputFilter filter) {