Move unsolicited vold events to Binder.
Create IVoldListener and move most unsolicited vold events over to
this new interface. The remaining events will be routed through
method-specific listeners instead of a global one.
Move to upstream DISALLOW_COPY_AND_ASSIGN macro.
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.DirectBootHostTest
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Test: cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.storage.cts.StorageManagerTest
Bug: 13758960
Change-Id: Ib9293487db2d525a76b9b9c2e9ac18d98601c6cf
diff --git a/model/VolumeBase.cpp b/model/VolumeBase.cpp
index 3f27d87..b2eff3b 100644
--- a/model/VolumeBase.cpp
+++ b/model/VolumeBase.cpp
@@ -44,7 +44,12 @@
void VolumeBase::setState(State state) {
mState = state;
+#if ENABLE_BINDER
+ auto listener = getListener();
+ if (listener) listener->onVolumeStateChanged(getId(), static_cast<int32_t>(mState));
+#else
notifyEvent(ResponseCode::VolumeStateChanged, StringPrintf("%d", mState));
+#endif
}
status_t VolumeBase::setDiskId(const std::string& diskId) {
@@ -114,7 +119,12 @@
}
mPath = path;
+#if ENABLE_BINDER
+ auto listener = getListener();
+ if (listener) listener->onVolumePathChanged(getId(), mPath);
+#else
notifyEvent(ResponseCode::VolumePathChanged, mPath);
+#endif
return OK;
}
@@ -125,7 +135,12 @@
}
mInternalPath = internalPath;
+#if ENABLE_BINDER
+ auto listener = getListener();
+ if (listener) listener->onVolumeInternalPathChanged(getId(), mInternalPath);
+#else
notifyEvent(ResponseCode::VolumeInternalPathChanged, mInternalPath);
+#endif
return OK;
}
@@ -141,6 +156,14 @@
StringPrintf("%s %s", getId().c_str(), value.c_str()).c_str(), false);
}
+android::sp<android::os::IVoldListener> VolumeBase::getListener() {
+ if (mSilent) {
+ return nullptr;
+ } else {
+ return VolumeManager::Instance()->getListener();
+ }
+}
+
void VolumeBase::addVolume(const std::shared_ptr<VolumeBase>& volume) {
mVolumes.push_back(volume);
}
@@ -163,8 +186,14 @@
mCreated = true;
status_t res = doCreate();
+#if ENABLE_BINDER
+ auto listener = getListener();
+ if (listener) listener->onVolumeCreated(getId(),
+ static_cast<int32_t>(mType), mDiskId, mPartGuid);
+#else
notifyEvent(ResponseCode::VolumeCreated,
StringPrintf("%d \"%s\" \"%s\"", mType, mDiskId.c_str(), mPartGuid.c_str()));
+#endif
setState(State::kUnmounted);
return res;
}
@@ -183,7 +212,12 @@
setState(State::kRemoved);
}
+#if ENABLE_BINDER
+ auto listener = getListener();
+ if (listener) listener->onVolumeDestroyed(getId());
+#else
notifyEvent(ResponseCode::VolumeDestroyed);
+#endif
status_t res = doDestroy();
mCreated = false;
return res;