最近项目需求里需要在设置菜单的休眠模式里添加一项永不休眠选择项。针对MTK平台的修改方式有如下几步骤。(其他平台和android原生系统的修改方式类似,只是android原生系统修改永不休眠需要通过设置较长的时间实现)
1.由于代码不同,在Jelly Bean(android4.2)之前,如下
在alps\frameworks\base\packages\SettingsProvider\res\values\defaults.xml中设置def_screen_off_timeout为-1,即
<integer name="def_screen_off_timeout">-1</integer>
同时请注意,经由下面的操作,setting里面休眠时间的Never菜单才会出来:
修改alps\packages\apps\Settings\res\values\arrays.xml:
<!-- Display settings. The delay in inactivity before the screen is turned off. These are shown ain 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>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>
修改对比语言value文件夹下的arrays.xml,修改screen_timeout_entries对应的翻译。不用管那个msgid,只是google用来表示是他自己的资源而已,直接添加<item >"不灭"</item>即可,请知悉。
2,若是android4.2的code,请在前面的修改基础上再修改下面的代码:
PowerManagerService.java
private void updateUserActivitySummaryLocked(long now, int dirty) { ..... //change code here ============== Slog.d(TAG,"mScreenOffTimeoutSetting ="+mScreenOffTimeoutSetting); //if (mUserActivitySummary != 0 ) { if (mUserActivitySummary != 0 && mScreenOffTimeoutSetting > 0) { //change code here end ============== Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT); msg.setAsynchronous(true); mHandler.sendMessageAtTime(msg, nextTimeout); }
3.最后对packages/apps/Settings/src/com/android/settings下的DisplaySettings.java文件进行修改,修改如下:
private void updateTimeoutPreferenceDescription(long currentTimeout) { String summary; //code here //if (currentTimeout < 0) { // Unsupported value //summary = ""; // } else { final CharSequence[] entries = preference.getEntries(); final CharSequence[] values = preference.getEntryValues(); //code end .................................... if (entries.length != 0) { //code here if(best == 7){ summary = "无操作 永不灭"; }else{ summary = preference.getContext().getString( R.string.screen_timeout_summary, entries[best]); Log.i("zfc","summary="+summary+",best="+best); } //code end } else { summary = ""; }