Android 添加永不休眠

1.修改framework/base/packages/SettingsProvider/res/values/defaults.xml中
def_screen_off_timeout默认值为0

2.修改framework/base/services/core/java/com/android/server/policy/PhoneWindowManager.java中
搜索关键字never screenOff

private void updateLockScreenTimeout() {
    synchronized (mScreenLockTimeout) {
        boolean enable = (mAllowLockscreenWhenOn && mAwake &&
                mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId));
        if (mLockScreenTimerActive != enable) {
            if (enable) {
                if (localLOGV) Log.v(TAG, "setting lockscreen timer");
                mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
                //*/  add never screenOff
                if (mLockScreenTimeout != 0) {
                    mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
                }
                //*/
            } else {
                if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
                mHandler.removeCallbacks(mScreenLockTimeout);
            }
            mLockScreenTimerActive = enable;
        }
    }
}

3…修改framework/base/service/core/java/com/android/server/power/PowerManagerService.java中
搜索关键字never screenOff

private void updateUserActivitySummaryLocked(long now, int dirty) {
    // Update the status of the user activity timeout timer.
    if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY
            | DIRTY_WAKEFULNESS | DIRTY_SETTINGS)) != 0) {
        mHandler.removeMessages(MSG_USER_ACTIVITY_TIMEOUT);

        long nextTimeout = 0;
        if (mWakefulness == WAKEFULNESS_AWAKE
                || mWakefulness == WAKEFULNESS_DREAMING
                || mWakefulness == WAKEFULNESS_DOZING) {
            final int sleepTimeout = getSleepTimeoutLocked();
            final int screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout);
            final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
            final boolean userInactiveOverride = mUserInactiveOverrideFromWindowManager;
            final int screenButtonLightDuration = getButtonLightDurationLocked(screenOffTimeout);

            mUserActivitySummary = 0;
            if (mLastUserActivityTime >= mLastWakeTime) {
                if ( (mLastUserActivityButtonTime >= mLastWakeTime) && (now < mLastUserActivityButtonTime + screenButtonLightDuration) ) {
                    mUserActivitySummary |= USER_ACTIVITY_BUTTON_BRIGHT;
                    mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;
                    nextTimeout = mLastUserActivityButtonTime + screenButtonLightDuration;
                } else if (now < mLastUserActivityTime + screenOffTimeout - screenDimDuration) {
                    nextTimeout = mLastUserActivityTime + screenOffTimeout - screenDimDuration;
                    mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;
                } else {
                    nextTimeout = mLastUserActivityTime + screenOffTimeout;
                    if (now < nextTimeout) {
                        mUserActivitySummary |= USER_ACTIVITY_SCREEN_DIM;
                    }
                }
            }
            if (mUserActivitySummary == 0
                    && mLastUserActivityTimeNoChangeLights >= mLastWakeTime) {
                nextTimeout = mLastUserActivityTimeNoChangeLights + screenOffTimeout;
                if (now < nextTimeout) {
                    if (mDisplayPowerRequest.policy == DisplayPowerRequest.POLICY_BRIGHT) {
                        mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT;
                    } else if (mDisplayPowerRequest.policy == DisplayPowerRequest.POLICY_DIM) {
                        mUserActivitySummary = USER_ACTIVITY_SCREEN_DIM;
                    }
                }
            }

            if (mUserActivitySummary == 0) {
                if (sleepTimeout >= 0) {
                    final long anyUserActivity = Math.max(mLastUserActivityTime,
                            mLastUserActivityTimeNoChangeLights);
                    if (anyUserActivity >= mLastWakeTime) {
                        nextTimeout = anyUserActivity + sleepTimeout;
                        if (now < nextTimeout) {
                            mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM;
                        }
                    }
                } else {
                    mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM;
                    nextTimeout = -1;
                }
            }

            if (mUserActivitySummary != USER_ACTIVITY_SCREEN_DREAM && userInactiveOverride) {
                if ((mUserActivitySummary &
                        (USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM)) != 0) {
                    // Device is being kept awake by recent user activity
                    if (nextTimeout >= now && mOverriddenTimeout == -1) {
                        // Save when the next timeout would have occurred
                        mOverriddenTimeout = nextTimeout;
                    }
                }
                mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM;
                nextTimeout = -1;
            }

            //*/  add never screenOff
            if (mScreenOffTimeoutSetting != 0) {
                if (mUserActivitySummary != 0 && nextTimeout >= 0) {
                    Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
                    msg.setAsynchronous(true);
                    mHandler.sendMessageAtTime(msg, nextTimeout);
                }
            } else {
                mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;

            }
            //*/
        } else {
            mUserActivitySummary = 0;
        }

        if (DEBUG_SPEW) {
            Slog.d(TAG, "updateUserActivitySummaryLocked: mWakefulness="
                    + PowerManagerInternal.wakefulnessToString(mWakefulness)
                    + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
                    + ", nextTimeout=" + TimeUtils.formatUptime(nextTimeout));
        }
    }
}

4.修改packages/apps/Settings/res/values/arrays.xml
在screen_timeout_entries中添加一个item never
在screen_timeout_values中添加一个item 0
注意在添加这两个item时,要添加在第一项,避免出现无论选择多少时间,都显示永不休眠的bug

你可能感兴趣的:(Android)