MTP: Add support for reserve storage setting to avoid low storage situations.

Set resource config_mtpReserveSpaceMegabytes to number of megabytes to reserve.
If MTP has dedicated storage this value should be zero, but if MTP is
sharing storage with the rest of the system, set this to a positive value
to ensure that MTP activity does not result in the storage being
too close to full.

BUG: 3250924

Change-Id: I881c87240da268bad1ea1b99ad03673ab85ffdbf
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/mtp/MtpStorage.cpp b/media/mtp/MtpStorage.cpp
index eccf186..abc23de 100644
--- a/media/mtp/MtpStorage.cpp
+++ b/media/mtp/MtpStorage.cpp
@@ -32,11 +32,11 @@
 
 namespace android {
 
-MtpStorage::MtpStorage(MtpStorageID id, const char* filePath, MtpDatabase* db)
+MtpStorage::MtpStorage(MtpStorageID id, const char* filePath, uint64_t reserveSpace)
     :   mStorageID(id),
         mFilePath(filePath),
-        mDatabase(db),
-        mMaxCapacity(0)
+        mMaxCapacity(0),
+        mReserveSpace(reserveSpace)
 {
     LOGD("MtpStorage id: %d path: %s\n", id, filePath);
 }
@@ -70,7 +70,8 @@
     struct statfs   stat;
     if (statfs(mFilePath, &stat))
         return -1;
-    return (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize;
+    uint64_t freeSpace = (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize;
+    return (freeSpace > mReserveSpace ? freeSpace - mReserveSpace : 0);
 }
 
 const char* MtpStorage::getDescription() const {