Add a library to wrap libfiemap differences between recovery and normal AOSP.

libsnapshot has to work both in normal boot and in recovery. Normally,
we want libfiemap to be used through gsid, via binder, to consolidate the
necessary SELinux permissions. However binder is not available in
recovery, so instead we introduce a compile-time abstraction layer.

Recovery should link to libfiemap; otherwise, libfiemap_binder
should be used instead. They both present the same API.

Bug: 134536978
Test: manual test
Change-Id: I60370af2175723141e61f0ee301cad40d2f331c1
diff --git a/gsi_service.cpp b/gsi_service.cpp
index a208c5e..352b2c2 100644
--- a/gsi_service.cpp
+++ b/gsi_service.cpp
@@ -32,7 +32,7 @@
 #include <android-base/logging.h>
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
-#include <android/gsi/BnImageManager.h>
+#include <android/gsi/BnImageService.h>
 #include <android/gsi/IGsiService.h>
 #include <ext4_utils/ext4_utils.h>
 #include <fs_mgr.h>
@@ -396,9 +396,9 @@
     return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(message.c_str()));
 }
 
-class ImageManagerService : public BinderService<ImageManagerService>, public BnImageManager {
+class ImageService : public BinderService<ImageService>, public BnImageService {
   public:
-    ImageManagerService(GsiService* service, std::unique_ptr<ImageManager>&& impl, uid_t uid);
+    ImageService(GsiService* service, std::unique_ptr<ImageManager>&& impl, uid_t uid);
     binder::Status createBackingImage(const std::string& name, int64_t size, int flags) override;
     binder::Status deleteBackingImage(const std::string& name) override;
     binder::Status mapImageDevice(const std::string& name, int32_t timeout_ms,
@@ -415,12 +415,10 @@
     uid_t uid_;
 };
 
-ImageManagerService::ImageManagerService(GsiService* service, std::unique_ptr<ImageManager>&& impl,
-                                         uid_t uid)
+ImageService::ImageService(GsiService* service, std::unique_ptr<ImageManager>&& impl, uid_t uid)
     : service_(service), parent_(service->parent()), impl_(std::move(impl)), uid_(uid) {}
 
-binder::Status ImageManagerService::createBackingImage(const std::string& name, int64_t size,
-                                                       int flags) {
+binder::Status ImageService::createBackingImage(const std::string& name, int64_t size, int flags) {
     if (!CheckUid()) return UidSecurityError();
 
     std::lock_guard<std::mutex> guard(parent_->lock());
@@ -431,7 +429,7 @@
     return binder::Status::ok();
 }
 
-binder::Status ImageManagerService::deleteBackingImage(const std::string& name) {
+binder::Status ImageService::deleteBackingImage(const std::string& name) {
     if (!CheckUid()) return UidSecurityError();
 
     std::lock_guard<std::mutex> guard(parent_->lock());
@@ -442,8 +440,8 @@
     return binder::Status::ok();
 }
 
-binder::Status ImageManagerService::mapImageDevice(const std::string& name, int32_t timeout_ms,
-                                                   MappedImage* mapping) {
+binder::Status ImageService::mapImageDevice(const std::string& name, int32_t timeout_ms,
+                                            MappedImage* mapping) {
     if (!CheckUid()) return UidSecurityError();
 
     std::lock_guard<std::mutex> guard(parent_->lock());
@@ -454,7 +452,7 @@
     return binder::Status::ok();
 }
 
-binder::Status ImageManagerService::unmapImageDevice(const std::string& name) {
+binder::Status ImageService::unmapImageDevice(const std::string& name) {
     if (!CheckUid()) return UidSecurityError();
 
     std::lock_guard<std::mutex> guard(parent_->lock());
@@ -465,8 +463,7 @@
     return binder::Status::ok();
 }
 
-binder::Status ImageManagerService::backingImageExists(const std::string& name,
-                                                       bool* _aidl_return) {
+binder::Status ImageService::backingImageExists(const std::string& name, bool* _aidl_return) {
     if (!CheckUid()) return UidSecurityError();
 
     std::lock_guard<std::mutex> guard(parent_->lock());
@@ -479,8 +476,8 @@
     return uid_ == IPCThreadState::self()->getCallingUid();
 }
 
-binder::Status GsiService::openImageManager(const std::string& prefix,
-                                            android::sp<IImageManager>* _aidl_return) {
+binder::Status GsiService::openImageService(const std::string& prefix,
+                                            android::sp<IImageService>* _aidl_return) {
     static constexpr char kImageMetadataPrefix[] = "/metadata/gsi/";
     static constexpr char kImageDataPrefix[] = "/data/gsi/";
 
@@ -511,7 +508,7 @@
         return BinderError("Unknown error");
     }
 
-    *_aidl_return = new ImageManagerService(this, std::move(impl), uid);
+    *_aidl_return = new ImageService(this, std::move(impl), uid);
     return binder::Status::ok();
 }