OSDN Git Service

Passing partial vs full wake lock info for ARC++
authorTri Vo <trong@google.com>
Fri, 21 Sep 2018 22:19:16 +0000 (15:19 -0700)
committerTri Vo <trong@google.com>
Tue, 25 Sep 2018 17:54:25 +0000 (10:54 -0700)
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
suspend/1.0/default/SystemSuspend.cpp
suspend/1.0/default/SystemSuspend.h
suspend/1.0/default/SystemSuspendUnitTest.cpp
suspend/1.0/types.hal [new file with mode: 0644]

index 344aa51..6c24c64 100644 (file)
@@ -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);
 };
index bf22f12..bffc0e3 100644 (file)
@@ -92,7 +92,8 @@ Return<bool> SystemSuspend::enableAutosuspend() {
     return true;
 }
 
-Return<sp<IWakeLock>> SystemSuspend::acquireWakeLock(const hidl_string& name) {
+Return<sp<IWakeLock>> SystemSuspend::acquireWakeLock(WakeLockType /* type */,
+                                                     const hidl_string& name) {
     IWakeLock* wl = new WakeLock{this};
     {
         auto l = std::lock_guard(mStatsLock);
index fc397fc..ac799e9 100644 (file)
@@ -64,7 +64,7 @@ class SystemSuspend : public ISystemSuspend, public hidl_death_recipient {
    public:
     SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd);
     Return<bool> enableAutosuspend() override;
-    Return<sp<IWakeLock>> acquireWakeLock(const hidl_string& name) override;
+    Return<sp<IWakeLock>> acquireWakeLock(WakeLockType type, const hidl_string& name) override;
     Return<bool> registerCallback(const sp<ISystemSuspendCallback>& cb) override;
     Return<void> debug(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override;
     void serviceDied(uint64_t /* cookie */, const wp<IBase>& service);
index d7055d1..3f46a3e 100644 (file)
@@ -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<IWakeLock> acquireWakeLock() { return suspendService->acquireWakeLock("TestLock"); }
+    sp<IWakeLock> 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<IWakeLock> wl = suspendService->acquireWakeLock("TestLock");
+        sp<IWakeLock> 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 (file)
index 0000000..10f7cc4
--- /dev/null
@@ -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
+};