From a3a3c8168d7b6cd4d6fde89d429051f631d075e9 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 19 Feb 2020 17:14:05 +0100 Subject: [PATCH] Don't try to set quotas on sdcardfs. sdcardfs takes care of quotas in a different way. Bug: 146419093 Test: no attempts to set quota on devices without sdcardfs Change-Id: I6a81bf008141cde5a53ee5a413993407a7771b45 --- .../jni/android_os_storage_StorageManager.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/jni/android_os_storage_StorageManager.cpp b/core/jni/android_os_storage_StorageManager.cpp index aee6733ecf532..fd3e66b1bbce4 100644 --- a/core/jni/android_os_storage_StorageManager.cpp +++ b/core/jni/android_os_storage_StorageManager.cpp @@ -15,6 +15,7 @@ */ #define LOG_TAG "StorageManager" +#include #include #include #include @@ -25,11 +26,30 @@ namespace android { +static const char* kProcFilesystems = "/proc/filesystems"; + +// Checks whether the passed in filesystem is listed in /proc/filesystems +static bool IsFilesystemSupported(const std::string& fsType) { + std::string supported; + if (!android::base::ReadFileToString(kProcFilesystems, &supported)) { + PLOG(ERROR) << "Failed to read supported filesystems"; + return false; + } + return supported.find(fsType + "\n") != std::string::npos; +} + jboolean android_os_storage_StorageManager_setQuotaProjectId(JNIEnv* env, jobject self, jstring path, jlong projectId) { struct fsxattr fsx; ScopedUtfChars utf_chars_path(env, path); + static bool sdcardFsSupported = IsFilesystemSupported("sdcardfs"); + if (sdcardFsSupported) { + // sdcardfs doesn't support project ID quota tracking and takes care of quota + // in a different way. + return JNI_TRUE; + } + if (projectId > UINT32_MAX) { LOG(ERROR) << "Invalid project id: " << projectId; return JNI_FALSE;