Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, The Linux Foundation. All rights reserved. |
dianlujitao | 19a43cc | 2018-01-18 21:24:30 +0800 | [diff] [blame] | 3 | * Copyright (C) 2017-2019 The LineageOS Project |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * * Neither the name of The Linux Foundation nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Michael Bestas | 434acc2 | 2019-09-29 21:06:22 +0300 | [diff] [blame] | 31 | #define LOG_TAG "android.hardware.power@1.2-service-qti" |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 32 | |
dianlujitao | 19a43cc | 2018-01-18 21:24:30 +0800 | [diff] [blame] | 33 | // #define LOG_NDEBUG 0 |
| 34 | |
Michael Bestas | 420f265 | 2019-09-29 23:59:05 +0300 | [diff] [blame] | 35 | #include "Power.h" |
Steve Kondik | e0a0903 | 2015-10-19 14:43:39 -0700 | [diff] [blame] | 36 | #include <android-base/file.h> |
Ethan Chen | d1cd53f | 2018-03-01 21:31:15 -0800 | [diff] [blame] | 37 | #include <log/log.h> |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 38 | #include "power-common.h" |
Keith Mok | e9c7fcc | 2015-11-13 09:46:14 -0800 | [diff] [blame] | 39 | #include "power-feature.h" |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 40 | |
| 41 | namespace android { |
| 42 | namespace hardware { |
| 43 | namespace power { |
| 44 | namespace V1_2 { |
| 45 | namespace implementation { |
| 46 | |
Michael Bestas | 420f265 | 2019-09-29 23:59:05 +0300 | [diff] [blame] | 47 | using ::android::hardware::hidl_vec; |
| 48 | using ::android::hardware::Return; |
| 49 | using ::android::hardware::Void; |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 50 | using ::android::hardware::power::V1_0::Feature; |
| 51 | using ::android::hardware::power::V1_0::PowerHint; |
| 52 | using ::android::hardware::power::V1_0::PowerStatePlatformSleepState; |
| 53 | using ::android::hardware::power::V1_0::Status; |
| 54 | using ::android::hardware::power::V1_1::PowerStateSubsystem; |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 55 | |
| 56 | Power::Power() { |
| 57 | power_init(); |
| 58 | } |
| 59 | |
| 60 | Return<void> Power::setInteractive(bool interactive) { |
Michael Bestas | 420f265 | 2019-09-29 23:59:05 +0300 | [diff] [blame] | 61 | set_interactive(interactive ? 1 : 0); |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 62 | return Void(); |
| 63 | } |
| 64 | |
| 65 | Return<void> Power::powerHint(PowerHint_1_0 hint, int32_t data) { |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 66 | power_hint(static_cast<power_hint_t>(hint), data ? (&data) : NULL); |
| 67 | return Void(); |
| 68 | } |
| 69 | |
Michael Bestas | 420f265 | 2019-09-29 23:59:05 +0300 | [diff] [blame] | 70 | Return<void> Power::setFeature(Feature feature, bool activate) { |
Steve Kondik | e0a0903 | 2015-10-19 14:43:39 -0700 | [diff] [blame] | 71 | switch (feature) { |
| 72 | #ifdef TAP_TO_WAKE_NODE |
| 73 | case Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE: |
LuK1337 | 0db671a | 2019-12-07 23:51:29 +0100 | [diff] [blame] | 74 | ::android::base::WriteStringToFile(activate ? "1" : "0", TAP_TO_WAKE_NODE, true); |
Steve Kondik | e0a0903 | 2015-10-19 14:43:39 -0700 | [diff] [blame] | 75 | break; |
| 76 | #endif |
| 77 | default: |
| 78 | break; |
| 79 | } |
Keith Mok | e9c7fcc | 2015-11-13 09:46:14 -0800 | [diff] [blame] | 80 | set_device_specific_feature(static_cast<feature_t>(feature), activate ? 1 : 0); |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 81 | return Void(); |
| 82 | } |
| 83 | |
| 84 | Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) { |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 85 | hidl_vec<PowerStatePlatformSleepState> states; |
| 86 | states.resize(0); |
| 87 | |
| 88 | _hidl_cb(states, Status::SUCCESS); |
| 89 | return Void(); |
| 90 | } |
| 91 | |
| 92 | Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) { |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 93 | hidl_vec<PowerStateSubsystem> subsystems; |
| 94 | |
| 95 | _hidl_cb(subsystems, Status::SUCCESS); |
| 96 | return Void(); |
| 97 | } |
| 98 | |
| 99 | Return<void> Power::powerHintAsync(PowerHint_1_0 hint, int32_t data) { |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 100 | return powerHint(hint, data); |
| 101 | } |
| 102 | |
| 103 | Return<void> Power::powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) { |
Michael Bestas | 420f265 | 2019-09-29 23:59:05 +0300 | [diff] [blame] | 104 | return powerHint(static_cast<PowerHint_1_0>(hint), data); |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 105 | } |
| 106 | |
dianlujitao | 19a43cc | 2018-01-18 21:24:30 +0800 | [diff] [blame] | 107 | Return<int32_t> Power::getFeature(LineageFeature feature) { |
| 108 | if (feature == LineageFeature::SUPPORTED_PROFILES) { |
| 109 | return get_number_of_profiles(); |
| 110 | } |
| 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | status_t Power::registerAsSystemService() { |
| 115 | status_t ret = 0; |
| 116 | |
| 117 | ret = IPower::registerAsService(); |
| 118 | if (ret != 0) { |
| 119 | ALOGE("Failed to register IPower (%d)", ret); |
| 120 | goto fail; |
| 121 | } else { |
| 122 | ALOGI("Successfully registered IPower"); |
| 123 | } |
| 124 | |
| 125 | ret = ILineagePower::registerAsService(); |
| 126 | if (ret != 0) { |
| 127 | ALOGE("Failed to register ILineagePower (%d)", ret); |
| 128 | goto fail; |
| 129 | } else { |
| 130 | ALOGI("Successfully registered ILineagePower"); |
| 131 | } |
| 132 | |
| 133 | fail: |
| 134 | return ret; |
| 135 | } |
| 136 | |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 137 | } // namespace implementation |
| 138 | } // namespace V1_2 |
| 139 | } // namespace power |
| 140 | } // namespace hardware |
| 141 | } // namespace android |