OSDN Git Service

power: Add android.hardware.power@1.0-impl
authorRuchi Kandoi <kandoiruchi@google.com>
Thu, 29 Sep 2016 20:56:05 +0000 (13:56 -0700)
committerRuchi Kandoi <kandoiruchi@google.com>
Tue, 11 Oct 2016 16:39:14 +0000 (09:39 -0700)
Bug: 31177288
Change-Id: I410768ef422ec11c2c9d955e7d3aec9a50cb361e
Signed-off-by: Ruchi Kandoi<kandoiruchi@google.com>
Android.bp
power/1.0/default/Android.bp [new file with mode: 0644]
power/1.0/default/Power.cpp [new file with mode: 0644]
power/1.0/default/Power.h [new file with mode: 0644]

index 417ce5d..0a664bf 100644 (file)
@@ -7,6 +7,7 @@ subdirs = [
     "nfc/1.0/default",
     "radio/1.0",
     "power/1.0",
+    "power/1.0/default",
     "tests/bar/1.0",
     "tests/baz/1.0",
     "tests/expression/1.0",
diff --git a/power/1.0/default/Android.bp b/power/1.0/default/Android.bp
new file mode 100644 (file)
index 0000000..b6c507c
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_shared {
+    name: "android.hardware.power@1.0-impl",
+    relative_install_path: "hw",
+    srcs: ["Power.cpp"],
+
+    shared_libs: [
+        "liblog",
+        "libhardware",
+        "libhidl",
+        "libhwbinder",
+        "libutils",
+        "android.hardware.power@1.0",
+    ],
+
+}
diff --git a/power/1.0/default/Power.cpp b/power/1.0/default/Power.cpp
new file mode 100644 (file)
index 0000000..5d0593b
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "android.hardware.power@1.0-impl"
+#include <hardware/hardware.h>
+#include <hardware/power.h>
+#include "Power.h"
+
+namespace android {
+namespace hardware {
+namespace power {
+namespace V1_0 {
+namespace implementation {
+
+Power::Power(power_module_t *module) : mModule(module) {
+    if (mModule)
+        mModule->init(mModule);
+}
+
+Power::~Power() {
+    delete(mModule);
+}
+
+// Methods from ::android::hardware::power::V1_0::IPower follow.
+Return<void> Power::setInteractive(bool interactive)  {
+    if (mModule->setInteractive > 0)
+        mModule->setInteractive(mModule, interactive ? 1 : 0);
+    return Void();
+}
+
+Return<void> Power::powerHint(PowerHint hint, int32_t data)  {
+    int32_t param = data;
+    if (mModule->powerHint > 0)
+        mModule->powerHint(mModule, static_cast<power_hint_t>(hint), &param);
+    return Void();
+}
+
+Return<void> Power::setFeature(Feature feature, bool activate)  {
+    if (mModule->setFeature > 0)
+        mModule->setFeature(mModule, static_cast<feature_t>(feature),
+                activate ? 1 : 0);
+    return Void();
+}
+
+Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb)  {
+    hidl_vec<PowerStatePlatformSleepState> states;
+    ssize_t number_platform_modes;
+    size_t *voters = nullptr;
+    power_state_platform_sleep_state_t *legacy_states = nullptr;
+    int ret;
+
+    if (mModule->get_number_of_platform_modes == nullptr ||
+            mModule->get_voter_list == nullptr ||
+            mModule->get_platform_low_power_stats == nullptr)
+    {
+        _hidl_cb(states, Status::SUCCESS);
+        return Void();
+    }
+
+    number_platform_modes = mModule->get_number_of_platform_modes(mModule);
+    if (number_platform_modes > 0)
+    {
+       voters = new size_t [number_platform_modes];
+       if (voters == nullptr)
+           goto done;
+
+       ret = mModule->get_voter_list(mModule, voters);
+       if (ret != 0)
+           goto done;
+
+       legacy_states = new power_state_platform_sleep_state_t [number_platform_modes];
+       if (legacy_states == nullptr)
+           goto done;
+
+       for (int i = 0; i < number_platform_modes; i++)
+       {
+          legacy_states[i].voters = nullptr;
+          legacy_states[i].voters = new power_state_voter_t [voters[i]];
+          if (legacy_states[i].voters == nullptr)
+              goto done;
+       }
+
+       ret = mModule->get_platform_low_power_stats(mModule, legacy_states);
+       if (ret != 0)
+           goto done;
+
+       states.resize(number_platform_modes);
+       for (int i = 0; i < number_platform_modes; i++)
+       {
+          power_state_platform_sleep_state_t& legacy_state = legacy_states[i];
+          PowerStatePlatformSleepState& state = states[i];
+          state.name = legacy_state.name;
+          state.residencyInMsecSinceBoot = legacy_state.residency_in_msec_since_boot;
+          state.totalTransitions = legacy_state.total_transitions;
+          state.supportedOnlyInSuspend = legacy_state.supported_only_in_suspend;
+          state.voters.resize(voters[i]);
+          for(size_t j = 0; j < voters[i]; j++)
+          {
+              state.voters[j].name = legacy_state.voters[j].name;
+              state.voters[j].totalTimeInMsecVotedForSinceBoot = legacy_state.voters[j].total_time_in_msec_voted_for_since_boot;
+              state.voters[j].totalNumberOfTimesVotedSinceBoot = legacy_state.voters[j].total_number_of_times_voted_since_boot;
+          }
+       }
+    }
+done:
+    if (legacy_states)
+    {
+        for (int i = 0; i < number_platform_modes; i++)
+        {
+            if(legacy_states[i].voters)
+                delete(legacy_states[i].voters);
+        }
+    }
+    delete[] legacy_states;
+    delete[] voters;
+    _hidl_cb(states, Status::SUCCESS);
+    return Void();
+}
+
+IPower* HIDL_FETCH_IPower(const char* name) {
+    int ret = 0;
+    const hw_module_t* hw_module = NULL;
+    power_module_t *power_module;
+    ret = hw_get_module(name, &hw_module);
+    if (ret == 0 && hw_module->methods->open > 0) {
+        ret = hw_module->methods->open(hw_module, name,
+                reinterpret_cast<hw_device_t**>(&power_module));
+        if (ret == 0) {
+            return new Power(power_module);
+        }
+        else {
+            ALOGE("Passthrough failed to load legacy HAL.");
+            return nullptr;
+        }
+    }
+    else {
+        ALOGE ("hw_get_module %s failed: %d", name, ret);
+        return nullptr;
+    }
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace power
+}  // namespace hardware
+}  // namespace android
diff --git a/power/1.0/default/Power.h b/power/1.0/default/Power.h
new file mode 100644 (file)
index 0000000..a0495be
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HIDL_GENERATED_android_hardware_power_V1_0_Power_H_
+#define HIDL_GENERATED_android_hardware_power_V1_0_Power_H_
+
+#include <android/hardware/power/1.0/IPower.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+namespace android {
+namespace hardware {
+namespace power {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::power::V1_0::Feature;
+using ::android::hardware::power::V1_0::IPower;
+using ::android::hardware::power::V1_0::PowerHint;
+using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
+using ::android::hardware::power::V1_0::Status;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Power : public IPower {
+    Power(power_module_t* module);
+    ~Power();
+    Return<void> setInteractive(bool interactive)  override;
+    Return<void> powerHint(PowerHint hint, int32_t data)  override;
+    Return<void> setFeature(Feature feature, bool activate)  override;
+    Return<void> getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb)  override;
+
+  private:
+    power_module_t* mModule;
+};
+
+extern "C" IPower* HIDL_FETCH_IPower(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace power
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_power_V1_0_Power_H_