首先修改android:entries和 android:entryValues屬性飒筑。默認(rèn)的是screen_timeout_entries和screen_timeout_values回怜,是沒有永不息屏的選項(xiàng)的泽篮,但是array有定義dream_timeout_entries和dream_timeout_values丐膝,這里有永不息屏现喳。
//vendor\mediatek\proprietary\packages\apps\MtkSettings\res\xml\display_settings.xml
<com.android.settings.display.TimeoutListPreference
android:key="screen_timeout"
android:title="@string/screen_timeout"
android:summary="@string/summary_placeholder"
android:entries="@array/screen_timeout_entries"
android:entryValues="@array/screen_timeout_values"
settings:keywords="@string/keywords_screen_timeout" />
修改后如下怔接。
<com.android.settings.display.TimeoutListPreference
android:key="screen_timeout"
android:title="@string/screen_timeout"
android:summary="@string/summary_placeholder"
android:entries="@array/dream_timeout_entries"
android:entryValues="@array/dream_timeout_values"
settings:keywords="@string/keywords_screen_timeout" />
但是這樣只是setting中對(duì)應(yīng)的dialog界面會(huì)增加never這個(gè)選項(xiàng)吟税,如果選擇never的話凹耙,還是會(huì)息屏姿现。never對(duì)應(yīng)的時(shí)間是0.
我嘗試在PowerManagerService增加判斷,這里雖然可以實(shí)現(xiàn)永不息屏肖抱,但是會(huì)導(dǎo)致新的問題备典,鎖屏后無法亮屏。
if(mScreenOffTimeoutSetting == 0){
return mMaximumScreenOffTimeoutFromDeviceAdmin;
}
具體如下(這樣修改在Android11中會(huì)導(dǎo)致新的問題)意述。
//frameworks\base\services\core\java\com\android\server\power\PowerManagerService.java
private long getScreenOffTimeoutLocked(long sleepTimeout, long attentiveTimeout) {
long timeout = mScreenOffTimeoutSetting;
if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
}
if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {
timeout = Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);
}
if (sleepTimeout >= 0) {
timeout = Math.min(timeout, sleepTimeout);
}
if (attentiveTimeout >= 0) {
timeout = Math.min(timeout, attentiveTimeout);
}
if(mScreenOffTimeoutSetting == 0){
return mMaximumScreenOffTimeoutFromDeviceAdmin;
}
return Math.max(timeout, mMinimumScreenOffTimeoutConfig);
}
最終修改如下提佣。
1.給mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
加個(gè)判斷。
//frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
private void updateLockScreenTimeout() {
synchronized (mScreenLockTimeout) {
final boolean enable = !mAllowLockscreenWhenOnDisplays.isEmpty()
&& mDefaultDisplayPolicy.isAwake()
&& 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
//mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
if (mLockScreenTimeout != 0) {
mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
}
} else {
if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
mHandler.removeCallbacks(mScreenLockTimeout);
}
mLockScreenTimerActive = enable;
}
}
}
2.修改updateUserActivitySummaryLocked中部分邏輯荤崇,增加判斷條件拌屏。
最終如下。
//frameworks\base\services\core\java\com\android\server\power\PowerManagerService.java
private void updateUserActivitySummaryLocked(long now, int dirty) {
// Update the status of the user activity timeout timer.
................
/* if ((mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0
&& (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) == 0) {
nextTimeout = mAttentionDetector.updateUserActivity(nextTimeout,
screenDimDuration);
}
if (nextProfileTimeout > 0) {
nextTimeout = Math.min(nextTimeout, nextProfileTimeout);
}
if (mUserActivitySummary != 0 && nextTimeout >= 0) {
scheduleUserInactivityTimeout(nextTimeout);
}*/
if (mScreenOffTimeoutSetting != 0) {
if ((mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0
&& (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) == 0) {
nextTimeout = mAttentionDetector.updateUserActivity(nextTimeout,screenDimDuration);
}
if (nextProfileTimeout > 0) {
nextTimeout = Math.min(nextTimeout, nextProfileTimeout);
}
if (mUserActivitySummary != 0 && nextTimeout >= 0) {
scheduleUserInactivityTimeout(nextTimeout);
}
} else {
mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;
}
} else {
mUserActivitySummary = 0;
}
if (DEBUG_SPEW) {
Slog.d(TAG, "updateUserActivitySummaryLocked: mWakefulness="
+ PowerManagerInternal.wakefulnessToString(getWakefulnessLocked())
+ ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
+ ", nextTimeout=" + TimeUtils.formatUptime(nextTimeout));
}
}
}
參考鏈接:
展訊平臺(tái)記錄下工作中一些修改
Android7.1 Settings加入永不休眠選項(xiàng)
安卓7.0顯示設(shè)置界面休眠菜單添加“永不滅屏”選項(xiàng)
android設(shè)置永不滅屏