system/hardware/interfaces
Revisão | 1f00dd48f696e86925a47da7a9f29b0e65d2fe31 (tree) |
---|---|
Hora | 2018-09-06 14:12:26 |
Autor | Tri Vo <trong@goog...> |
Commiter | android-build-merger |
Add IWakeLock::release() method.
am: d502490bac
Change-Id: Id5e96044930c08c01589afdf1d213c98f39efb92
@@ -18,6 +18,14 @@ package android.system.suspend@1.0; | ||
18 | 18 | |
19 | 19 | /** |
20 | 20 | * 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(). | |
22 | 23 | */ |
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 | +}; |
@@ -57,13 +57,24 @@ static inline int getCallingPid() { | ||
57 | 57 | return IPCThreadState::self()->getCallingPid(); |
58 | 58 | } |
59 | 59 | |
60 | -WakeLock::WakeLock(SystemSuspend* systemSuspend) : mSystemSuspend(systemSuspend) { | |
60 | +WakeLock::WakeLock(SystemSuspend* systemSuspend) : mReleased(), mSystemSuspend(systemSuspend) { | |
61 | 61 | mSystemSuspend->incSuspendCounter(); |
62 | 62 | } |
63 | 63 | |
64 | 64 | 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 | + }); | |
67 | 78 | } |
68 | 79 | |
69 | 80 | SystemSuspend::SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd) |
@@ -45,7 +45,12 @@ class WakeLock : public IWakeLock { | ||
45 | 45 | WakeLock(SystemSuspend* systemSuspend); |
46 | 46 | ~WakeLock(); |
47 | 47 | |
48 | + Return<void> release(); | |
49 | + | |
48 | 50 | private: |
51 | + inline void releaseOnce(); | |
52 | + std::once_flag mReleased; | |
53 | + | |
49 | 54 | SystemSuspend* mSystemSuspend; |
50 | 55 | }; |
51 | 56 |
@@ -183,6 +183,16 @@ TEST_F(SystemSuspendTest, WakeLockDestructor) { | ||
183 | 183 | ASSERT_FALSE(isSystemSuspendBlocked()); |
184 | 184 | } |
185 | 185 | |
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 | + | |
186 | 196 | // Tests that multiple WakeLocks correctly block SystemSuspend HAL. |
187 | 197 | TEST_F(SystemSuspendTest, MultipleWakeLocks) { |
188 | 198 | { |
@@ -248,7 +258,9 @@ TEST_F(SystemSuspendTest, WakeLockStressTest) { | ||
248 | 258 | for (int i = 0; i < numThreads; i++) { |
249 | 259 | tds[i] = std::thread([this] { |
250 | 260 | 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(); | |
252 | 264 | } |
253 | 265 | }); |
254 | 266 | } |