Move long-running calls to async with listeners.

Now that we're using Binder, we can have callers provide explicit
listeners for every request instead of trying to squeeze them all
into unsolicited socket events.

Move benchmarking to be async to avoid blocking other commands for
up to several minutes.  Remove post-trim benchmarking flag, since
benchmarking now requires a separate callback.  Will bring back in
a future CL.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Test: adb shell sm fstrim
Bug: 62201209, 13758960
Change-Id: I0f2ebf1ac3b4252ecd6b44303f2887adfdb58e86
diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp
index f5f0838..6c25674 100644
--- a/VoldNativeService.cpp
+++ b/VoldNativeService.cpp
@@ -16,6 +16,7 @@
 
 #include "VoldNativeService.h"
 #include "VolumeManager.h"
+#include "BenchmarkTask.h"
 #include "MoveTask.h"
 #include "Process.h"
 #include "TrimTask.h"
@@ -333,17 +334,39 @@
     return translate(vol->format(fsType));
 }
 
-binder::Status VoldNativeService::benchmark(const std::string& volId, int64_t* _aidl_return) {
+binder::Status VoldNativeService::benchmark(const std::string& volId,
+        const android::sp<android::os::IVoldTaskListener>& listener) {
     ENFORCE_UID(AID_SYSTEM);
     CHECK_ARGUMENT_ID(volId);
     ACQUIRE_LOCK;
 
-    *_aidl_return = VolumeManager::Instance()->benchmarkPrivate(volId);
+    std::string path;
+    if (volId == "private" || volId == "null") {
+        path = "/data";
+    } else {
+        auto vol = VolumeManager::Instance()->findVolume(volId);
+        if (vol == nullptr) {
+            return error("Failed to find volume " + volId);
+        }
+        if (vol->getType() != VolumeBase::Type::kPrivate) {
+            return error("Volume " + volId + " not private");
+        }
+        if (vol->getState() != VolumeBase::State::kMounted) {
+            return error("Volume " + volId + " not mounted");
+        }
+        path = vol->getPath();
+    }
+
+    if (path.empty()) {
+        return error("Volume " + volId + " missing path");
+    }
+
+    (new android::vold::BenchmarkTask(path, listener))->start();
     return ok();
 }
 
 binder::Status VoldNativeService::moveStorage(const std::string& fromVolId,
-        const std::string& toVolId) {
+        const std::string& toVolId, const android::sp<android::os::IVoldTaskListener>& listener) {
     ENFORCE_UID(AID_SYSTEM);
     CHECK_ARGUMENT_ID(fromVolId);
     CHECK_ARGUMENT_ID(toVolId);
@@ -356,7 +379,7 @@
     } else if (toVol == nullptr) {
         return error("Failed to find volume " + toVolId);
     }
-    (new android::vold::MoveTask(fromVol, toVol))->start();
+    (new android::vold::MoveTask(fromVol, toVol, listener))->start();
     return ok();
 }
 
@@ -402,11 +425,12 @@
     return translate(VolumeManager::Instance()->destroyObb(volId));
 }
 
-binder::Status VoldNativeService::fstrim(int32_t fstrimFlags) {
+binder::Status VoldNativeService::fstrim(int32_t fstrimFlags,
+        const android::sp<android::os::IVoldTaskListener>& listener) {
     ENFORCE_UID(AID_SYSTEM);
     ACQUIRE_LOCK;
 
-    (new android::vold::TrimTask(fstrimFlags))->start();
+    (new android::vold::TrimTask(fstrimFlags, listener))->start();
     return ok();
 }