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

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-12 17:41:47

Android设置系统开机自动永不休眠的相关文章

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\arr

android 设置系统屏幕亮度

android 设置系统屏幕亮度 权限<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission> /*** 获得当前屏幕亮度的模式 * SCREEN_BRIGHTNESS_MODE_AUTOMATIC=1 为自动调节屏幕亮度* SCREEN_BRIGHTNESS_MODE_MANUAL=0 为手动调节屏幕亮度*/private int getScreen

WPF 设置程序开机自动运行(+注册表项)

#region 设置程序开机自动运行(+注册表项) RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (rgkRun == null) { rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\Cur

Android 设置系统亮度

Android 播放器中修改系统亮度 /** * 播放器Activity */ public class PlayerActivity extends Activity { /** * 系统是否自动调节亮度 */ private boolean isAutoBrightness = false; /** * 系统亮度变化值 */ private static final int SYSTEM_BRIGHTNESS_CHANGE_VALUES = 25; /** * 最大系统音量值 */ priv

[转载] CentOS系统开机自动挂载光驱 和 fstab文件详解

参考 http://blog.itpub.net/12272958/viewspace-676977/ 一.开机自动挂载光驱 1.按习惯,root用户,在/media目录下建立目录cdrom——mkdir/media/cdrom 2.修改/etc/fstab文件.在该文件最后按顺序添加如下内容: /dev/cdrom /media/cdrom auto exec 0 0 3.重启CentOS系统 4.执行命令:mount -tiso9660 /dev/cdrom /media/cdrom 完成光

C#.NET Form设置/取消开机自动运行,判断程序是否已经设置成开机自动启动(转载)

#region//开机自动运行        private void CB_Auto_CheckedChanged(object sender, EventArgs e)        {//CB_Auto是一个Checkbox,IsAutoRun 是个布尔变量,用于控制是否开机运行            if (CB_Auto.Checked == true) IsAutoRun = true;            else IsAutoRun = false;            tr

Android 设置系统时间与日期方法

一.设置系统时间 static void setTime(Context context, int hourOfDay, int minute) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, hourOfDay); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long wh

Android 设置系统的返回键 和软键盘获取焦点问题

很多朋友出现过这样的一个问题,当底部弹出评论框时,有几个问题,一个是软件盘弹出时怎么让焦点在输入框,关于这个问题,本人也是遇到过,解决了很久,有的是在布局设置或者代码里setFocusable(true),并没有用,又在代码或者代码里设置requestFocus(),依然没有用,其实这个解决办法是没有错的,但是为什么会没用呢,因为并没有及时是在软件盘弹出时设置,所以先提出隐藏和显示软件盘的方法 private void onFocusChange(boolean hasFocus) { fina

转:android中APK开机自动运行

背景知识:当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为android.intent.action.BOOT_COMPLETED.只要在程序中“捕捉”到这个消息,再启动之即可.记住,Android框架说:Don't call me, I'll call you back.我们要做的是做好接收这个消息的准备,而实现的手段就是实现一个BroadcastReceiver. 代码解析: 1.界面Activity:SayHello.jav