Chris Ye | 11857fb | 2020-02-28 21:47:22 -0800 | [diff] [blame^] | 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 | /** |
| 28 | * BatterySaverPolicyConfig is a structure of configs to set Battery Saver policy flags. |
| 29 | * This file needs to be kept in sync with |
| 30 | * frameworks/base/core/java/android/os/BatterySaverPolicyConfig.java |
| 31 | */ |
| 32 | struct BatterySaverPolicyConfig : public android::Parcelable { |
| 33 | |
| 34 | BatterySaverPolicyConfig(float adjustBrightnessFactor = 1.0f, |
| 35 | bool advertiseIsEnabled = false, |
| 36 | bool deferFullBackup = false, |
| 37 | bool deferKeyValueBackup = false, |
| 38 | std::vector<std::pair<String16, String16>> deviceSpecificSettings = {}, |
| 39 | bool disableAnimation = false, |
| 40 | bool disableAod = false, |
| 41 | bool disableLaunchBoost = false, |
| 42 | bool disableOptionalSensors = false, |
| 43 | bool disableSoundTrigger = 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 | : mAdjustBrightnessFactor(adjustBrightnessFactor), |
| 54 | mAdvertiseIsEnabled(advertiseIsEnabled), |
| 55 | mDeferFullBackup(deferFullBackup), |
| 56 | mDeferKeyValueBackup(deferKeyValueBackup), |
| 57 | mDeviceSpecificSettings(deviceSpecificSettings), |
| 58 | mDisableAnimation(disableAnimation), |
| 59 | mDisableAod(disableAod), |
| 60 | mDisableLaunchBoost(disableLaunchBoost), |
| 61 | mDisableOptionalSensors(disableOptionalSensors), |
| 62 | mDisableSoundTrigger(disableSoundTrigger), |
| 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 | } |
| 73 | |
| 74 | status_t readFromParcel(const android::Parcel* parcel) override; |
| 75 | status_t writeToParcel(android::Parcel* parcel) const override; |
| 76 | bool operator == (const BatterySaverPolicyConfig &bsp) const { |
| 77 | return fabs(mAdjustBrightnessFactor - bsp.mAdjustBrightnessFactor) == 0.0f && |
| 78 | mAdvertiseIsEnabled == bsp.mAdvertiseIsEnabled && |
| 79 | mDeferFullBackup == bsp.mDeferFullBackup && |
| 80 | mDeferKeyValueBackup == bsp.mDeferKeyValueBackup && |
| 81 | mDeviceSpecificSettings == bsp.mDeviceSpecificSettings && |
| 82 | mDisableAnimation == bsp.mDisableAnimation && |
| 83 | mDisableAod == bsp.mDisableAod && |
| 84 | mDisableLaunchBoost == bsp.mDisableLaunchBoost && |
| 85 | mDisableOptionalSensors == bsp.mDisableOptionalSensors && |
| 86 | mDisableSoundTrigger == bsp.mDisableSoundTrigger && |
| 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 | } |
| 97 | |
| 98 | private: |
| 99 | status_t readDeviceSpecificSettings(const android::Parcel *parcel); |
| 100 | status_t writeDeviceSpecificSettings(android::Parcel *parcel) const; |
| 101 | /** Adjust screen brightness factor */ |
| 102 | float mAdjustBrightnessFactor; |
| 103 | /** Is advertise enabled */ |
| 104 | bool mAdvertiseIsEnabled; |
| 105 | /** Defer full backup */ |
| 106 | bool mDeferFullBackup; |
| 107 | /** Defer key value backup */ |
| 108 | bool mDeferKeyValueBackup; |
| 109 | /** Device specific settings */ |
| 110 | std::vector<std::pair<String16, String16>> mDeviceSpecificSettings; |
| 111 | /** Disable animation */ |
| 112 | bool mDisableAnimation; |
| 113 | /** Disable Aod */ |
| 114 | bool mDisableAod; |
| 115 | /** Disable launch boost */ |
| 116 | bool mDisableLaunchBoost; |
| 117 | /** Disable optional sensors */ |
| 118 | bool mDisableOptionalSensors; |
| 119 | /** Disable sound trigger */ |
| 120 | bool mDisableSoundTrigger; |
| 121 | /** Disable vibration */ |
| 122 | bool mDisableVibration; |
| 123 | /** Enable adjust brightness */ |
| 124 | bool mEnableAdjustBrightness; |
| 125 | /** Enable data saver */ |
| 126 | bool mEnableDataSaver; |
| 127 | /** Enable firewall */ |
| 128 | bool mEnableFirewall; |
| 129 | /** Enable night mode */ |
| 130 | bool mEnableNightMode; |
| 131 | /** Enable quick doze */ |
| 132 | bool mEnableQuickDoze; |
| 133 | /** Force all Apps standby */ |
| 134 | bool mForceAllAppsStandby; |
| 135 | /** Force Background check */ |
| 136 | bool mForceBackgroundCheck; |
| 137 | /** Location mode */ |
| 138 | LocationMode mLocationMode; |
| 139 | }; |
| 140 | |
| 141 | } // namespace android::os |
| 142 | |
| 143 | #endif /* ANDROID_OS_BATTERY_SAVER_POLICY_CONFIG_H */ |