Home | History | Annotate | Download | only in power
      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 (at) 1.1-service.marlin"
     18 
     19 #include <android/log.h>
     20 #include <utils/Log.h>
     21 
     22 #include <android-base/properties.h>
     23 
     24 #include "Power.h"
     25 
     26 enum subsystem_type {
     27     SUBSYSTEM_WLAN,
     28 
     29     //Don't add any lines after that line
     30     SUBSYSTEM_COUNT
     31 };
     32 
     33 enum wlan_param_id {
     34     CUMULATIVE_SLEEP_TIME_MS,
     35     CUMULATIVE_TOTAL_ON_TIME_MS,
     36     DEEP_SLEEP_ENTER_COUNTER,
     37     LAST_DEEP_SLEEP_ENTER_TSTAMP_MS,
     38 
     39     //Don't add any lines after that line
     40     WLAN_PARAM_COUNT
     41 };
     42 
     43 enum wlan_state_id {
     44     WLAN_STATE_ACTIVE = 0,
     45     WLAN_STATE_DEEP_SLEEP,
     46 
     47     //Don't add any lines after that line
     48     WLAN_STATE_COUNT
     49 };
     50 
     51 namespace android {
     52 namespace hardware {
     53 namespace power {
     54 namespace V1_1 {
     55 namespace implementation {
     56 
     57 using ::android::hardware::power::V1_0::Feature;
     58 using ::android::hardware::power::V1_0::PowerHint;
     59 using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
     60 using ::android::hardware::power::V1_0::Status;
     61 using ::android::hardware::power::V1_1::PowerStateSubsystem;
     62 using ::android::hardware::hidl_vec;
     63 using ::android::hardware::Return;
     64 using ::android::hardware::Void;
     65 
     66 Power::Power() {
     67 }
     68 
     69 // Methods from ::android::hardware::power::V1_0::IPower follow.
     70 Return<void> Power::setInteractive(bool __attribute__((__unused__)) interactive)  {
     71     return Void();
     72 }
     73 
     74 Return<void> Power::powerHint(PowerHint __attribute__((__unused__)) hint, int32_t __attribute__((__unused__)) data) {
     75     return Void();
     76 }
     77 
     78 Return<void> Power::setFeature(Feature /*feature*/, bool /*activate*/)  {
     79     return Void();
     80 }
     81 
     82 Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) {
     83 
     84     hidl_vec<PowerStatePlatformSleepState> states;
     85 
     86     states.resize(0);
     87     _hidl_cb(states, Status::SUCCESS);
     88     return Void();
     89 }
     90 
     91 static int get_wlan_low_power_stats(struct PowerStateSubsystem &subsystem) {
     92 
     93     struct PowerStateSubsystemSleepState *state;
     94 
     95     subsystem.name = "wlan";
     96     subsystem.states.resize(WLAN_STATE_COUNT);
     97 
     98     /* Update statistics for Active State */
     99     state = &subsystem.states[WLAN_STATE_ACTIVE];
    100     state->name = "Active";
    101     state->residencyInMsecSinceBoot = 1000;
    102     state->totalTransitions = 1;
    103     state->lastEntryTimestampMs = 0;
    104     state->supportedOnlyInSuspend = false;
    105 
    106     /* Update statistics for Deep-Sleep state */
    107     state = &subsystem.states[WLAN_STATE_DEEP_SLEEP];
    108     state->name = "Deep-Sleep";
    109     state->residencyInMsecSinceBoot = 0;
    110     state->totalTransitions = 0;
    111     state->lastEntryTimestampMs = 0;
    112     state->supportedOnlyInSuspend = false;
    113 
    114     return 0;
    115 }
    116 
    117 Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) {
    118 
    119     hidl_vec<PowerStateSubsystem> subsystems;
    120     int ret;
    121 
    122     subsystems.resize(subsystem_type::SUBSYSTEM_COUNT);
    123 
    124     //We currently have only one Subsystem for WLAN
    125     ret = get_wlan_low_power_stats(subsystems[subsystem_type::SUBSYSTEM_WLAN]);
    126     if (ret != 0) {
    127         goto done;
    128     }
    129 
    130     //Add query for other subsystems here
    131 
    132 done:
    133     _hidl_cb(subsystems, Status::SUCCESS);
    134     return Void();
    135 }
    136 
    137 Return<void> Power::powerHintAsync(PowerHint hint, int32_t data) {
    138     // just call the normal power hint in this oneway function
    139     return powerHint(hint, data);
    140 }
    141 
    142 }  // namespace implementation
    143 }  // namespace V1_1
    144 }  // namespace power
    145 }  // namespace hardware
    146 }  // namespace android
    147