| 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_POWER_SAVE_STATE_H | 
 | 18 | #define ANDROID_OS_POWER_SAVE_STATE_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 |  * PowerSaveState is a structure to encapsulate PowerSaveState status. | 
 | 29 |  * This file needs to be kept in sync with frameworks/base/core/java/android/os/PowerSaveState.java | 
 | 30 |  */ | 
 | 31 | struct PowerSaveState : public android::Parcelable { | 
 | 32 |  | 
 | 33 |     PowerSaveState(bool batterySaverEnabled = false, | 
 | 34 |                    bool globalBatterySaverEnabled = false, | 
 | 35 |                    LocationMode locationMode = static_cast<LocationMode>(0), | 
 | 36 |                    float brightnessFactor = 0.5f) | 
 | 37 |             : mBatterySaverEnabled(batterySaverEnabled), | 
 | 38 |               mGlobalBatterySaverEnabled(globalBatterySaverEnabled), | 
 | 39 |               mLocationMode(locationMode), | 
 | 40 |               mBrightnessFactor(brightnessFactor) { | 
 | 41 |     } | 
 | 42 |  | 
 | 43 |     bool getBatterySaverEnabled() const { return mBatterySaverEnabled; } | 
 | 44 |     bool getGlobalBatterySaverEnabled() const { return mGlobalBatterySaverEnabled; } | 
 | 45 |     LocationMode getLocationMode() const { return mLocationMode; } | 
 | 46 |     float getBrightnessFactor() const { return mBrightnessFactor; } | 
 | 47 |     bool operator == (const PowerSaveState &ps) const { | 
 | 48 |         return mBatterySaverEnabled == ps.mBatterySaverEnabled && | 
 | 49 |                mGlobalBatterySaverEnabled == ps.mGlobalBatterySaverEnabled && | 
 | 50 |                mLocationMode == ps.mLocationMode && | 
 | 51 |                fabs(mBrightnessFactor - ps.mBrightnessFactor) == 0.0f; | 
 | 52 |     } | 
 | 53 |  | 
 | 54 |     status_t readFromParcel(const android::Parcel* parcel) override; | 
 | 55 |     status_t writeToParcel(android::Parcel* parcel) const override; | 
 | 56 |  | 
 | 57 | private: | 
 | 58 |     /** Whether we should enable battery saver for this service. */ | 
 | 59 |     bool mBatterySaverEnabled; | 
 | 60 |     /** Whether battery saver mode is enabled. */ | 
 | 61 |     bool mGlobalBatterySaverEnabled; | 
 | 62 |     /** Location mode */ | 
 | 63 |     LocationMode mLocationMode; | 
 | 64 |     /** Screen brightness factor. */ | 
 | 65 |     float mBrightnessFactor; | 
 | 66 | }; | 
 | 67 |  | 
 | 68 | } // namespace android::os | 
 | 69 |  | 
 | 70 | #endif /* ANDROID_OS_POWER_SAVE_STATE_H */ |