libbinder_ndk: ScopedAResource, support move op=
Bug: 141828236
Test: use in vibrator HAL implementation
Change-Id: Ie572e30be3e69f647ad4d2117aa201bb2af749ed
diff --git a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h
index 8f37c5e..946ccb7 100644
--- a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h
+++ b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h
@@ -159,13 +159,17 @@
*/
T* getR() { return &mT; }
- // copy-constructing, or move/copy assignment is disallowed
+ // copy-constructing/assignment is disallowed
ScopedAResource(const ScopedAResource&) = delete;
ScopedAResource& operator=(const ScopedAResource&) = delete;
- ScopedAResource& operator=(ScopedAResource&&) = delete;
- // move-constructing is okay
+ // move-constructing/assignment is okay
ScopedAResource(ScopedAResource&& other) : mT(std::move(other.mT)) { other.mT = DEFAULT; }
+ ScopedAResource& operator=(ScopedAResource&& other) {
+ set(other.mT);
+ other.mT = DEFAULT;
+ return *this;
+ }
private:
T mT;
@@ -197,6 +201,7 @@
explicit ScopedAStatus(AStatus* a = nullptr) : ScopedAResource(a) {}
~ScopedAStatus() {}
ScopedAStatus(ScopedAStatus&&) = default;
+ ScopedAStatus& operator=(ScopedAStatus&&) = default;
/**
* See AStatus_isOk.