From 365b75f1572ae951054564afbf1f028691ac19e5 Mon Sep 17 00:00:00 2001 From: Tri Vo Date: Fri, 21 Sep 2018 15:19:16 -0700 Subject: [PATCH] Passing partial vs full wake lock info for ARC++ We pass an enum to acquireWakeLock(), symmetric to how it's done in libpower interface. The screen could be managed above (android) or below (ARC++) this HAL depending on the device, so we don't mandate that full wake locks keep the screen alive. Only requirement is that all wake locks block system suspend. Bug: 115947180 Test: SystemSuspendV1_0UnitTest Change-Id: I92c65371852ffb2f71f5d529b7020d256cb1ba76 --- suspend/1.0/ISystemSuspend.hal | 4 +++- suspend/1.0/default/SystemSuspend.cpp | 3 ++- suspend/1.0/default/SystemSuspend.h | 2 +- suspend/1.0/default/SystemSuspendUnitTest.cpp | 7 +++++-- suspend/1.0/types.hal | 29 +++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 suspend/1.0/types.hal diff --git a/suspend/1.0/ISystemSuspend.hal b/suspend/1.0/ISystemSuspend.hal index 344aa51..6c24c64 100644 --- a/suspend/1.0/ISystemSuspend.hal +++ b/suspend/1.0/ISystemSuspend.hal @@ -42,10 +42,12 @@ interface ISystemSuspend { * device from suspending. This method must be able to be called * independently of enableAutosuspend(). * + * @param type type of the requested wake lock. * @param debugName debug string attached to the acquired IWakeLock. Wake * lock names are not necessarily unique. * * @return lock the interface for the created wake lock. */ - acquireWakeLock(string debugName) generates (IWakeLock lock); + acquireWakeLock(WakeLockType type, string debugName) + generates (IWakeLock lock); }; diff --git a/suspend/1.0/default/SystemSuspend.cpp b/suspend/1.0/default/SystemSuspend.cpp index bf22f12..bffc0e3 100644 --- a/suspend/1.0/default/SystemSuspend.cpp +++ b/suspend/1.0/default/SystemSuspend.cpp @@ -92,7 +92,8 @@ Return SystemSuspend::enableAutosuspend() { return true; } -Return> SystemSuspend::acquireWakeLock(const hidl_string& name) { +Return> SystemSuspend::acquireWakeLock(WakeLockType /* type */, + const hidl_string& name) { IWakeLock* wl = new WakeLock{this}; { auto l = std::lock_guard(mStatsLock); diff --git a/suspend/1.0/default/SystemSuspend.h b/suspend/1.0/default/SystemSuspend.h index fc397fc..ac799e9 100644 --- a/suspend/1.0/default/SystemSuspend.h +++ b/suspend/1.0/default/SystemSuspend.h @@ -64,7 +64,7 @@ class SystemSuspend : public ISystemSuspend, public hidl_death_recipient { public: SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd); Return enableAutosuspend() override; - Return> acquireWakeLock(const hidl_string& name) override; + Return> acquireWakeLock(WakeLockType type, const hidl_string& name) override; Return registerCallback(const sp& cb) override; Return debug(const hidl_handle& handle, const hidl_vec& options) override; void serviceDied(uint64_t /* cookie */, const wp& service); diff --git a/suspend/1.0/default/SystemSuspendUnitTest.cpp b/suspend/1.0/default/SystemSuspendUnitTest.cpp index d7055d1..3f46a3e 100644 --- a/suspend/1.0/default/SystemSuspendUnitTest.cpp +++ b/suspend/1.0/default/SystemSuspendUnitTest.cpp @@ -49,6 +49,7 @@ using android::system::suspend::V1_0::ISystemSuspendCallback; using android::system::suspend::V1_0::IWakeLock; using android::system::suspend::V1_0::readFd; using android::system::suspend::V1_0::SystemSuspend; +using android::system::suspend::V1_0::WakeLockType; namespace android { @@ -131,7 +132,9 @@ class SystemSuspendTest : public ::testing::Test { bool isSystemSuspendBlocked() { return isReadBlocked(stateFd); } - sp acquireWakeLock() { return suspendService->acquireWakeLock("TestLock"); } + sp acquireWakeLock() { + return suspendService->acquireWakeLock(WakeLockType::PARTIAL, "TestLock"); + } SystemSuspendStats getDebugDump() { // Index 0 corresponds to the read end of the pipe; 1 to the write end. @@ -247,7 +250,7 @@ TEST_F(SystemSuspendTest, CleanupOnAbort) { // Test that debug dump has correct information about acquired WakeLocks. TEST_F(SystemSuspendTest, DebugDump) { { - sp wl = suspendService->acquireWakeLock("TestLock"); + sp wl = acquireWakeLock(); SystemSuspendStats debugDump = getDebugDump(); ASSERT_EQ(debugDump.wake_lock_stats().size(), 1); ASSERT_EQ(debugDump.wake_lock_stats().begin()->second.name(), "TestLock"); diff --git a/suspend/1.0/types.hal b/suspend/1.0/types.hal new file mode 100644 index 0000000..10f7cc4 --- /dev/null +++ b/suspend/1.0/types.hal @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2018 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.system.suspend@1.0; + +/** + * Blocking CPU suspend is the only constraint that must be respected by all + * wake lock types. E.g. a request for a full wake lock must block CPU suspend, + * but not necessarily keep the screen alive. + */ +enum WakeLockType : uint32_t { + /* CPU stays on. */ + PARTIAL, + /* CPU and the screen stay on. */ + FULL +}; -- 2.11.0