当前位置:   article > 正文

android6.0设置-电池-智能省电

android6.0设置-电池-智能省电

                                              MTK Android6.0设置中的智能省电默认关闭

        对于大多部分的setting中的配置信息,在default.xml文件中都有配置,但是也有一些设置中的配置信息在配置文件中没有的,所以就需要各位在源码中找到代码所处的位置,进行判断分析是否关闭或者打开。所以,就有了今天的博文。

       以下是MTK Android6.0中的源码信息,高通、瑞芯微等源码仅供参考:

1、源码位置:alps\packages\apps\Settings\src\com\mediatek\settings\fuelgauge\PowerUsageExts.java

  1. // init power usage extends items 按钮初始化的分析
  2. public void initPowerUsageExtItems() {
  3. // background power saving
  4. if (FeatureOption.MTK_BG_POWER_SAVING_SUPPORT
  5. && FeatureOption.MTK_BG_POWER_SAVING_UI_SUPPORT) {
  6. mBgPowerSavingPrf = new SwitchPreference(mContext);
  7. mBgPowerSavingPrf.setKey(KEY_BACKGROUND_POWER_SAVING);
  8. mBgPowerSavingPrf.setTitle(R.string.bg_power_saving_title);
  9. mBgPowerSavingPrf.setOrder(PREFERENCE_ORDER_FIRST);
  10. mBgPowerSavingPrf.setChecked(Settings.System.getInt(mContext.getContentResolver(),
  11. Settings.System.BG_POWER_SAVING_ENABLE, 0) != 1); //modified BG_POWER_SAVING_ENABLE Off by default
  12. mPowerUsageScreen.addPreference(mBgPowerSavingPrf);
  13. }
  14. }
  15. // on click 待机智能省电小按钮的响应事件
  16. public boolean onPowerUsageExtItemsClick(PreferenceScreen preferenceScreen,
  17. Preference preference) {
  18. if (KEY_BACKGROUND_POWER_SAVING.equals(preference.getKey())) {
  19. if (preference instanceof SwitchPreference) {
  20. SwitchPreference pref = (SwitchPreference) preference;
  21. int bgState = pref.isChecked() ? 1 : 0;
  22. Log.d(TAG, "background power saving state: " + bgState);
  23. Settings.System.putInt(mContext.getContentResolver(),
  24. Settings.System.BG_POWER_SAVING_ENABLE, bgState);
  25. if (mBgPowerSavingPrf != null) {
  26. mBgPowerSavingPrf.setChecked(pref.isChecked());
  27. }
  28. }
  29. // If user click on PowerSaving preference just return here
  30. return true;
  31. }
  32. return false;
  33. }

       到此,Settings中的电池->待机智能省电就可以自行改写了。

2、由于最近碰机器灭屏断网的问题,经过APP以及系统调试判断时智能待机省电打开的原因。但是,在这个问题上我是默认把待机智能省电关闭的了,并且经过测试部门测试某些特定功能也是通过的,怎么还是打开的呢?于是再次跟踪源码分析了一下,上面对于某些软件来说可能只是UI层面的显示关闭,并没有真正的关闭智能省电。特此纠正一下上面分析流程和总结结果:

首先,在以前的分析代码中,initPowerUsageExtItems()这个初始化方法,是在刚开机的时候设置UI开关按钮的状态是on还是off;如若想要改变UI按钮的状态就要onPowerUsageExtItemsClick()这个方法点击响应事件,但是根据他的响应具体是设置1或者0两个值;

  1. int bgState = pref.isChecked() ? 1 : 0;
  2. Log.d(TAG, "background power saving state: " + bgState);
  3. Settings.System.putInt(mContext.getContentResolver(),
  4. Settings.System.BG_POWER_SAVING_ENABLE, bgState);//通过这里写入值

通过字段BG_POWER_SAVING_ENABLE再grep源码

在,frameworks/base/services/core/java/com/mediatek/datashaping/DataShapingServiceImpl.java文件中又做了处理(设置以及开始改变功能的实现):

  1. public void start() {
  2. mGateOpenState = new GateOpenState(this, mContext);
  3. mGateOpenLockedState = new GateOpenLockedState(this, mContext);
  4. mGateCloseState = new GateCloseState(this, mContext);
  5. setCurrentState(DATA_SHAPING_STATE_OPEN_LOCKED);
  6. Slog.d(TAG, "start check user preference");
  7. mContext.getContentResolver().registerContentObserver(
  8. Settings.System.getUriFor(Settings.System.BG_POWER_SAVING_ENABLE), true,
  9. mSettingsObserver);
  10. mSettingsObserver.onChange(false);
  11. }
  1. public boolean openLteDataUpLinkGate(boolean isForce) {
  2. if (!mDataShapingEnabled) {
  3. Slog.d(TAG, "[openLteDataUpLinkGate] DataShaping is Disabled!");
  4. return false;
  5. }
  6. boolean powerSavingEnabled = 0 != Settings.System.getInt(
  7. mContext.getContentResolver(), Settings.System.BG_POWER_SAVING_ENABLE, 0);
  8. /// M: AlarmGrouping & DataShaping Testing Config to force Enable or Disable Feature. @{
  9. if ("0".equals(SystemProperties.get("persist.alarmgroup.enable", "-1"))) {
  10. powerSavingEnabled = false;
  11. Slog.d(TAG, "[openLteDataUpLinkGate] persist.alarmgroup.enable is false");
  12. } else if ("1".equals(SystemProperties.get("persist.alarmgroup.enable", "-1"))) {
  13. powerSavingEnabled = true;
  14. Slog.d(TAG, "[openLteDataUpLinkGate] persist.alarmgroup.enable is true");
  15. }
  16. /// M: AlarmGrouping & DataShaping Testing Config to force Enable or Disable Feature. @}
  17. if (powerSavingEnabled) {
  18. if (System.currentTimeMillis() - mLastAlarmTriggerSuccessTime
  19. >= ALARM_MANAGER_OPEN_GATE_INTERVAL) {
  20. if (mDataShapingHandler != null) {
  21. mDataShapingHandler.sendEmptyMessage(MSG_ALARM_MANAGER_TRIGGER);
  22. }
  23. mLastAlarmTriggerSuccessTime = System.currentTimeMillis();
  24. Slog.d(TAG, "Alarm manager openLteDataUpLinkGate: true");
  25. return true;
  26. } else {
  27. Slog.d(TAG, "Alarm manager openLteDataUpLinkGate: false");
  28. return false;
  29. }
  30. } else {
  31. Slog.d(TAG, "[openLteDataUpLinkGate] powerSaving is Disabled!");
  32. return false;
  33. }
  34. }
  1. private ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
  2. public void onChange(boolean selfChange) {
  3. boolean dataShapingEnabled = 0 != Settings.System.getInt(
  4. mContext.getContentResolver(), Settings.System.BG_POWER_SAVING_ENABLE, 0);
  5. .
  6. .
  7. .
  8. .
  9. }

frameworks/base/packages/SettingsProvider/src/com/mediatek/providers/utils/ProvidersUtils.java,通过这个文件就可看出framework设置的具体值,

  1. loadIntegerSetting(stmt, Settings.System.BG_POWER_SAVING_ENABLE,
  2. 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开启-->

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号