summaryrefslogtreecommitdiff
path: root/cmds/installd/utils.cpp
diff options
context:
space:
mode:
author Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-02-21 07:03:09 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-02-21 07:03:09 +0000
commit818ac485917cf803ec72ae27979f06dea26dae4b (patch)
treed76b930f20a9f93c1b3e28e7e0e70ded7437a800 /cmds/installd/utils.cpp
parentb66c667594dc8f41a8f2478f05f3315066be7e9e (diff)
parentad4e7b6bcf256dd578263b1652e0dfd09b2eea27 (diff)
Merge "Implement quota calculation for project ID based quota." am: 26b068e97c am: 93f07fb962 am: ad4e7b6bcf
Change-Id: I87d15d081855c5c4c3b24737cd4c239b31a97d2e
Diffstat (limited to 'cmds/installd/utils.cpp')
-rw-r--r--cmds/installd/utils.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 042d69e7e0..c47df52984 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -26,6 +26,7 @@
#include <sys/xattr.h>
#include <sys/statvfs.h>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include <android-base/stringprintf.h>
@@ -34,9 +35,11 @@
#include <cutils/properties.h>
#include <log/log.h>
#include <private/android_filesystem_config.h>
+#include <private/android_projectid_config.h>
#include "dexopt_return_codes.h"
#include "globals.h" // extern variables.
+#include "QuotaUtils.h"
#ifndef LOG_TAG
#define LOG_TAG "installd"
@@ -1057,6 +1060,51 @@ int prepare_app_cache_dir(const std::string& parent, const char* name, mode_t ta
return 0;
}
+static const char* kProcFilesystems = "/proc/filesystems";
+bool supports_sdcardfs() {
+ std::string supported;
+ if (!android::base::ReadFileToString(kProcFilesystems, &supported)) {
+ PLOG(ERROR) << "Failed to read supported filesystems";
+ return false;
+ }
+ return supported.find("sdcardfs\n") != std::string::npos;
+}
+
+int64_t get_occupied_app_space_external(const std::string& uuid, int32_t userId, int32_t appId) {
+ static const bool supportsSdcardFs = supports_sdcardfs();
+
+ if (supportsSdcardFs) {
+ int extGid = multiuser_get_ext_gid(userId, appId);
+
+ if (extGid == -1) {
+ return -1;
+ }
+
+ return GetOccupiedSpaceForGid(uuid, extGid);
+ } else {
+ uid_t uid = multiuser_get_uid(userId, appId);
+ long projectId = uid - AID_APP_START + PROJECT_ID_EXT_DATA_START;
+ return GetOccupiedSpaceForProjectId(uuid, projectId);
+ }
+}
+int64_t get_occupied_app_cache_space_external(const std::string& uuid, int32_t userId, int32_t appId) {
+ static const bool supportsSdcardFs = supports_sdcardfs();
+
+ if (supportsSdcardFs) {
+ int extCacheGid = multiuser_get_ext_cache_gid(userId, appId);
+
+ if (extCacheGid == -1) {
+ return -1;
+ }
+
+ return GetOccupiedSpaceForGid(uuid, extCacheGid);
+ } else {
+ uid_t uid = multiuser_get_uid(userId, appId);
+ long projectId = uid - AID_APP_START + PROJECT_ID_EXT_CACHE_START;
+ return GetOccupiedSpaceForProjectId(uuid, projectId);
+ }
+}
+
// Collect all non empty profiles from the given directory and puts then into profile_paths.
// The profiles are identified based on PROFILE_EXT extension.
// If a subdirectory or profile file cannot be opened the method logs a warning and moves on.