• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/hardware/interfaces


Commit MetaInfo

Revision1f00dd48f696e86925a47da7a9f29b0e65d2fe31 (tree)
Time2018-09-06 14:12:26
AuthorTri Vo <trong@goog...>
Commiterandroid-build-merger

Log Message

Add IWakeLock::release() method.
am: d502490bac

Change-Id: Id5e96044930c08c01589afdf1d213c98f39efb92

Change Summary

Incremental Difference

--- a/suspend/1.0/IWakeLock.hal
+++ b/suspend/1.0/IWakeLock.hal
@@ -18,6 +18,14 @@ package android.system.suspend@1.0;
1818
1919 /**
2020 * Allocating an IWakeLock instance must block system suspend. Deallocating an
21- * IWakeLock must initiate system suspend if no other wake lock is allocated.
21+ * IWakeLock must unblock system suspend in a manner equivalent to calling
22+ * IWakeLock::release().
2223 */
23-interface IWakeLock {};
24+interface IWakeLock {
25+ /**
26+ * Releases IWakeLock instance. This method only has effect first time its
27+ * called. Subsequent calls must result in no-ops. If no unreleased wake
28+ * lock is present, system is allowed to suspend.
29+ */
30+ oneway release();
31+};
--- a/suspend/1.0/default/SystemSuspend.cpp
+++ b/suspend/1.0/default/SystemSuspend.cpp
@@ -57,13 +57,24 @@ static inline int getCallingPid() {
5757 return IPCThreadState::self()->getCallingPid();
5858 }
5959
60-WakeLock::WakeLock(SystemSuspend* systemSuspend) : mSystemSuspend(systemSuspend) {
60+WakeLock::WakeLock(SystemSuspend* systemSuspend) : mReleased(), mSystemSuspend(systemSuspend) {
6161 mSystemSuspend->incSuspendCounter();
6262 }
6363
6464 WakeLock::~WakeLock() {
65- mSystemSuspend->decSuspendCounter();
66- mSystemSuspend->deleteWakeLockStatsEntry(reinterpret_cast<uint64_t>(this));
65+ releaseOnce();
66+}
67+
68+Return<void> WakeLock::release() {
69+ releaseOnce();
70+ return Void();
71+}
72+
73+void WakeLock::releaseOnce() {
74+ std::call_once(mReleased, [this]() {
75+ mSystemSuspend->decSuspendCounter();
76+ mSystemSuspend->deleteWakeLockStatsEntry(reinterpret_cast<uint64_t>(this));
77+ });
6778 }
6879
6980 SystemSuspend::SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd)
--- a/suspend/1.0/default/SystemSuspend.h
+++ b/suspend/1.0/default/SystemSuspend.h
@@ -45,7 +45,12 @@ class WakeLock : public IWakeLock {
4545 WakeLock(SystemSuspend* systemSuspend);
4646 ~WakeLock();
4747
48+ Return<void> release();
49+
4850 private:
51+ inline void releaseOnce();
52+ std::once_flag mReleased;
53+
4954 SystemSuspend* mSystemSuspend;
5055 };
5156
--- a/suspend/1.0/default/SystemSuspendUnitTest.cpp
+++ b/suspend/1.0/default/SystemSuspendUnitTest.cpp
@@ -183,6 +183,16 @@ TEST_F(SystemSuspendTest, WakeLockDestructor) {
183183 ASSERT_FALSE(isSystemSuspendBlocked());
184184 }
185185
186+// Tests that upon WakeLock::release() SystemSuspend HAL is unblocked.
187+TEST_F(SystemSuspendTest, WakeLockRelease) {
188+ sp<IWakeLock> wl = acquireWakeLock();
189+ ASSERT_NE(wl, nullptr);
190+ unblockSystemSuspendFromWakeupCount();
191+ ASSERT_TRUE(isSystemSuspendBlocked());
192+ wl->release();
193+ ASSERT_FALSE(isSystemSuspendBlocked());
194+}
195+
186196 // Tests that multiple WakeLocks correctly block SystemSuspend HAL.
187197 TEST_F(SystemSuspendTest, MultipleWakeLocks) {
188198 {
@@ -248,7 +258,9 @@ TEST_F(SystemSuspendTest, WakeLockStressTest) {
248258 for (int i = 0; i < numThreads; i++) {
249259 tds[i] = std::thread([this] {
250260 for (int i = 0; i < numLocks; i++) {
251- sp<IWakeLock> wl = acquireWakeLock();
261+ sp<IWakeLock> wl1 = acquireWakeLock();
262+ sp<IWakeLock> wl2 = acquireWakeLock();
263+ wl2->release();
252264 }
253265 });
254266 }