Add HAL method to return SupportInfo object for PowerHAL
Add a way for the PowerHAL to return a single official, canonical
support object for all of the things it does or doesn't support,
alleviating the need for continued plumbing here by consolidating
all of the info into one place.
Test: atest VtsHalPowerTargetTest
Bug: 367803904
Flag: EXEMPT HAL interface change
Change-Id: Ie5880dc1e8a5083141dc5858e59c560effd220e5
diff --git a/power/aidl/default/Power.cpp b/power/aidl/default/Power.cpp
index 64294e5..36d0055 100644
--- a/power/aidl/default/Power.cpp
+++ b/power/aidl/default/Power.cpp
@@ -41,6 +41,11 @@
ndk::enum_range<Boost>().end()};
const std::vector<Mode> MODE_RANGE{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()};
+template <class T>
+constexpr size_t enum_size() {
+ return static_cast<size_t>(*(ndk::enum_range<T>().end() - 1)) + 1;
+}
+
ScopedAStatus Power::setMode(Mode type, bool enabled) {
LOG(VERBOSE) << "Power setMode: " << static_cast<int32_t>(type) << " to: " << enabled;
return ScopedAStatus::ok();
@@ -105,11 +110,30 @@
return ndk::ScopedAStatus::ok();
}
-ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
+ndk::ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
*outNanoseconds = std::chrono::nanoseconds(1ms).count();
return ScopedAStatus::ok();
}
+template <class E>
+int64_t bitsForEnum() {
+ return static_cast<int64_t>(std::bitset<enum_size<E>()>().set().to_ullong());
+}
+
+ndk::ScopedAStatus Power::getSupportInfo(SupportInfo* _aidl_return) {
+ static SupportInfo supportInfo = {
+ .usesSessions = false,
+ .modes = bitsForEnum<Mode>(),
+ .boosts = bitsForEnum<Boost>(),
+ .sessionHints = 0,
+ .sessionModes = 0,
+ .sessionTags = 0,
+ };
+ // Copy the support object into the binder
+ *_aidl_return = supportInfo;
+ return ndk::ScopedAStatus::ok();
+}
+
} // namespace example
} // namespace impl
} // namespace power