vold uses health filesystem HAL
to runDevGc(). This fixes a Treble violation.
Bug: 111655771
Test: manual
Change-Id: I53d6db6ffa99e43e281f8086442151692c1826ca
diff --git a/Android.bp b/Android.bp
index 556784f..080c5fe 100644
--- a/Android.bp
+++ b/Android.bp
@@ -139,6 +139,9 @@
],
},
},
+ shared_libs: [
+ "android.hardware.health.filesystem@1.0",
+ ],
}
cc_binary {
@@ -168,6 +171,11 @@
"vold_prepare_subdirs",
"wait_for_keymaster",
],
+
+ shared_libs: [
+ "android.hardware.health.filesystem@1.0",
+ "libhidltransport",
+ ],
}
cc_binary {
diff --git a/IdleMaint.cpp b/IdleMaint.cpp
index 7744024..b4b7746 100644
--- a/IdleMaint.cpp
+++ b/IdleMaint.cpp
@@ -23,11 +23,13 @@
#include <android-base/chrono_utils.h>
#include <android-base/file.h>
-#include <android-base/stringprintf.h>
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+#include <android/hardware/health/filesystem/1.0/IFileSystem.h>
#include <fs_mgr.h>
-#include <private/android_filesystem_config.h>
#include <hardware_legacy/power.h>
+#include <private/android_filesystem_config.h>
#include <dirent.h>
#include <sys/mount.h>
@@ -42,6 +44,11 @@
using android::base::StringPrintf;
using android::base::Timer;
using android::base::WriteStringToFile;
+using android::hardware::Return;
+using android::hardware::Void;
+using android::hardware::health::filesystem::V1_0::IFileSystem;
+using android::hardware::health::filesystem::V1_0::IGarbageCollectCallback;
+using android::hardware::health::filesystem::V1_0::Result;
namespace android {
namespace vold {
@@ -255,7 +262,7 @@
return android::OK;
}
-static void runDevGc(void) {
+static void runDevGcFstab(void) {
std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
fs_mgr_free_fstab);
struct fstab_rec *rec = NULL;
@@ -282,7 +289,7 @@
PLOG(WARNING) << "Reading manual_gc failed in " << path;
break;
}
-
+ require = android::base::Trim(require);
if (require == "" || require == "off" || require == "disabled") {
LOG(DEBUG) << "No more to do Dev GC";
break;
@@ -307,6 +314,57 @@
return;
}
+class GcCallback : public IGarbageCollectCallback {
+ public:
+ Return<void> onFinish(Result result) override {
+ std::unique_lock<std::mutex> lock(mMutex);
+ mFinished = true;
+ mResult = result;
+ lock.unlock();
+ mCv.notify_all();
+ return Void();
+ }
+ void wait(uint64_t seconds) {
+ std::unique_lock<std::mutex> lock(mMutex);
+ mCv.wait_for(lock, std::chrono::seconds(seconds), [this] { return mFinished; });
+
+ if (!mFinished) {
+ LOG(WARNING) << "Dev GC on HAL timeout";
+ } else if (mResult != Result::SUCCESS) {
+ LOG(WARNING) << "Dev GC on HAL failed with " << toString(mResult);
+ } else {
+ LOG(INFO) << "Dev GC on HAL successful";
+ }
+ }
+
+ private:
+ std::mutex mMutex;
+ std::condition_variable mCv;
+ bool mFinished{false};
+ Result mResult{Result::UNKNOWN_ERROR};
+};
+
+static void runDevGcOnHal(sp<IFileSystem> service) {
+ LOG(DEBUG) << "Start Dev GC on HAL";
+ sp<GcCallback> cb = new GcCallback();
+ auto ret = service->garbageCollect(DEVGC_TIMEOUT_SEC, cb);
+ if (!ret.isOk()) {
+ LOG(WARNING) << "Cannot start Dev GC on HAL: " << ret.description();
+ return;
+ }
+ cb->wait(DEVGC_TIMEOUT_SEC);
+}
+
+static void runDevGc(void) {
+ auto service = IFileSystem::getService();
+ if (service != nullptr) {
+ runDevGcOnHal(service);
+ } else {
+ // fallback to legacy code path
+ runDevGcFstab();
+ }
+}
+
int RunIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
std::unique_lock<std::mutex> lk(cv_m);
if (idle_maint_stat != IdleMaintStats::kStopped) {
diff --git a/main.cpp b/main.cpp
index 5525e85..c4071d1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -28,6 +28,7 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <cutils/klog.h>
+#include <hidl/HidlTransportSupport.h>
#include <utils/Trace.h>
#include <stdio.h>
@@ -108,6 +109,8 @@
PLOG(ERROR) << "Error reading configuration... continuing anyways";
}
+ android::hardware::configureRpcThreadpool(1, false /* callerWillJoin */);
+
ATRACE_BEGIN("VoldNativeService::start");
if (android::vold::VoldNativeService::start() != android::OK) {
LOG(ERROR) << "Unable to start VoldNativeService";