2014年9月10日 星期三

Android 4.4 在選單增加 Display Never Timeout

Android 4.4.x 在選單增加 Display Never Timeout

本文源自: http://ansonlai.iteye.com/blog/1899764

剛抓下來的 android 4.4.x 裡面的 設定--> 顯示 --> 休眠
只有 30 sec, 1 min, 2 min, 5 min, 10 min, 30 min項目,
可是有些情況我們並不想讓 Display 因為省電保護或... 因而關閉顯示(黑畫面)
可是一開始卻並無此項目可選....

Step 1:  改packages/apps/Settings/res/values/arrays.xml

    <!-- Display settings.  The delay in inactivity before the screen is turned off. These are shown in a list dialog. -->
    <string-array name="screen_timeout_entries">
        <item>15 seconds</item>
        <item>30 seconds</item>
        <item>1 minute</item>
        <item>2 minutes</item>
        <item>5 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>300000</item>
        <!-- Do not translate. -->
        <item>600000</item>
        <!-- Do not translate. -->
        <item>1800000</item>
        <item>-1</item>
    </string-array>



Step 2: 修改所有 packages/apps/Settings/res/values-xxxx/array.xml (各語系的顯示)
以英文為例:  packages/apps/Settings/res/values-en-rGB/arrays.xml

  <string-array name="screen_timeout_entries">
    <item msgid="3342301044271143016">"15 seconds"</item>
    <item msgid="8881760709354815449">"30 seconds"</item>
    <item msgid="7589406073232279088">"1 minute"</item>
    <item msgid="7001195990902244174">"2 minutes"</item>
    <item msgid="7489864775127957179">"5 minutes"</item>
    <item msgid="2314124409517439288">"10 minutes"</item>
    <item msgid="6864027152847611413">"30 minutes"</item>
    <item msgid="9989898989898989898">"Never"</item>
  </string-array>


Step 3: 修改code:  packages/apps/Settings/src/com/android/settings/DisplaySettings.java

    private void 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);
    }


Step 4: 修改code: frameworks/base/services/java/com/android/server/power/PowerManagerService.java

    private void updateUserActivitySummaryLocked(long now, int dirty) {
        // Update the status of the user activity 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) {
                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));
            }
        }
    }



源自: http://ansonlai.iteye.com/blog/1899764

沒有留言:

張貼留言