Android设置系统开机自己主动永不休眠

Posted claireyuancy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android设置系统开机自己主动永不休眠相关的知识,希望对你有一定的参考价值。

android4.2系统增永不休眠同一时候隐藏休眠选项

1. android\frameworks\base\packages\SettingsProvider\res\values\defaults.xml中设置def_screen_off_timeout为-1,

        <integername="def_screen_off_timeout">-1</integer>

 

2. android\packages\apps\Settings\res\values\arrays.xml文件添加两项。标红选项。

    <!--Display settings.  The delay ininactivity before the screen is turned off. These are shown ain a list dialog.-->

    <string-arrayname="screen_timeout_entries">

        <item>15 seconds</item>

        <item>30 seconds</item>

        <item>1 minute</item>

        <item>2 minutes</item>

        <item>10 minutes</item>

        <item>30 minutes</item>

        <item>never</item>

    </string-array>


    <!-- Do not translate. -->

   <string-array  name="screen_timeout_values"translatable="false">

        <!-- Do not translate. -->

        <item>15000</item>

        <!-- Do not translate. -->

        <item>30000</item>

        <!-- Do not translate. -->

        <item>60000</item>

        <!-- Do not translate. -->

        <item>120000</item>

        <!-- Do not translate. -->

        <item>600000</item>

        <!-- Do not translate. -->

        <item>1800000</item>

         <item>-1</item>

    </string-array>

 

3. android\packages\apps\Settings\res\values-zh-rCN中添加永不休眠相应的中文

    <string-arrayname="screen_timeout_entries">

    <itemmsgid="3342301044271143016">"15 秒"</item>

    <itemmsgid="8881760709354815449">"30 秒"</item>

    <item msgid="7589406073232279088">"1分钟"</item>

    <itemmsgid="7001195990902244174">"2 分钟"</item>

    <itemmsgid="7489864775127957179">"5 分钟"</item>

    <itemmsgid="2314124409517439288">"10 分钟"</item>

    <itemmsgid="6864027152847611413">"30 分钟"</item>

    <item msgid="9989898989898989898">"永不休眠"</item>

    </string-array>

 

4./services/java/com/android/server/power/PowerManagerService.java

private int getScreenOffTimeoutLocked() {

        int DonotSleeptimeout;

         int timeout =mScreenOffTimeoutSetting;

         if(isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {

             timeout = Math.min(timeout,mMaximumScreenOffTimeoutFromDeviceAdmin);

 

         if(mUserActivityTimeoutOverrideFromWindowManager >= 0) {

             timeout = (int)Math.min(timeout,mUserActivityTimeoutOverrideFromWindowManager);

         }

        DonotSleeptimeout = mScreenOffTimeoutSetting;

       if(DonotSleeptimeout  < 0)

        {

            DonotSleeptimeout= mMaximumScreenOffTimeoutFromDeviceAdmin ;

            returnMath.max(DonotSleeptimeout, mMaximumScreenOffTimeoutFromDeviceAdmin);

        }

         return Math.max(timeout,MINIMUM_SCREEN_OFF_TIMEOUT);

     }

 

privatevoid updateUserActivitySummaryLocked(long now, int dirty) {

        // Update the status of the useractivity timeout timer.

        if ((dirty & (DIRTY_USER_ACTIVITY |DIRTY_WAKEFULNESS | DIRTY_SETTINGS)) != 0) {

           mHandler.removeMessages(MSG_USER_ACTIVITY_TIMEOUT);

 

            long nextTimeout = 0;

            if (mWakefulness !=WAKEFULNESS_ASLEEP) {

                final int screenOffTimeout =getScreenOffTimeoutLocked();

                final int screenDimDuration =getScreenDimDurationLocked(screenOffTimeout);

 

                mUserActivitySummary = 0;

                if (mLastUserActivityTime >=mLastWakeTime) {

                    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

                        &&mLastUserActivityTimeNoChangeLights >= mLastWakeTime) {

                    nextTimeout =mLastUserActivityTimeNoChangeLights + screenOffTimeout;

                    if (now < nextTimeout

                            &&mDisplayPowerRequest.screenState

                                    !=DisplayPowerRequest.SCREEN_STATE_OFF) {

                        mUserActivitySummary =mDisplayPowerRequest.screenState

                                ==DisplayPowerRequest.SCREEN_STATE_BRIGHT ?

                               USER_ACTIVITY_SCREEN_BRIGHT : USER_ACTIVITY_SCREEN_DIM;

                    }

                }

                if (mUserActivitySummary != 0&&mScreenOffTimeoutSetting > 0) {

                    Message msg =mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);

                    msg.setAsynchronous(true);

                    mHandler.sendMessageAtTime(msg,nextTimeout);

                }

            } else {

                mUserActivitySummary = 0;

            }

 

            if (DEBUG_SPEW) {

                Slog.d(TAG,"updateUserActivitySummaryLocked: mWakefulness="

                        +wakefulnessToString(mWakefulness)

                        + ",mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)

                        + ",nextTimeout=" + TimeUtils.formatUptime(nextTimeout));

            }

        }

    }

 

5. /android/packages/apps/Settings/src/com/android/settings/ DisplaySettings.java

privatevoid updateTimeoutPreferenceDescription(long currentTimeout) {

        ListPreference preference =mScreenTimeoutPreference;

        String summary;

        if (currentTimeout < -1) {

            // Unsupported value

            summary = "";

        } else {

            final CharSequence[] entries =preference.getEntries();

            final CharSequence[] values =preference.getEntryValues();

            if (entries == null ||entries.length == 0) {

                summary = "";

            } else {

                int best = 0;

                for (int i = 0; i <values.length; i++) {

                    long timeout =Long.parseLong(values[i].toString());

                    if (currentTimeout >=timeout) {

                        best = i;

                      

                    }

                }

                 

                summary = preference.getContext().getString(R.string.screen_timeout_summary,

                        entries[best]);

              if(currentTimeout < 0)summary =entries[best].toString();

            }

        }

        preference.setSummary(summary);

   

}



onCreate方法中隐藏休眠选项:

 

mScreenTimeoutPreference= (ListPreference) findPreference(KEY_SCREEN_TIMEOUT);

        final long currentTimeout =Settings.System.getLong(resolver, SCREEN_OFF_TIMEOUT,

                FALLBACK_SCREEN_TIMEOUT_VALUE);

        mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));

       mScreenTimeoutPreference.setOnPreferenceChangeListener(this);

       disableUnusableTimeouts(mScreenTimeoutPreference);

       updateTimeoutPreferenceDescription(currentTimeout);

//hide sleep item

getPreferenceScreen().removePreference(mScreenTimeoutPreference);

 

 




以上是关于Android设置系统开机自己主动永不休眠的主要内容,如果未能解决你的问题,请参考以下文章

Android系统-Settings-添加永不休眠选项并默认永不休眠

苹果电脑休眠怎么唤醒

Android系统-Settings-添加用不休眠选项并默认永不休眠

Android进阶技巧之Android休眠机制

Android添加永不休眠选项

linux怎么设置不休眠