1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_OS_BATTERY_SAVER_POLICY_CONFIG_H 18 #define ANDROID_OS_BATTERY_SAVER_POLICY_CONFIG_H 19 20 #include <math.h> 21 #include <binder/Parcelable.h> 22 #include <utils/RefBase.h> 23 24 namespace android::os { 25 26 enum class LocationMode : int32_t; 27 enum class SoundTriggerMode : int32_t; 28 /** 29 * BatterySaverPolicyConfig is a structure of configs to set Battery Saver policy flags. 30 * This file needs to be kept in sync with 31 * frameworks/base/core/java/android/os/BatterySaverPolicyConfig.java 32 */ 33 struct BatterySaverPolicyConfig : public android::Parcelable { 34 35 BatterySaverPolicyConfig(float adjustBrightnessFactor = 1.0f, 36 bool advertiseIsEnabled = false, 37 bool deferFullBackup = false, 38 bool deferKeyValueBackup = false, 39 std::vector<std::pair<String16, String16>> deviceSpecificSettings = {}, 40 bool disableAnimation = false, 41 bool disableAod = false, 42 bool disableLaunchBoost = false, 43 bool disableOptionalSensors = false, 44 bool disableVibration = false, 45 bool enableAdjustBrightness = false, 46 bool enableDataSaver = false, 47 bool enableFirewall = false, 48 bool enableNightMode = false, 49 bool enableQuickDoze = false, 50 bool forceAllAppsStandby = false, 51 bool forceBackgroundCheck = false, 52 LocationMode locationMode = static_cast<LocationMode>(0), 53 SoundTriggerMode soundTriggerMode = static_cast<SoundTriggerMode>(0)) mAdjustBrightnessFactorBatterySaverPolicyConfig54 : mAdjustBrightnessFactor(adjustBrightnessFactor), 55 mAdvertiseIsEnabled(advertiseIsEnabled), 56 mDeferFullBackup(deferFullBackup), 57 mDeferKeyValueBackup(deferKeyValueBackup), 58 mDeviceSpecificSettings(deviceSpecificSettings), 59 mDisableAnimation(disableAnimation), 60 mDisableAod(disableAod), 61 mDisableLaunchBoost(disableLaunchBoost), 62 mDisableOptionalSensors(disableOptionalSensors), 63 mDisableVibration(disableVibration), 64 mEnableAdjustBrightness(enableAdjustBrightness), 65 mEnableDataSaver(enableDataSaver), 66 mEnableFirewall(enableFirewall), 67 mEnableNightMode(enableNightMode), 68 mEnableQuickDoze(enableQuickDoze), 69 mForceAllAppsStandby(forceAllAppsStandby), 70 mForceBackgroundCheck(forceBackgroundCheck), 71 mLocationMode(locationMode), 72 mSoundTriggerMode(soundTriggerMode) { 73 } 74 75 status_t readFromParcel(const android::Parcel* parcel) override; 76 status_t writeToParcel(android::Parcel* parcel) const override; 77 bool operator == (const BatterySaverPolicyConfig &bsp) const { 78 return fabs(mAdjustBrightnessFactor - bsp.mAdjustBrightnessFactor) == 0.0f && 79 mAdvertiseIsEnabled == bsp.mAdvertiseIsEnabled && 80 mDeferFullBackup == bsp.mDeferFullBackup && 81 mDeferKeyValueBackup == bsp.mDeferKeyValueBackup && 82 mDeviceSpecificSettings == bsp.mDeviceSpecificSettings && 83 mDisableAnimation == bsp.mDisableAnimation && 84 mDisableAod == bsp.mDisableAod && 85 mDisableLaunchBoost == bsp.mDisableLaunchBoost && 86 mDisableOptionalSensors == bsp.mDisableOptionalSensors && 87 mDisableVibration == bsp.mDisableVibration && 88 mEnableAdjustBrightness == bsp.mEnableAdjustBrightness && 89 mEnableDataSaver == bsp.mEnableDataSaver && 90 mEnableFirewall == bsp.mEnableFirewall && 91 mEnableNightMode == bsp.mEnableNightMode && 92 mEnableQuickDoze == bsp.mEnableQuickDoze && 93 mForceAllAppsStandby == bsp.mForceAllAppsStandby && 94 mForceBackgroundCheck == bsp.mForceBackgroundCheck && 95 mLocationMode == bsp.mLocationMode && 96 mSoundTriggerMode == bsp.mSoundTriggerMode; 97 } 98 99 private: 100 status_t readDeviceSpecificSettings(const android::Parcel *parcel); 101 status_t writeDeviceSpecificSettings(android::Parcel *parcel) const; 102 /** Adjust screen brightness factor */ 103 float mAdjustBrightnessFactor; 104 /** Is advertise enabled */ 105 bool mAdvertiseIsEnabled; 106 /** Defer full backup */ 107 bool mDeferFullBackup; 108 /** Defer key value backup */ 109 bool mDeferKeyValueBackup; 110 /** Device specific settings */ 111 std::vector<std::pair<String16, String16>> mDeviceSpecificSettings; 112 /** Disable animation */ 113 bool mDisableAnimation; 114 /** Disable Aod */ 115 bool mDisableAod; 116 /** Disable launch boost */ 117 bool mDisableLaunchBoost; 118 /** Disable optional sensors */ 119 bool mDisableOptionalSensors; 120 /** Disable vibration */ 121 bool mDisableVibration; 122 /** Enable adjust brightness */ 123 bool mEnableAdjustBrightness; 124 /** Enable data saver */ 125 bool mEnableDataSaver; 126 /** Enable firewall */ 127 bool mEnableFirewall; 128 /** Enable night mode */ 129 bool mEnableNightMode; 130 /** Enable quick doze */ 131 bool mEnableQuickDoze; 132 /** Force all Apps standby */ 133 bool mForceAllAppsStandby; 134 /** Force Background check */ 135 bool mForceBackgroundCheck; 136 /** Location mode */ 137 LocationMode mLocationMode; 138 /** SoundTrigger mode */ 139 SoundTriggerMode mSoundTriggerMode; 140 }; 141 142 } // namespace android::os 143 144 #endif /* ANDROID_OS_BATTERY_SAVER_POLICY_CONFIG_H */ 145