PowerManagerService 关于WackLock 休眠过程

一般我们手机在放置一段时间后,会进行自动灭屏,接下来我们分析下自动灭屏的流程


        frameworks\base\services\core\java\com\android\server\power\PowerManagerService.java

        @Override // Binder call
        public void goToSleep(long eventTime, int reason, int flags) {
            if (eventTime > SystemClock.uptimeMillis()) {
                throw new IllegalArgumentException("event time must not be in the future");
            }

            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.DEVICE_POWER, null);

            final int uid = Binder.getCallingUid();
            final long ident = Binder.clearCallingIdentity();
            try {
                goToSleepInternal(eventTime, reason, flags, uid);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }


     
            //主要作用是强制系统进入休眠模式,一般常用的是一段时间无人操作后,系统将调用goToSleepInternal进入休眠状态
    private void goToSleepInternal(long eventTime, int reason, int flags, int uid) {
        synchronized (mLock) {
            if (mProximityPositive && reason == PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON) {
                Slog.d(TAG, "Proximity positive sleep and force wakeup by power button");
                mDirty |= DIRTY_WAKEFULNESS;
                mWakefulness = WAKEFULNESS_ASLEEP;
                updatePowerStateLocked();
                return;
            }

            if (goToSleepNoUpdateLocked(eventTime, reason, flags, uid)) {//进入休眠状态
                updatePowerStateLocked();
            }
        }
    }

至于updatePowerStateLocked();流程可以参考这个流程

PowerManagerService开机启动关于WackLock处理的相关流程

你可能感兴趣的:(PowerManagerService 关于WackLock 休眠过程)