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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值