宝剑锋从磨砺出,梅花香自苦寒来。这篇文章主要讲述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设置系统开机自己主动永不休眠】
推荐阅读
- bWAPP----HTML Injection - Stored (Blog)
- Android studio 插件之 GsonFormat (自己主动生成javabean)
- Android开发学习--MVP模式入门
- 在android开发中如何使用JavaMail程序
- Android 音频播放——AudioTrack直接播PCMMediaPlayer播媒体文件可以是audio
- Android 音频采集——MediaRecord(编码后录影文件) AudioRecord(PCM原始数据)
- [WPF]The type name ‘App’ does not exist in the type '...'的问题
- 如何搭建类似湖南卫视芒果TV直播的APP后台软件系统
- 移动webApp - 1像素实现(点5像素的秘密)