Expose ImageManager::RemoveAllImages via binder.
Bug: N/A
Test: manual test
Change-Id: I9429ed49f57caab054c6c3418d4da351a21a8131
diff --git a/aidl/android/gsi/IImageService.aidl b/aidl/android/gsi/IImageService.aidl
index 1195c00..db348ba 100644
--- a/aidl/android/gsi/IImageService.aidl
+++ b/aidl/android/gsi/IImageService.aidl
@@ -98,4 +98,9 @@
* @return True on success, false otherwise.
*/
void zeroFillNewImage(@utf8InCpp String name, long bytes);
+
+ /**
+ * Find and remove all images in the containing folder of this instance.
+ */
+ void removeAllImages();
}
diff --git a/gsi_service.cpp b/gsi_service.cpp
index dbf0ea6..2916c74 100644
--- a/gsi_service.cpp
+++ b/gsi_service.cpp
@@ -359,6 +359,7 @@
binder::Status backingImageExists(const std::string& name, bool* _aidl_return) override;
binder::Status isImageMapped(const std::string& name, bool* _aidl_return) override;
binder::Status zeroFillNewImage(const std::string& name, int64_t bytes) override;
+ binder::Status removeAllImages() override;
private:
bool CheckUid();
@@ -454,6 +455,16 @@
return binder::Status::ok();
}
+binder::Status ImageService::removeAllImages() {
+ if (!CheckUid()) return UidSecurityError();
+
+ std::lock_guard<std::mutex> guard(parent_->lock());
+ if (!impl_->RemoveAllImages()) {
+ return BinderError("Failed to remove all images");
+ }
+ return binder::Status::ok();
+}
+
bool ImageService::CheckUid() {
return uid_ == IPCThreadState::self()->getCallingUid();
}
diff --git a/libfiemap/binder.cpp b/libfiemap/binder.cpp
index dcb887a..49779f4 100644
--- a/libfiemap/binder.cpp
+++ b/libfiemap/binder.cpp
@@ -42,6 +42,7 @@
bool MapImageWithDeviceMapper(const IPartitionOpener& opener, const std::string& name,
std::string* dev) override;
bool ZeroFillNewImage(const std::string& name, uint64_t bytes) override;
+ bool RemoveAllImages() override;
std::vector<std::string> GetAllBackingImages() override;
@@ -152,6 +153,16 @@
return true;
}
+bool ImageManagerBinder::RemoveAllImages() {
+ auto status = manager_->removeAllImages();
+ if (!status.isOk()) {
+ LOG(ERROR) << __PRETTY_FUNCTION__
+ << " binder returned: " << status.exceptionMessage().string();
+ return false;
+ }
+ return true;
+}
+
static android::sp<IGsid> AcquireIGsid(const std::chrono::milliseconds& timeout_ms) {
if (android::base::GetProperty("init.svc.gsid", "") != "running") {
if (!android::base::SetProperty("ctl.start", "gsid") ||
diff --git a/libfiemap/include/libfiemap/image_manager.h b/libfiemap/include/libfiemap/image_manager.h
index efbe9bd..5ff4628 100644
--- a/libfiemap/include/libfiemap/image_manager.h
+++ b/libfiemap/include/libfiemap/image_manager.h
@@ -91,6 +91,9 @@
// whole file if filled with zeros.
virtual bool ZeroFillNewImage(const std::string& name, uint64_t bytes) = 0;
+ // Find and remove all images and metadata for this manager.
+ virtual bool RemoveAllImages() = 0;
+
virtual bool UnmapImageIfExists(const std::string& name);
};
@@ -115,15 +118,13 @@
bool IsImageMapped(const std::string& name) override;
bool MapImageWithDeviceMapper(const IPartitionOpener& opener, const std::string& name,
std::string* dev) override;
+ bool RemoveAllImages() override;
std::vector<std::string> GetAllBackingImages();
// Same as CreateBackingImage, but provides a progress notification.
bool CreateBackingImage(const std::string& name, uint64_t size, int flags,
std::function<bool(uint64_t, uint64_t)>&& on_progress);
- // Find and remove all images and metadata for a given image dir.
- bool RemoveAllImages();
-
// Returns true if the named partition exists. This does not check the
// consistency of the backing image/data file.
bool PartitionExists(const std::string& name);