码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-08-15 13:33:21      阅读:2731      评论:0      收藏:0      [点我收藏+]

标签:android   autosleep   suspend   wake   display   

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   autosleep   suspend   wake   display   

原文地址:http://blog.csdn.net/wlwl0071986/article/details/47680893

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!