MH2 | Implement ScopeWakelock ctor and dtor
Put the ScopedWakelock class into its own header and its implementation
into its own cpp. Implement the refcounting of the wakelocks. However,
do not incorporate the wakelock handling into post events in halproxy
yet.
Bug: 136511617
Test: No new tests yet. Will add more in a later patchset once more
fleshed out and integrated with postEvents.
Change-Id: I0815c6a6659ec5933b799294956595b11e7bf1b3
diff --git a/sensors/2.0/multihal/ScopedWakelock.cpp b/sensors/2.0/multihal/ScopedWakelock.cpp
new file mode 100644
index 0000000..0430fa3
--- /dev/null
+++ b/sensors/2.0/multihal/ScopedWakelock.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include "ScopedWakelock.h"
+
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace V2_0 {
+namespace implementation {
+
+ScopedWakelock::ScopedWakelock(IScopedWakelockRefCounter* refCounter, bool locked)
+ : mRefCounter(refCounter), mLocked(locked) {
+ // TODO: Move this implementation into HalProxy object instead
+ if (mLocked) {
+ mRefCounter->incrementRefCountAndMaybeAcquireWakelock();
+ }
+}
+
+ScopedWakelock::~ScopedWakelock() {
+ // TODO: Move this implementation into HalProxy object instead
+ if (mLocked) {
+ mRefCounter->decrementRefCountAndMaybeReleaseWakelock();
+ }
+}
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace sensors
+} // namespace hardware
+} // namespace android
\ No newline at end of file