1 /*
2  * Copyright (C) 2017 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 "android.hardware.power@1.1-service.hikey-common"
18 
19 #include <android/log.h>
20 #include <utils/Log.h>
21 
22 #include <android-base/properties.h>
23 
24 #include "Power.h"
25 #include "power-helper.h"
26 
27 enum subsystem_type {
28     //Don't add any lines after that line
29     SUBSYSTEM_COUNT
30 };
31 
32 
33 namespace android {
34 namespace hardware {
35 namespace power {
36 namespace V1_1 {
37 namespace implementation {
38 
39 using ::android::hardware::power::V1_0::Feature;
40 using ::android::hardware::power::V1_0::PowerHint;
41 using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
42 using ::android::hardware::power::V1_0::Status;
43 using ::android::hardware::power::V1_1::PowerStateSubsystem;
44 using ::android::hardware::hidl_vec;
45 using ::android::hardware::Return;
46 using ::android::hardware::Void;
47 
Power()48 Power::Power() {
49     power_init();
50 }
51 
52 // Methods from ::android::hardware::power::V1_0::IPower follow.
setInteractive(bool interactive)53 Return<void> Power::setInteractive(bool interactive)  {
54     power_set_interactive(interactive ? 1 : 0);
55     return Void();
56 }
57 
powerHint(PowerHint hint,int32_t data)58 Return<void> Power::powerHint(PowerHint hint, int32_t data) {
59     power_hint(static_cast<power_hint_t>(hint), data ? (&data) : NULL);
60     return Void();
61 }
62 
setFeature(Feature,bool)63 Return<void> Power::setFeature(Feature /*feature*/, bool /*activate*/)  {
64     return Void();
65 }
66 
getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb)67 Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) {
68 
69     hidl_vec<PowerStatePlatformSleepState> states;
70 
71     _hidl_cb(states, Status::SUCCESS);
72     return Void();
73 }
74 
75 
getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb)76 Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) {
77 
78     hidl_vec<PowerStateSubsystem> subsystems;
79     subsystems.resize(subsystem_type::SUBSYSTEM_COUNT);
80 
81     //Add query for other subsystems here
82 
83     _hidl_cb(subsystems, Status::SUCCESS);
84     return Void();
85 }
86 
powerHintAsync(PowerHint hint,int32_t data)87 Return<void> Power::powerHintAsync(PowerHint hint, int32_t data) {
88     // just call the normal power hint in this oneway function
89     return powerHint(hint, data);
90     return Void();
91 }
92 
93 }  // namespace implementation
94 }  // namespace V1_1
95 }  // namespace power
96 }  // namespace hardware
97 }  // namespace android
98