diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 71243bf7dd..25d1ae4be7 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -432,7 +432,7 @@ android.hardware.power - 2-3 + 2-4 IPower default diff --git a/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/IPowerHintSession.aidl b/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/IPowerHintSession.aidl index 1d3ecb7eee..928668cd08 100644 --- a/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/IPowerHintSession.aidl +++ b/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/IPowerHintSession.aidl @@ -39,4 +39,5 @@ interface IPowerHintSession { oneway void pause(); oneway void resume(); oneway void close(); + oneway void sendHint(android.hardware.power.SessionHint hint); } diff --git a/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/SessionHint.aidl b/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/SessionHint.aidl new file mode 100644 index 0000000000..b19c77b525 --- /dev/null +++ b/power/aidl/aidl_api/android.hardware.power/current/android/hardware/power/SessionHint.aidl @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.power; +@Backing(type="int") @VintfStability +enum SessionHint { + CPU_LOAD_UP = 0, + CPU_LOAD_DOWN = 1, + CPU_LOAD_RESET = 2, + CPU_LOAD_RESUME = 3, +} diff --git a/power/aidl/android/hardware/power/IPowerHintSession.aidl b/power/aidl/android/hardware/power/IPowerHintSession.aidl index c289448855..4ca9c54c7c 100644 --- a/power/aidl/android/hardware/power/IPowerHintSession.aidl +++ b/power/aidl/android/hardware/power/IPowerHintSession.aidl @@ -16,6 +16,7 @@ package android.hardware.power; +import android.hardware.power.SessionHint; import android.hardware.power.WorkDuration; @VintfStability @@ -56,4 +57,12 @@ oneway interface IPowerHintSession { * Close the session to release resources. */ void close(); + + /** + * Gives information to the PowerHintSession about upcoming or unexpected + * changes in load to supplement the normal updateTarget/reportActual cycle. + * + * @param hint The hint to provide to the PowerHintSession + */ + void sendHint(SessionHint hint); } diff --git a/power/aidl/android/hardware/power/SessionHint.aidl b/power/aidl/android/hardware/power/SessionHint.aidl new file mode 100644 index 0000000000..6a95035d35 --- /dev/null +++ b/power/aidl/android/hardware/power/SessionHint.aidl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 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. + */ + +package android.hardware.power; + +@VintfStability +@Backing(type="int") +enum SessionHint { + /** + * This hint indicates an increase in CPU workload intensity. It means that + * this hint session needs extra CPU resources to meet the target duration. + * This hint must be sent before reporting the actual duration to the session. + */ + CPU_LOAD_UP = 0, + /** + * This hint indicates a decrease in CPU workload intensity. It means that + * this hint session can reduce CPU resources and still meet the target duration. + */ + CPU_LOAD_DOWN = 1, + /* + * This hint indicates an upcoming CPU workload that is completely changed and + * unknown. It means that the hint session should reset CPU resources to a known + * baseline to prepare for an arbitrary load, and must wake up if inactive. + */ + CPU_LOAD_RESET = 2, + /* + * This hint indicates that the most recent CPU workload is resuming after a + * period of inactivity. It means that the hint session should allocate similar + * CPU resources to what was used previously, and must wake up if inactive. + */ + CPU_LOAD_RESUME = 3, + +} diff --git a/power/aidl/default/Android.bp b/power/aidl/default/Android.bp index 223b9d5e6b..d1257f336a 100644 --- a/power/aidl/default/Android.bp +++ b/power/aidl/default/Android.bp @@ -30,7 +30,7 @@ cc_binary { shared_libs: [ "libbase", "libbinder_ndk", - "android.hardware.power-V3-ndk", + "android.hardware.power-V4-ndk", ], srcs: [ "main.cpp", diff --git a/power/aidl/default/power-default.xml b/power/aidl/default/power-default.xml index 927ba22dbf..f5dd6b957c 100644 --- a/power/aidl/default/power-default.xml +++ b/power/aidl/default/power-default.xml @@ -1,7 +1,7 @@ android.hardware.power - 3 + 4 IPower/default diff --git a/power/aidl/vts/Android.bp b/power/aidl/vts/Android.bp index ea398ac6b2..d5cc2b64af 100644 --- a/power/aidl/vts/Android.bp +++ b/power/aidl/vts/Android.bp @@ -32,7 +32,7 @@ cc_test { "libbinder_ndk", ], static_libs: [ - "android.hardware.power-V3-ndk", + "android.hardware.power-V4-ndk", ], test_suites: [ "vts", diff --git a/power/aidl/vts/VtsHalPowerTargetTest.cpp b/power/aidl/vts/VtsHalPowerTargetTest.cpp index 2cfa04ada9..dcf075f82f 100644 --- a/power/aidl/vts/VtsHalPowerTargetTest.cpp +++ b/power/aidl/vts/VtsHalPowerTargetTest.cpp @@ -34,12 +34,16 @@ using android::hardware::power::Boost; using android::hardware::power::IPower; using android::hardware::power::IPowerHintSession; using android::hardware::power::Mode; +using android::hardware::power::SessionHint; using android::hardware::power::WorkDuration; const std::vector kBoosts{ndk::enum_range().begin(), ndk::enum_range().end()}; const std::vector kModes{ndk::enum_range().begin(), ndk::enum_range().end()}; +const std::vector kSessionHints{ndk::enum_range().begin(), + ndk::enum_range().end()}; + const std::vector kInvalidBoosts = { static_cast(static_cast(kBoosts.front()) - 1), static_cast(static_cast(kBoosts.back()) + 1), @@ -50,6 +54,11 @@ const std::vector kInvalidModes = { static_cast(static_cast(kModes.back()) + 1), }; +const std::vector kInvalidSessionHints = { + static_cast(static_cast(kSessionHints.front()) - 1), + static_cast(static_cast(kSessionHints.back()) + 1), +}; + class DurationWrapper : public WorkDuration { public: DurationWrapper(int64_t dur, int64_t time) { @@ -175,6 +184,7 @@ TEST_P(PowerAidl, createAndCloseHintSession) { ASSERT_TRUE(session->close().isOk()); session.reset(); } + TEST_P(PowerAidl, createHintSessionFailed) { std::shared_ptr session; auto status = power->createHintSession(getpid(), getuid(), kEmptyTids, 16666666L, &session); @@ -198,6 +208,21 @@ TEST_P(PowerAidl, updateAndReportDurations) { ASSERT_TRUE(session->reportActualWorkDuration(kDurations).isOk()); } +TEST_P(PowerAidl, sendSessionHint) { + std::shared_ptr session; + auto status = power->createHintSession(getpid(), getuid(), kSelfTids, 16666666L, &session); + if (!status.isOk()) { + EXPECT_TRUE(isUnknownOrUnsupported(status)); + return; + } + for (const auto& sessionHint : kSessionHints) { + ASSERT_TRUE(session->sendHint(sessionHint).isOk()); + } + for (const auto& sessionHint : kInvalidSessionHints) { + ASSERT_TRUE(session->sendHint(sessionHint).isOk()); + } +} + // FIXED_PERFORMANCE mode is required for all devices which ship on Android 11 // or later TEST_P(PowerAidl, hasFixedPerformance) {