blob: 4f0d757e66b26e4a456d6b8667389e81686c71d6 [file] [log] [blame]
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -07001/*
2 * Copyright (c) 2019, The Linux Foundation. All rights reserved.
dianlujitao19a43cc2018-01-18 21:24:30 +08003 * Copyright (C) 2017-2019 The LineageOS Project
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -07004 *
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 Bestas434acc22019-09-29 21:06:22 +030031#define LOG_TAG "android.hardware.power@1.2-service-qti"
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070032
dianlujitao19a43cc2018-01-18 21:24:30 +080033// #define LOG_NDEBUG 0
34
Michael Bestas420f2652019-09-29 23:59:05 +030035#include "Power.h"
Steve Kondike0a09032015-10-19 14:43:39 -070036#include <android-base/file.h>
Ethan Chend1cd53f2018-03-01 21:31:15 -080037#include <log/log.h>
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070038#include "power-common.h"
Keith Moke9c7fcc2015-11-13 09:46:14 -080039#include "power-feature.h"
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070040
41namespace android {
42namespace hardware {
43namespace power {
44namespace V1_2 {
45namespace implementation {
46
Michael Bestas420f2652019-09-29 23:59:05 +030047using ::android::hardware::hidl_vec;
48using ::android::hardware::Return;
49using ::android::hardware::Void;
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070050using ::android::hardware::power::V1_0::Feature;
51using ::android::hardware::power::V1_0::PowerHint;
52using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
53using ::android::hardware::power::V1_0::Status;
54using ::android::hardware::power::V1_1::PowerStateSubsystem;
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070055
56Power::Power() {
57 power_init();
58}
59
60Return<void> Power::setInteractive(bool interactive) {
Michael Bestas420f2652019-09-29 23:59:05 +030061 set_interactive(interactive ? 1 : 0);
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070062 return Void();
63}
64
65Return<void> Power::powerHint(PowerHint_1_0 hint, int32_t data) {
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070066 power_hint(static_cast<power_hint_t>(hint), data ? (&data) : NULL);
67 return Void();
68}
69
Michael Bestas420f2652019-09-29 23:59:05 +030070Return<void> Power::setFeature(Feature feature, bool activate) {
Steve Kondike0a09032015-10-19 14:43:39 -070071 switch (feature) {
72#ifdef TAP_TO_WAKE_NODE
73 case Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE:
LuK13370db671a2019-12-07 23:51:29 +010074 ::android::base::WriteStringToFile(activate ? "1" : "0", TAP_TO_WAKE_NODE, true);
Steve Kondike0a09032015-10-19 14:43:39 -070075 break;
76#endif
77 default:
78 break;
79 }
Keith Moke9c7fcc2015-11-13 09:46:14 -080080 set_device_specific_feature(static_cast<feature_t>(feature), activate ? 1 : 0);
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070081 return Void();
82}
83
84Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) {
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070085 hidl_vec<PowerStatePlatformSleepState> states;
86 states.resize(0);
87
88 _hidl_cb(states, Status::SUCCESS);
89 return Void();
90}
91
92Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) {
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070093 hidl_vec<PowerStateSubsystem> subsystems;
94
95 _hidl_cb(subsystems, Status::SUCCESS);
96 return Void();
97}
98
99Return<void> Power::powerHintAsync(PowerHint_1_0 hint, int32_t data) {
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -0700100 return powerHint(hint, data);
101}
102
103Return<void> Power::powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) {
Michael Bestas420f2652019-09-29 23:59:05 +0300104 return powerHint(static_cast<PowerHint_1_0>(hint), data);
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -0700105}
106
dianlujitao19a43cc2018-01-18 21:24:30 +0800107Return<int32_t> Power::getFeature(LineageFeature feature) {
108 if (feature == LineageFeature::SUPPORTED_PROFILES) {
109 return get_number_of_profiles();
110 }
111 return -1;
112}
113
114status_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
133fail:
134 return ret;
135}
136
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -0700137} // namespace implementation
138} // namespace V1_2
139} // namespace power
140} // namespace hardware
141} // namespace android