Merge "[incremental] use vold to mount/unmount IncrementalFileSystem"
am: 6bdfb77d8b

Change-Id: Ic9abd7f6e502e9f051effa998e3fbd40746d57d7
diff --git a/Android.bp b/Android.bp
index 452746c..8d88e5f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -54,6 +54,7 @@
         "libf2fs_sparseblock",
         "libhardware",
         "libhardware_legacy",
+        "libincfs",
         "libhidlbase",
         "libkeymaster4support",
         "libkeyutils",
@@ -78,9 +79,15 @@
     ],
     aidl: {
         local_include_dirs: ["binder"],
-        include_dirs: ["frameworks/native/aidl/binder"],
+        include_dirs: [
+            "frameworks/native/aidl/binder",
+            "frameworks/base/core/java/android/os/incremental",
+        ],
         export_aidl_headers: true,
     },
+    whole_static_libs: [
+        "libincremental_aidl-cpp",
+    ],
 }
 
 cc_library_headers {
diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp
index f17f59f..cc32820 100644
--- a/VoldNativeService.cpp
+++ b/VoldNativeService.cpp
@@ -28,6 +28,7 @@
 #include "FsCrypt.h"
 #include "MetadataCrypt.h"
 #include "cryptfs.h"
+#include "incfs_ndk.h"
 
 #include <fstream>
 #include <thread>
@@ -915,5 +916,38 @@
     return ok();
 }
 
+binder::Status VoldNativeService::incFsVersion(int32_t* _aidl_return) {
+    *_aidl_return = IncFs_Version();
+    return ok();
+}
+
+binder::Status VoldNativeService::mountIncFs(
+        const std::string& imagePath, const std::string& targetDir, int32_t flags,
+        ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
+    auto result = IncFs_Mount(imagePath.c_str(), targetDir.c_str(), flags,
+                              INCFS_DEFAULT_READ_TIMEOUT_MS, 0777);
+    if (result.cmdFd < 0) {
+        return translate(result.cmdFd);
+    }
+    LOG(INFO) << "VoldNativeService::mountIncFs: everything is fine! " << result.cmdFd << "/"
+              << result.logFd;
+    using ParcelFileDescriptor = ::android::os::ParcelFileDescriptor;
+    using unique_fd = ::android::base::unique_fd;
+    _aidl_return->cmd = std::make_unique<ParcelFileDescriptor>(unique_fd(result.cmdFd));
+    if (result.logFd >= 0) {
+        _aidl_return->log = std::make_unique<ParcelFileDescriptor>(unique_fd(result.logFd));
+    }
+    return ok();
+}
+
+binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
+    return translate(IncFs_Unmount(dir.c_str()));
+}
+
+binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
+                                            const std::string& targetDir) {
+    return translate(IncFs_BindMount(sourceDir.c_str(), targetDir.c_str()));
+}
+
 }  // namespace vold
 }  // namespace android
diff --git a/VoldNativeService.h b/VoldNativeService.h
index 13137c5..0718263 100644
--- a/VoldNativeService.h
+++ b/VoldNativeService.h
@@ -141,6 +141,13 @@
     binder::Status supportsBlockCheckpoint(bool* _aidl_return);
     binder::Status supportsFileCheckpoint(bool* _aidl_return);
     binder::Status resetCheckpoint();
+
+    binder::Status incFsVersion(int32_t* _aidl_return) override;
+    binder::Status mountIncFs(
+            const std::string& imagePath, const std::string& targetDir, int32_t flags,
+            ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) override;
+    binder::Status unmountIncFs(const std::string& dir) override;
+    binder::Status bindMount(const std::string& sourceDir, const std::string& targetDir) override;
 };
 
 }  // namespace vold
diff --git a/binder/android/os/IVold.aidl b/binder/android/os/IVold.aidl
index 8e5c53d..681e9dc 100644
--- a/binder/android/os/IVold.aidl
+++ b/binder/android/os/IVold.aidl
@@ -16,6 +16,7 @@
 
 package android.os;
 
+import android.os.incremental.IncrementalFileSystemControlParcel;
 import android.os.IVoldListener;
 import android.os.IVoldTaskListener;
 
@@ -125,6 +126,11 @@
 
     FileDescriptor openAppFuseFile(int uid, int mountId, int fileId, int flags);
 
+    int incFsVersion();
+    IncrementalFileSystemControlParcel mountIncFs(@utf8InCpp String imagePath, @utf8InCpp String targetDir, int flags);
+    void unmountIncFs(@utf8InCpp String dir);
+    void bindMount(@utf8InCpp String sourceDir, @utf8InCpp String targetDir);
+
     const int ENCRYPTION_FLAG_NO_UI = 4;
 
     const int ENCRYPTION_STATE_NONE = 1;