1. 程式人生 > >Android P 省電策略BatterySaverPolicy檔案

Android P 省電策略BatterySaverPolicy檔案

BatterySaverPolicy 原始碼

  • frameworks/base/services/core/java/com/android/server/power/BatterySaverPolicy.java
    粗略看了下很有作為,感覺是目前5.0、6.0、7.0、8.0中變化比較大的部分
/**
 * Class to decide whether to turn on battery saver mode for specific service
 *
 * IMPORTANT: This class shares the power manager lock, which is very low in the lock hierarchy.
 * Do not call out with the lock held, such as AccessibilityManager. (Settings provider is okay.)
 *
 * Test:
 atest ${ANDROID_BUILD_TOP}/frameworks/base/services/tests/servicestests/src/com/android/server/power/BatterySaverPolicyTest.java
 */
public class BatterySaverPolicy extends ContentObserver {
    private static final String TAG = "BatterySaverPolicy";

    public static final boolean DEBUG = true; // DO NOT SUBMIT WITH TRUE.

    // Secure setting for GPS behavior when battery saver mode is on.
    public static final String SECURE_KEY_GPS_MODE = "batterySaverGpsMode";

    private static final String KEY_GPS_MODE = "gps_mode"; // GPS 省電
    private static final String KEY_VIBRATION_DISABLED = "vibration_disabled"; // 禁用觸控震動
    private static final String KEY_ANIMATION_DISABLED = "animation_disabled"; // 禁用動畫,但是這裡可能會帶來閃屏現象
    private static final String KEY_SOUNDTRIGGER_DISABLED = "soundtrigger_disabled"; // 禁用觸控聲音
    private static final String KEY_FIREWALL_DISABLED = "firewall_disabled"; // 聯網防火牆
    private static final String KEY_ADJUST_BRIGHTNESS_DISABLED = "adjust_brightness_disabled";// 螢幕亮度省電
    private static final String KEY_DATASAVER_DISABLED = "datasaver_disabled"; // 流量節省
    private static final String KEY_LAUNCH_BOOST_DISABLED = "launch_boost_disabled"; // 啟動加速
    private static final String KEY_ADJUST_BRIGHTNESS_FACTOR = "adjust_brightness_factor"; // 螢幕亮度
    private static final String KEY_FULLBACKUP_DEFERRED = "fullbackup_deferred"; // 新機制
    private static final String KEY_KEYVALUE_DEFERRED = "keyvaluebackup_deferred";// 新機制
    private static final String KEY_FORCE_ALL_APPS_STANDBY = "force_all_apps_standby";// 新機制
    private static final String KEY_FORCE_BACKGROUND_CHECK = "force_background_check";// 新機制
    private static final String KEY_OPTIONAL_SENSORS_DISABLED = "optional_sensors_disabled";// 新機制 感測器省電
    private static final String KEY_AOD_DISABLED = "aod_disabled";
    private static final String KEY_SEND_TRON_LOG = "send_tron_log";

    private static final String KEY_CPU_FREQ_INTERACTIVE = "cpufreq-i"; // CPU模式切換
    private static final String KEY_CPU_FREQ_NONINTERACTIVE = "cpufreq-n";

    private final Object mLock;
    private final Handler mHandler;