赞
踩
MTK Android6.0设置中的智能省电默认关闭
对于大多部分的setting中的配置信息,在default.xml文件中都有配置,但是也有一些设置中的配置信息在配置文件中没有的,所以就需要各位在源码中找到代码所处的位置,进行判断分析是否关闭或者打开。所以,就有了今天的博文。
以下是MTK Android6.0中的源码信息,高通、瑞芯微等源码仅供参考:
1、源码位置:alps\packages\apps\Settings\src\com\mediatek\settings\fuelgauge\PowerUsageExts.java
- // init power usage extends items 按钮初始化的分析
- public void initPowerUsageExtItems() {
- // background power saving
- if (FeatureOption.MTK_BG_POWER_SAVING_SUPPORT
- && FeatureOption.MTK_BG_POWER_SAVING_UI_SUPPORT) {
- mBgPowerSavingPrf = new SwitchPreference(mContext);
- mBgPowerSavingPrf.setKey(KEY_BACKGROUND_POWER_SAVING);
- mBgPowerSavingPrf.setTitle(R.string.bg_power_saving_title);
- mBgPowerSavingPrf.setOrder(PREFERENCE_ORDER_FIRST);
- mBgPowerSavingPrf.setChecked(Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.BG_POWER_SAVING_ENABLE, 0) != 1); //modified BG_POWER_SAVING_ENABLE Off by default
- mPowerUsageScreen.addPreference(mBgPowerSavingPrf);
- }
- }
-
- // on click 待机智能省电小按钮的响应事件
- public boolean onPowerUsageExtItemsClick(PreferenceScreen preferenceScreen,
- Preference preference) {
- if (KEY_BACKGROUND_POWER_SAVING.equals(preference.getKey())) {
- if (preference instanceof SwitchPreference) {
- SwitchPreference pref = (SwitchPreference) preference;
- int bgState = pref.isChecked() ? 1 : 0;
- Log.d(TAG, "background power saving state: " + bgState);
- Settings.System.putInt(mContext.getContentResolver(),
- Settings.System.BG_POWER_SAVING_ENABLE, bgState);
- if (mBgPowerSavingPrf != null) {
- mBgPowerSavingPrf.setChecked(pref.isChecked());
- }
- }
- // If user click on PowerSaving preference just return here
- return true;
- }
- return false;
- }
到此,Settings中的电池->待机智能省电就可以自行改写了。
2、由于最近碰机器灭屏断网的问题,经过APP以及系统调试判断时智能待机省电打开的原因。但是,在这个问题上我是默认把待机智能省电关闭的了,并且经过测试部门测试某些特定功能也是通过的,怎么还是打开的呢?于是再次跟踪源码分析了一下,上面对于某些软件来说可能只是UI层面的显示关闭,并没有真正的关闭智能省电。特此纠正一下上面分析流程和总结结果:
首先,在以前的分析代码中,initPowerUsageExtItems()这个初始化方法,是在刚开机的时候设置UI开关按钮的状态是on还是off;如若想要改变UI按钮的状态就要onPowerUsageExtItemsClick()这个方法点击响应事件,但是根据他的响应具体是设置1或者0两个值;
- int bgState = pref.isChecked() ? 1 : 0;
- Log.d(TAG, "background power saving state: " + bgState);
- Settings.System.putInt(mContext.getContentResolver(),
- Settings.System.BG_POWER_SAVING_ENABLE, bgState);//通过这里写入值
通过字段BG_POWER_SAVING_ENABLE再grep源码
在,frameworks/base/services/core/java/com/mediatek/datashaping/DataShapingServiceImpl.java文件中又做了处理(设置以及开始改变功能的实现):
- public void start() {
- mGateOpenState = new GateOpenState(this, mContext);
- mGateOpenLockedState = new GateOpenLockedState(this, mContext);
- mGateCloseState = new GateCloseState(this, mContext);
- setCurrentState(DATA_SHAPING_STATE_OPEN_LOCKED);
-
- Slog.d(TAG, "start check user preference");
- mContext.getContentResolver().registerContentObserver(
- Settings.System.getUriFor(Settings.System.BG_POWER_SAVING_ENABLE), true,
- mSettingsObserver);
- mSettingsObserver.onChange(false);
- }
- public boolean openLteDataUpLinkGate(boolean isForce) {
- if (!mDataShapingEnabled) {
- Slog.d(TAG, "[openLteDataUpLinkGate] DataShaping is Disabled!");
- return false;
- }
- boolean powerSavingEnabled = 0 != Settings.System.getInt(
- mContext.getContentResolver(), Settings.System.BG_POWER_SAVING_ENABLE, 0);
- /// M: AlarmGrouping & DataShaping Testing Config to force Enable or Disable Feature. @{
- if ("0".equals(SystemProperties.get("persist.alarmgroup.enable", "-1"))) {
- powerSavingEnabled = false;
- Slog.d(TAG, "[openLteDataUpLinkGate] persist.alarmgroup.enable is false");
- } else if ("1".equals(SystemProperties.get("persist.alarmgroup.enable", "-1"))) {
- powerSavingEnabled = true;
- Slog.d(TAG, "[openLteDataUpLinkGate] persist.alarmgroup.enable is true");
- }
- /// M: AlarmGrouping & DataShaping Testing Config to force Enable or Disable Feature. @}
- if (powerSavingEnabled) {
- if (System.currentTimeMillis() - mLastAlarmTriggerSuccessTime
- >= ALARM_MANAGER_OPEN_GATE_INTERVAL) {
- if (mDataShapingHandler != null) {
- mDataShapingHandler.sendEmptyMessage(MSG_ALARM_MANAGER_TRIGGER);
- }
- mLastAlarmTriggerSuccessTime = System.currentTimeMillis();
- Slog.d(TAG, "Alarm manager openLteDataUpLinkGate: true");
- return true;
- } else {
- Slog.d(TAG, "Alarm manager openLteDataUpLinkGate: false");
- return false;
- }
- } else {
- Slog.d(TAG, "[openLteDataUpLinkGate] powerSaving is Disabled!");
- return false;
- }
- }
- private ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
- public void onChange(boolean selfChange) {
- boolean dataShapingEnabled = 0 != Settings.System.getInt(
- mContext.getContentResolver(), Settings.System.BG_POWER_SAVING_ENABLE, 0);
- .
- .
- .
- .
- }
frameworks/base/packages/SettingsProvider/src/com/mediatek/providers/utils/ProvidersUtils.java,通过这个文件就可看出framework设置的具体值,
- loadIntegerSetting(stmt, Settings.System.BG_POWER_SAVING_ENABLE,
- R.integer.def_bg_power_saving);
但是这个是由R.integer.def_bg_power_saving供值,所以追踪到:
frameworks\base\packages\SettingsProvider\res\values\mtk_defaults.xml中的 以下字段
<integer name="def_bg_power_saving">1</integer><!-设置对应的值,选择0关闭或者1开启-->
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。