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

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

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

        -1

 

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

   

   

        15 seconds

        30 seconds

        1 minute

        2 minutes

        10 minutes

        30 minutes

        never

   


   

  

       

        15000

       

        30000

       

        60000

       

        120000

       

        600000

       

        1800000

         -1

   

 

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

   

    "15 秒"

    "30 秒"

    "1分钟"

    "2 分钟"

    "5 分钟"

    "10 分钟"

    "30 分钟"

    "永不休眠"

   

 

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

                            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

                    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);

 

 

你可能感兴趣的:(AndroidUI界面,android,autosleep,suspend,wake,display)