Trim both internal and adopted private storage.

Refactor fstrim code to be encapsulated in unique task object, and
give it option of benchmarking when finished.  Trimming now includes
both storage from fstab and adopted private volumes.  Cleaner timing
stats are logged for each unique volume.

Add wakelock during ongoing async move tasks.  Push disk sysfs path
to framework so it can parse any SD card registers as desired.

Bug: 21831325
Change-Id: I76577685f5cae4929c251ad314ffdaeb5eb1c8bf
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index d1a0b2f..6710b0c 100755
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -60,7 +60,6 @@
 #include "Asec.h"
 #include "VoldUtil.h"
 #include "cryptfs.h"
-#include "fstrim.h"
 
 #define MASS_STORAGE_FILE_PATH  "/sys/class/android_usb/android0/f_mass_storage/lun/file"
 
@@ -370,20 +369,23 @@
     return nullptr;
 }
 
-nsecs_t VolumeManager::benchmarkVolume(const std::string& id) {
+void VolumeManager::listVolumes(android::vold::VolumeBase::Type type,
+        std::list<std::string>& list) {
+    list.clear();
+    for (auto disk : mDisks) {
+        disk->listVolumes(type, list);
+    }
+}
+
+nsecs_t VolumeManager::benchmarkPrivate(const std::string& id) {
     std::string path;
-    std::string sysPath;
-    auto vol = findVolume(id);
-    if (vol != nullptr) {
-        if (vol->getState() == android::vold::VolumeBase::State::kMounted) {
-            path = vol->getPath();
-            auto disk = findDisk(vol->getDiskId());
-            if (disk != nullptr) {
-                sysPath = disk->getSysPath();
-            }
-        }
-    } else {
+    if (id == "private" || id == "null") {
         path = "/data";
+    } else {
+        auto vol = findVolume(id);
+        if (vol != nullptr && vol->getState() == android::vold::VolumeBase::State::kMounted) {
+            path = vol->getPath();
+        }
     }
 
     if (path.empty()) {
@@ -391,20 +393,7 @@
         return -1;
     }
 
-    path += "/misc";
-    if (android::vold::PrepareDir(path, 01771, AID_SYSTEM, AID_MISC)) {
-        return -1;
-    }
-    path += "/vold";
-    if (android::vold::PrepareDir(path, 0700, AID_ROOT, AID_ROOT)) {
-        return -1;
-    }
-    path += "/bench";
-    if (android::vold::PrepareDir(path, 0700, AID_ROOT, AID_ROOT)) {
-        return -1;
-    }
-
-    return android::vold::Benchmark(path, sysPath);
+    return android::vold::BenchmarkPrivate(path);
 }
 
 int VolumeManager::forgetPartition(const std::string& partGuid) {