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

Commit 2256fcf0 authored by Kun Liang's avatar Kun Liang Committed by Linux Build Service Account
Browse files

QuickBoot: enable QuickBoot power on

Support long press power key to power on when in QuickBoot mode.

Change-Id: I92a70e6d58f7b6c49e19ec446766f95d4c873846
parent 7c5c2ac6
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
@@ -148,6 +148,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
    static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;

    // QuickBoot time settings
    static final int DEFAULT_LONG_PRESS_POWERON_TIME = 500;
    static final int QUICKBOOT_LAUNCH_TIMEOUT = 2000;

    static final int SHORT_PRESS_POWER_NOTHING = 0;
    static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
    static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
@@ -233,6 +237,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
     * where the window manager is calling in with its own lock held.)
     */
    private final Object mLock = new Object();
    private final Object mQuickBootLock = new Object();

    Context mContext;
    IWindowManager mWindowManager;
@@ -360,6 +365,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    int mPointerLocationMode = 0; // guarded by mLock

    int mLongPressPoweronTime = DEFAULT_LONG_PRESS_POWERON_TIME;
    // The last window we were told about in focusChanged.
    WindowState mFocusedWindow;
    IApplicationToken mFocusedApp;
@@ -522,6 +528,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    SettingsObserver mSettingsObserver;
    ShortcutManager mShortcutManager;
    PowerManager.WakeLock mBroadcastWakeLock;
    PowerManager.WakeLock mQuickBootWakeLock;
    boolean mHavePendingMediaKeyRepeatWithWakeLock;

    private int mCurrentUserId;
@@ -999,6 +1006,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                "PhoneWindowManager.mBroadcastWakeLock");
        mQuickBootWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                "PhoneWindowManager.mQuickBootWakeLock");
        mLongPressPoweronTime = SystemProperties.getInt("ro.quickboot.press_duration",
                DEFAULT_LONG_PRESS_POWERON_TIME);
        mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
        mSupportAutoRotation = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_supportAutoRotation);
@@ -4213,6 +4224,58 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private final Runnable mQuickBootPowerLongPress = new Runnable() {

        public void run() {

            Intent intent = new Intent("org.codeaurora.action.QUICKBOOT");
            intent.putExtra("mode", 1);
            try {
                mContext.startActivityAsUser(intent,UserHandle.CURRENT);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
                releaseQuickBootWakeLock();
                return;
            }

            BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

                public void onReceive(Context context, Intent intent) {

                    synchronized (mQuickBootLock) {
                        mQuickBootLock.notifyAll();
                    }
                }
            };

            IntentFilter filter = new IntentFilter("org.codeaurora.quickboot.poweron_start");
            mContext.registerReceiver(broadcastReceiver,filter,
                    "android.permission.DEVICE_POWER",null);

            synchronized (mQuickBootLock) {
                try {
                    mQuickBootLock.wait(QUICKBOOT_LAUNCH_TIMEOUT);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            releaseQuickBootWakeLock();
        }
    };

    private void acquireQuickBootWakeLock() {
        if (!mQuickBootWakeLock.isHeld())  {
            mQuickBootWakeLock.acquire();
        }
    }

    private void releaseQuickBootWakeLock() {
        if (mQuickBootWakeLock.isHeld()) {
            mQuickBootWakeLock.release();
        }
    }

    /** {@inheritDoc} */
    @Override
    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
@@ -4226,6 +4289,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final boolean canceled = event.isCanceled();
        final int keyCode = event.getKeyCode();

        if (SystemProperties.getInt("sys.quickboot.enable", 0) == 1) {

            if (keyCode == KeyEvent.KEYCODE_POWER && !interactive) {
                if(down){
                    acquireQuickBootWakeLock();
                    mHandler.postDelayed(mQuickBootPowerLongPress, mLongPressPoweronTime);
                } else {
                    releaseQuickBootWakeLock();
                    mHandler.removeCallbacks(mQuickBootPowerLongPress);
                }
            }
            // ignore this event
            return 0;
        }

        final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;

        // If screen is off then we treat the case where the keyguard is open but hidden