Android 8.1 修改锁屏显示时间

简介: Android 8.1 修改锁屏显示时间

平台


RK3399 + Android 8.1


需求


加长锁屏显示时间, 延长用户解锁时间


补丁


|-- frameworks/base/core/res/res/values/config.xml


diff --git a/frameworks/base/core/res/res/values/config.xml b/frameworks/base/core/res/res/values/config.xml
index b81b609..c401275 100644
--- a/frameworks/base/core/res/res/values/config.xml
+++ b/frameworks/base/core/res/res/values/config.xml
@@ -1988,7 +1988,7 @@
          This value must be greater than zero, otherwise the device will immediately
          fall asleep again as soon as it is awoken.
     -->
-    <integer name="config_minimumScreenOffTimeout">10000</integer>
+    <integer name="config_minimumScreenOffTimeout">15000</integer>
     <!-- User activity timeout: Maximum screen dim duration in milliseconds.


由原来的10 秒延长到15秒


跟踪


|-- frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java


private void readConfigurationLocked() {
        ...
        mMinimumScreenOffTimeoutConfig = resources.getInteger(
                com.android.internal.R.integer.config_minimumScreenOffTimeout);
        ...
    }
    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);
                ...
                mUserActivitySummary = 0;
                if (mLastUserActivityTime >= mLastWakeTime) {
//计算超时进入休眠时间. 
//mLastUserActivityTime最后一次操作
                    nextTimeout = mLastUserActivityTime
                            + screenOffTimeout - screenDimDuration;
                    if (now < nextTimeout) {
                        mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT;
                    } else {
                        nextTimeout = mLastUserActivityTime + screenOffTimeout;
                        if (now < nextTimeout) {
                            mUserActivitySummary = USER_ACTIVITY_SCREEN_DIM;
                        }
                    }
                }
                ...
                if (mUserActivitySummary != 0 && nextTimeout >= 0) {
                    Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
                    msg.setAsynchronous(true);
                    mHandler.sendMessageAtTime(msg, nextTimeout);
                }
            }
    ...
        }
    }
/*
dumpsys power | grep mScreenOffTimeoutSetting
  mScreenOffTimeoutSetting=2147483647
*/
    private int getScreenOffTimeoutLocked(int sleepTimeout) {//-1
        int timeout = mScreenOffTimeoutSetting;//2147483647
        if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
            timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
        }
        if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {
            timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);
        }
        if (sleepTimeout >= 0) {
            timeout = Math.min(timeout, sleepTimeout);
        }
        return Math.max(timeout, mMinimumScreenOffTimeoutConfig);
    }
  //用户长时间不操作后:
    private void handleUserActivityTimeout() { // runs on handler thread
        synchronized (mLock) {
            if (DEBUG_SPEW) {
                Slog.d(TAG, "handleUserActivityTimeout");
            }
            mDirty |= DIRTY_USER_ACTIVITY;
            updatePowerStateLocked();
        }
    }
    /**
     * Updates the global power state based on dirty bits recorded in mDirty.
     *
     * This is the main function that performs power state transitions.
     * We centralize them here so that we can recompute the power state completely
     * each time something important changes, and ensure that we do it the same
     * way each time.  The point is to gather all of the transition logic here.
     */
    private void updatePowerStateLocked() {
    ...
            // Phase 2: Update display power state.
            boolean displayBecameReady = updateDisplayPowerStateLocked(dirtyPhase2);
            // Phase 3: Update dream state (depends on display ready signal).
            updateDreamLocked(dirtyPhase2, displayBecameReady);
            // Phase 4: Send notifications, if needed.
            finishWakefulnessChangeIfNeededLocked();
    ...
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_POWER);
        }
    }
  /**
     * Determines whether to post a message to the sandman to update the dream state.
     */
    private void updateDreamLocked(int dirty, boolean displayBecameReady) {
        if ((dirty & (DIRTY_WAKEFULNESS
                | DIRTY_USER_ACTIVITY
                | DIRTY_WAKE_LOCKS
                | DIRTY_BOOT_COMPLETED
                | DIRTY_SETTINGS
                | DIRTY_IS_POWERED
                | DIRTY_STAY_ON
                | DIRTY_PROXIMITY_POSITIVE
                | DIRTY_BATTERY_STATE)) != 0 || displayBecameReady) {
            if (mDisplayReady) {
                scheduleSandmanLocked();
            }
        }
    }
    private void scheduleSandmanLocked() {
        if (!mSandmanScheduled) {
            mSandmanScheduled = true;
            Message msg = mHandler.obtainMessage(MSG_SANDMAN);
            msg.setAsynchronous(true);
            mHandler.sendMessage(msg);
        }
    }
  private void handleSandman() { // runs on handler thread
        // Handle preconditions.
  ...
                // Doze has ended or will be stopped.  Update the power state.
                reallyGoToSleepNoUpdateLocked(SystemClock.uptimeMillis(), Process.SYSTEM_UID);
                updatePowerStateLocked();
            }
        }
        // Stop dream.
        if (isDreaming) {
            mDreamManager.stopDream(false /*immediate*/);
        }
    }
    // Done dozing, drop everything and go to sleep.
    private boolean reallyGoToSleepNoUpdateLocked(long eventTime, int uid) {
        if (DEBUG_SPEW) {
            Slog.d(TAG, "reallyGoToSleepNoUpdateLocked: eventTime=" + eventTime
                    + ", uid=" + uid);
        }
        if (eventTime < mLastWakeTime || mWakefulness == WAKEFULNESS_ASLEEP
                || !mBootCompleted || !mSystemReady) {
            return false;
        }
        Trace.traceBegin(Trace.TRACE_TAG_POWER, "reallyGoToSleep");
        try {
            Slog.i(TAG, "Sleeping (uid " + uid +")...");
            setWakefulnessLocked(WAKEFULNESS_ASLEEP, PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_POWER);
        }
        return true;
    }
相关文章
|
数据安全/隐私保护 Android开发
Android10.0 锁屏分析——KeyguardPINView PIN锁分析
Android10.0 锁屏分析——KeyguardPINView PIN锁分析
|
存储 数据库 数据安全/隐私保护
Android11.0(R) 预留清空锁屏密码接口
Android11.0(R) 预留清空锁屏密码接口
328 0
|
Android开发
Android11.0(R) 手机锁屏炫酷充电动画————自定义View方案
Android11.0(R) 手机锁屏炫酷充电动画————自定义View方案
411 0
|
Java Android开发 开发者
Android9.0 无锁屏下连续锁屏-解屏2次,画面点击无响应 bug 解决办法
Android9.0 无锁屏下连续锁屏-解屏2次,画面点击无响应 bug 解决办法
148 0
|
Android开发
Android 10.0 锁屏壁纸 LockscreenWallpaper(三)
Android 10.0 锁屏壁纸 LockscreenWallpaper(三)
Android 10.0 锁屏壁纸 LockscreenWallpaper(三)
|
安全 算法 Java
Android10.0 锁屏分析——KeyguardPatternView图案锁分析
Android10.0 锁屏分析——KeyguardPatternView图案锁分析
Android10.0 锁屏分析——KeyguardPatternView图案锁分析
|
Java Android开发
Android 8.1 系统锁屏显示流程整理
Android 8.1 系统锁屏显示流程整理
441 0
|
Android开发
android 4.2 修改默锁屏为无
android 4.2 修改默锁屏为无
176 0
android4.2 不显示锁屏同时POWER不进休眠
android4.2 不显示锁屏同时POWER不进休眠
98 0