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 | #define LOG_TAG "BatterySaverPolicyConfig" |
| 18 | |
| 19 | #include <android/BatterySaverPolicyConfig.h> |
| 20 | #include <binder/Parcel.h> |
| 21 | #include <utils/Log.h> |
| 22 | |
| 23 | namespace android::os { |
| 24 | |
| 25 | status_t BatterySaverPolicyConfig::readDeviceSpecificSettings(const android::Parcel *parcel) { |
| 26 | int32_t num = 0; |
| 27 | status_t ret = parcel->readInt32(&num); |
| 28 | if (ret != OK) { |
| 29 | return ret; |
| 30 | } |
| 31 | for (int i = 0; i < num; i++) { |
| 32 | String16 key, val; |
| 33 | ret = parcel->readString16(&key) ?: |
| 34 | parcel->readString16(&val); |
| 35 | if (ret != OK) { |
| 36 | return ret; |
| 37 | } |
| 38 | mDeviceSpecificSettings.emplace_back(key, val); |
| 39 | } |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | status_t BatterySaverPolicyConfig::readFromParcel(const android::Parcel *parcel) { |
| 44 | if (parcel == nullptr) { |
| 45 | ALOGE("%s: Null parcel", __func__); |
| 46 | return BAD_VALUE; |
| 47 | } |
| 48 | |
| 49 | return parcel->readFloat(&mAdjustBrightnessFactor) |
| 50 | ?: parcel->readBool(&mAdvertiseIsEnabled) |
| 51 | ?: parcel->readBool(&mDeferFullBackup) |
| 52 | ?: parcel->readBool(&mDeferKeyValueBackup) |
| 53 | ?: readDeviceSpecificSettings(parcel) |
| 54 | ?: parcel->readBool(&mDisableAnimation) |
| 55 | ?: parcel->readBool(&mDisableAod) |
| 56 | ?: parcel->readBool(&mDisableLaunchBoost) |
| 57 | ?: parcel->readBool(&mDisableOptionalSensors) |
Chris Ye | 11857fb | 2020-02-28 21:47:22 -0800 | [diff] [blame] | 58 | ?: parcel->readBool(&mDisableVibration) |
| 59 | ?: parcel->readBool(&mEnableAdjustBrightness) |
| 60 | ?: parcel->readBool(&mEnableDataSaver) |
| 61 | ?: parcel->readBool(&mEnableFirewall) |
| 62 | ?: parcel->readBool(&mEnableNightMode) |
| 63 | ?: parcel->readBool(&mEnableQuickDoze) |
| 64 | ?: parcel->readBool(&mForceAllAppsStandby) |
| 65 | ?: parcel->readBool(&mForceBackgroundCheck) |
Nicholas Ambur | bc581bd | 2020-12-08 13:17:00 -0800 | [diff] [blame] | 66 | ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mLocationMode)) |
| 67 | ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mSoundTriggerMode)); |
Chris Ye | 11857fb | 2020-02-28 21:47:22 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | status_t BatterySaverPolicyConfig::writeDeviceSpecificSettings(android::Parcel *parcel) const { |
| 71 | status_t ret = parcel->writeInt32(mDeviceSpecificSettings.size()); |
| 72 | if (ret != OK) { |
| 73 | return ret; |
| 74 | } |
| 75 | for (auto& settings : mDeviceSpecificSettings) { |
| 76 | ret = parcel->writeString16(settings.first) ?: |
| 77 | parcel->writeString16(settings.second); |
| 78 | if (ret != OK) { |
| 79 | return ret; |
| 80 | } |
| 81 | } |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | status_t BatterySaverPolicyConfig::writeToParcel(android::Parcel *parcel) const { |
| 86 | if (parcel == nullptr) { |
| 87 | ALOGE("%s: Null parcel", __func__); |
| 88 | return BAD_VALUE; |
| 89 | } |
| 90 | |
| 91 | return parcel->writeFloat(mAdjustBrightnessFactor) |
| 92 | ?: parcel->writeBool(mAdvertiseIsEnabled) |
| 93 | ?: parcel->writeBool(mDeferFullBackup) |
| 94 | ?: parcel->writeBool(mDeferKeyValueBackup) |
| 95 | ?: writeDeviceSpecificSettings(parcel) |
| 96 | ?: parcel->writeBool(mDisableAnimation) |
| 97 | ?: parcel->writeBool(mDisableAod) |
| 98 | ?: parcel->writeBool(mDisableLaunchBoost) |
| 99 | ?: parcel->writeBool(mDisableOptionalSensors) |
Chris Ye | 11857fb | 2020-02-28 21:47:22 -0800 | [diff] [blame] | 100 | ?: parcel->writeBool(mDisableVibration) |
| 101 | ?: parcel->writeBool(mEnableAdjustBrightness) |
| 102 | ?: parcel->writeBool(mEnableDataSaver) |
| 103 | ?: parcel->writeBool(mEnableFirewall) |
| 104 | ?: parcel->writeBool(mEnableNightMode) |
| 105 | ?: parcel->writeBool(mEnableQuickDoze) |
| 106 | ?: parcel->writeBool(mForceAllAppsStandby) |
| 107 | ?: parcel->writeBool(mForceBackgroundCheck) |
Nicholas Ambur | bc581bd | 2020-12-08 13:17:00 -0800 | [diff] [blame] | 108 | ?: parcel->writeInt32(static_cast<int32_t>(mLocationMode)) |
| 109 | ?: parcel->writeInt32(static_cast<int32_t>(mSoundTriggerMode)); |
Chris Ye | 11857fb | 2020-02-28 21:47:22 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | } // namespace android::os |