[frameworks] update with incfs.h

BUG: 150470163
Test: atest PackageManagerShellCommandIncrementalTest
Change-Id: I32ac2576c7468e04ada61e82ca778f762ce2559f
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index ae27c7a..25da8fe 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -157,7 +157,6 @@
 
 IncrementalService::IncFsMount::~IncFsMount() {
     incrementalService.mDataLoaderManager->destroyDataLoader(mountId);
-    control.reset();
     LOG(INFO) << "Unmounting and cleaning up mount " << mountId << " with root '" << root << '\'';
     for (auto&& [target, _] : bindPoints) {
         LOG(INFO) << "\tbind: " << target;
@@ -424,9 +423,10 @@
             LOG(ERROR) << "Vold::mountIncFs() returned invalid control parcel.";
             return kInvalidStorageId;
         }
-        control.cmd = controlParcel.cmd.release().release();
-        control.pendingReads = controlParcel.pendingReads.release().release();
-        control.logs = controlParcel.log.release().release();
+        int cmd = controlParcel.cmd.release().release();
+        int pendingReads = controlParcel.pendingReads.release().release();
+        int logs = controlParcel.log.release().release();
+        control = mIncFs->createControl(cmd, pendingReads, logs);
     }
 
     std::unique_lock l(mLock);
@@ -965,16 +965,17 @@
     auto mountTarget = path::join(root, constants().mount);
     const auto backing = path::join(root, constants().backing);
 
-    IncFsMount::Control control;
     IncrementalFileSystemControlParcel controlParcel;
     auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel);
     if (!status.isOk()) {
         LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
         return false;
     }
-    control.cmd = controlParcel.cmd.release().release();
-    control.pendingReads = controlParcel.pendingReads.release().release();
-    control.logs = controlParcel.log.release().release();
+
+    int cmd = controlParcel.cmd.release().release();
+    int pendingReads = controlParcel.pendingReads.release().release();
+    int logs = controlParcel.log.release().release();
+    IncFsMount::Control control = mIncFs->createControl(cmd, pendingReads, logs);
 
     auto ifs = std::make_shared<IncFsMount>(std::string(root), -1, std::move(control), *this);
 
@@ -1084,10 +1085,10 @@
     }
     FileSystemControlParcel fsControlParcel;
     fsControlParcel.incremental = aidl::make_nullable<IncrementalFileSystemControlParcel>();
-    fsControlParcel.incremental->cmd.reset(base::unique_fd(::dup(ifs.control.cmd)));
+    fsControlParcel.incremental->cmd.reset(base::unique_fd(::dup(ifs.control.cmd())));
     fsControlParcel.incremental->pendingReads.reset(
-            base::unique_fd(::dup(ifs.control.pendingReads)));
-    fsControlParcel.incremental->log.reset(base::unique_fd(::dup(ifs.control.logs)));
+            base::unique_fd(::dup(ifs.control.pendingReads())));
+    fsControlParcel.incremental->log.reset(base::unique_fd(::dup(ifs.control.logs())));
     sp<IncrementalDataLoaderListener> listener =
             new IncrementalDataLoaderListener(*this,
                                               externalListener ? *externalListener
diff --git a/services/incremental/ServiceWrappers.h b/services/incremental/ServiceWrappers.h
index 5349ebf..c70a47d 100644
--- a/services/incremental/ServiceWrappers.h
+++ b/services/incremental/ServiceWrappers.h
@@ -66,15 +66,17 @@
 class IncFsWrapper {
 public:
     virtual ~IncFsWrapper() = default;
-    virtual ErrorCode makeFile(Control control, std::string_view path, int mode, FileId id,
+    virtual Control createControl(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs) const = 0;
+    virtual ErrorCode makeFile(const Control& control, std::string_view path, int mode, FileId id,
                                NewFileParams params) const = 0;
-    virtual ErrorCode makeDir(Control control, std::string_view path, int mode) const = 0;
-    virtual RawMetadata getMetadata(Control control, FileId fileid) const = 0;
-    virtual RawMetadata getMetadata(Control control, std::string_view path) const = 0;
-    virtual FileId getFileId(Control control, std::string_view path) const = 0;
-    virtual ErrorCode link(Control control, std::string_view from, std::string_view to) const = 0;
-    virtual ErrorCode unlink(Control control, std::string_view path) const = 0;
-    virtual base::unique_fd openWrite(Control control, FileId id) const = 0;
+    virtual ErrorCode makeDir(const Control& control, std::string_view path, int mode) const = 0;
+    virtual RawMetadata getMetadata(const Control& control, FileId fileid) const = 0;
+    virtual RawMetadata getMetadata(const Control& control, std::string_view path) const = 0;
+    virtual FileId getFileId(const Control& control, std::string_view path) const = 0;
+    virtual ErrorCode link(const Control& control, std::string_view from,
+                           std::string_view to) const = 0;
+    virtual ErrorCode unlink(const Control& control, std::string_view path) const = 0;
+    virtual base::unique_fd openWrite(const Control& control, FileId id) const = 0;
     virtual ErrorCode writeBlocks(Span<const DataBlock> blocks) const = 0;
 };
 
@@ -149,29 +151,33 @@
 public:
     RealIncFs() = default;
     ~RealIncFs() = default;
-    ErrorCode makeFile(Control control, std::string_view path, int mode, FileId id,
+    Control createControl(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs) const override {
+        return incfs::createControl(cmd, pendingReads, logs);
+    }
+    ErrorCode makeFile(const Control& control, std::string_view path, int mode, FileId id,
                        NewFileParams params) const override {
         return incfs::makeFile(control, path, mode, id, params);
     }
-    ErrorCode makeDir(Control control, std::string_view path, int mode) const override {
+    ErrorCode makeDir(const Control& control, std::string_view path, int mode) const override {
         return incfs::makeDir(control, path, mode);
     }
-    RawMetadata getMetadata(Control control, FileId fileid) const override {
+    RawMetadata getMetadata(const Control& control, FileId fileid) const override {
         return incfs::getMetadata(control, fileid);
     }
-    RawMetadata getMetadata(Control control, std::string_view path) const override {
+    RawMetadata getMetadata(const Control& control, std::string_view path) const override {
         return incfs::getMetadata(control, path);
     }
-    FileId getFileId(Control control, std::string_view path) const override {
+    FileId getFileId(const Control& control, std::string_view path) const override {
         return incfs::getFileId(control, path);
     }
-    ErrorCode link(Control control, std::string_view from, std::string_view to) const override {
+    ErrorCode link(const Control& control, std::string_view from,
+                   std::string_view to) const override {
         return incfs::link(control, from, to);
     }
-    ErrorCode unlink(Control control, std::string_view path) const override {
+    ErrorCode unlink(const Control& control, std::string_view path) const override {
         return incfs::unlink(control, path);
     }
-    base::unique_fd openWrite(Control control, FileId id) const override {
+    base::unique_fd openWrite(const Control& control, FileId id) const override {
         return base::unique_fd{incfs::openWrite(control, id)};
     }
     ErrorCode writeBlocks(Span<const DataBlock> blocks) const override {
diff --git a/services/incremental/test/IncrementalServiceTest.cpp b/services/incremental/test/IncrementalServiceTest.cpp
index f5b88d9..c4b4d17 100644
--- a/services/incremental/test/IncrementalServiceTest.cpp
+++ b/services/incremental/test/IncrementalServiceTest.cpp
@@ -164,22 +164,23 @@
 
 class MockIncFs : public IncFsWrapper {
 public:
+    MOCK_CONST_METHOD3(createControl, Control(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs));
     MOCK_CONST_METHOD5(makeFile,
-                       ErrorCode(Control control, std::string_view path, int mode, FileId id,
+                       ErrorCode(const Control& control, std::string_view path, int mode, FileId id,
                                  NewFileParams params));
-    MOCK_CONST_METHOD3(makeDir, ErrorCode(Control control, std::string_view path, int mode));
-    MOCK_CONST_METHOD2(getMetadata, RawMetadata(Control control, FileId fileid));
-    MOCK_CONST_METHOD2(getMetadata, RawMetadata(Control control, std::string_view path));
-    MOCK_CONST_METHOD2(getFileId, FileId(Control control, std::string_view path));
+    MOCK_CONST_METHOD3(makeDir, ErrorCode(const Control& control, std::string_view path, int mode));
+    MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, FileId fileid));
+    MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, std::string_view path));
+    MOCK_CONST_METHOD2(getFileId, FileId(const Control& control, std::string_view path));
     MOCK_CONST_METHOD3(link,
-                       ErrorCode(Control control, std::string_view from, std::string_view to));
-    MOCK_CONST_METHOD2(unlink, ErrorCode(Control control, std::string_view path));
-    MOCK_CONST_METHOD2(openWrite, base::unique_fd(Control control, FileId id));
+                       ErrorCode(const Control& control, std::string_view from, std::string_view to));
+    MOCK_CONST_METHOD2(unlink, ErrorCode(const Control& control, std::string_view path));
+    MOCK_CONST_METHOD2(openWrite, base::unique_fd(const Control& control, FileId id));
     MOCK_CONST_METHOD1(writeBlocks, ErrorCode(Span<const DataBlock> blocks));
 
     void makeFileFails() { ON_CALL(*this, makeFile(_, _, _, _, _)).WillByDefault(Return(-1)); }
     void makeFileSuccess() { ON_CALL(*this, makeFile(_, _, _, _, _)).WillByDefault(Return(0)); }
-    RawMetadata getMountInfoMetadata(Control control, std::string_view path) {
+    RawMetadata getMountInfoMetadata(const Control& control, std::string_view path) {
         metadata::Mount m;
         m.mutable_storage()->set_id(100);
         m.mutable_loader()->set_package_name("com.test");
@@ -189,13 +190,13 @@
         m.mutable_loader()->release_package_name();
         return {metadata.begin(), metadata.end()};
     }
-    RawMetadata getStorageMetadata(Control control, std::string_view path) {
+    RawMetadata getStorageMetadata(const Control& control, std::string_view path) {
         metadata::Storage st;
         st.set_id(100);
         auto metadata = st.SerializeAsString();
         return {metadata.begin(), metadata.end()};
     }
-    RawMetadata getBindPointMetadata(Control control, std::string_view path) {
+    RawMetadata getBindPointMetadata(const Control& control, std::string_view path) {
         metadata::BindPoint bp;
         std::string destPath = "dest";
         std::string srcPath = "src";