Merge "Remove redundant libgui dependency for GraphicBufferOverBinder_test"
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index c95ee41..fe6780f 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -474,7 +474,8 @@
StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
sUsingProjectIdsFlag = access(using_project_ids.c_str(), F_OK) == 0;
});
- return sUsingProjectIdsFlag;
+ // return sUsingProjectIdsFlag;
+ return false;
}
static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t uid, gid_t gid,
@@ -633,8 +634,9 @@
}
static binder::Status createAppDataDirs(const std::string& path, int32_t uid, int32_t gid,
- int32_t* previousUid, int32_t cacheGid,
- const std::string& seInfo, mode_t targetMode) {
+ int32_t previousUid, int32_t cacheGid,
+ const std::string& seInfo, mode_t targetMode,
+ long projectIdApp, long projectIdCache) {
struct stat st{};
bool parent_dir_exists = (stat(path.c_str(), &st) == 0);
@@ -644,25 +646,17 @@
bool code_cache_exists = (access(code_cache_path.c_str(), F_OK) == 0);
if (parent_dir_exists) {
- if (*previousUid < 0) {
- // If previousAppId is -1 in CreateAppDataArgs, we will assume the current owner
- // of the directory as previousUid. This is required because it is not always possible
- // to chown app data during app upgrade (e.g. secondary users' CE storage not unlocked)
- *previousUid = st.st_uid;
- }
- if (*previousUid != uid) {
- if (!chown_app_dir(path, uid, *previousUid, cacheGid)) {
+ if (previousUid > 0 && previousUid != uid) {
+ if (!chown_app_dir(path, uid, previousUid, cacheGid)) {
return error("Failed to chown " + path);
}
}
}
// Prepare only the parent app directory
- long project_id_app = get_project_id(uid, PROJECT_ID_APP_START);
- long project_id_cache_app = get_project_id(uid, PROJECT_ID_APP_CACHE_START);
- if (prepare_app_dir(path, targetMode, uid, gid, project_id_app) ||
- prepare_app_cache_dir(path, "cache", 02771, uid, cacheGid, project_id_cache_app) ||
- prepare_app_cache_dir(path, "code_cache", 02771, uid, cacheGid, project_id_cache_app)) {
+ if (prepare_app_dir(path, targetMode, uid, gid, projectIdApp) ||
+ prepare_app_cache_dir(path, "cache", 02771, uid, cacheGid, projectIdCache) ||
+ prepare_app_cache_dir(path, "code_cache", 02771, uid, cacheGid, projectIdCache)) {
return error("Failed to prepare " + path);
}
@@ -703,12 +697,9 @@
int32_t uid = multiuser_get_uid(userId, appId);
- // If previousAppId < 0, we will use the existing app data owner as previousAppUid
- // If previousAppId == 0, we use uid as previousUid (no data migration will happen)
- // if previousAppId > 0, an app is upgrading and changing its app ID
- int32_t previousUid = previousAppId > 0
- ? (int32_t) multiuser_get_uid(userId, previousAppId)
- : (previousAppId == 0 ? uid : -1);
+ // If previousAppId > 0, an app is changing its app ID
+ int32_t previousUid =
+ previousAppId > 0 ? (int32_t)multiuser_get_uid(userId, previousAppId) : -1;
int32_t cacheGid = multiuser_get_cache_gid(userId, appId);
mode_t targetMode = targetSdkVersion >= MIN_RESTRICTED_HOME_SDK_VERSION ? 0700 : 0751;
@@ -718,10 +709,14 @@
cacheGid = uid;
}
+ long projectIdApp = get_project_id(uid, PROJECT_ID_APP_START);
+ long projectIdCache = get_project_id(uid, PROJECT_ID_APP_CACHE_START);
+
if (flags & FLAG_STORAGE_CE) {
auto path = create_data_user_ce_package_path(uuid_, userId, pkgname);
- auto status = createAppDataDirs(path, uid, uid, &previousUid, cacheGid, seInfo, targetMode);
+ auto status = createAppDataDirs(path, uid, uid, previousUid, cacheGid, seInfo, targetMode,
+ projectIdApp, projectIdCache);
if (!status.isOk()) {
return status;
}
@@ -746,11 +741,12 @@
if (flags & FLAG_STORAGE_DE) {
auto path = create_data_user_de_package_path(uuid_, userId, pkgname);
- auto status = createAppDataDirs(path, uid, uid, &previousUid, cacheGid, seInfo, targetMode);
+ auto status = createAppDataDirs(path, uid, uid, previousUid, cacheGid, seInfo, targetMode,
+ projectIdApp, projectIdCache);
if (!status.isOk()) {
return status;
}
- if (previousUid != uid) {
+ if (previousUid > 0 && previousUid != uid) {
chown_app_profile_dir(packageName, appId, userId);
}
@@ -946,8 +942,12 @@
}
const int32_t sandboxUid = multiuser_get_sdk_sandbox_uid(userId, appId);
int32_t previousSandboxUid = multiuser_get_sdk_sandbox_uid(userId, previousAppId);
- auto status = createAppDataDirs(path, sandboxUid, AID_NOBODY, &previousSandboxUid,
- cacheGid, seInfo, 0700 | S_ISGID);
+ int32_t appUid = multiuser_get_uid(userId, appId);
+ long projectIdApp = get_project_id(appUid, PROJECT_ID_APP_START);
+ long projectIdCache = get_project_id(appUid, PROJECT_ID_APP_CACHE_START);
+ auto status =
+ createAppDataDirs(path, sandboxUid, AID_NOBODY, previousSandboxUid, cacheGid,
+ seInfo, 0700 | S_ISGID, projectIdApp, projectIdCache);
if (!status.isOk()) {
res = status;
continue;
diff --git a/cmds/installd/tests/installd_service_test.cpp b/cmds/installd/tests/installd_service_test.cpp
index 162e668..effb401 100644
--- a/cmds/installd/tests/installd_service_test.cpp
+++ b/cmds/installd/tests/installd_service_test.cpp
@@ -509,97 +509,100 @@
system(removeCommand.c_str());
}
}
-TEST_F(ServiceTest, GetAppSizeProjectID_UID) {
- struct stat s;
- std::string externalPicDir =
- StringPrintf("%s/Pictures", create_data_media_path(nullptr, 0).c_str());
- if (stat(externalPicDir.c_str(), &s) == 0) {
- // fetch the appId from the uid of the external storage owning app
- int32_t externalStorageAppId = multiuser_get_app_id(s.st_uid);
- // Fetch Package Name for the external storage owning app uid
- std::string pkg = get_package_name(s.st_uid);
-
- std::vector<int64_t> externalStorageSize, externalStorageSizeAfterAddingCacheFile;
- std::vector<int64_t> ceDataInodes;
-
- std::vector<std::string> codePaths;
- std::vector<std::string> packageNames;
- // set up parameters
- packageNames.push_back(pkg);
- ceDataInodes.push_back(0);
- // initialise the mounts
- service->invalidateMounts();
- auto using_project_ids =
- StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
- bool usingProjectIds = access(using_project_ids.c_str(), F_OK) == 0;
- if (!usingProjectIds) {
- service->setFirstBoot();
- }
-
- if (access(using_project_ids.c_str(), F_OK) != 0) {
- // projectids is not used, so check that ioctl features should be absent
- auto temp_path = StringPrintf("%smisc/installd/ioctl_check", android_data_dir.c_str());
-
- if (access(temp_path.c_str(), F_OK) != 0) {
- open(temp_path.c_str(), O_CREAT | O_TRUNC | O_RDWR | O_CLOEXEC, 0644);
- bool result = set_quota_project_id(temp_path, 0, false) == 0;
- // delete the temp file
- // remove the external file
- remove(temp_path.c_str());
- // since using_project_ids file is not present, so ioctl settings should be absent
- // that is denoted by the result of setting project id flag as false
- ASSERT_FALSE(result);
- }
- }
- // call the getAppSize to get the current size of the external storage owning app
- service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
- externalStorageAppId, ceDataInodes, codePaths, &externalStorageSize);
- // add a file with 20MB size to the external storage
- std::string externalStorageCacheDir =
- StringPrintf("%s/%s/cache", create_data_user_ce_path(nullptr, 0).c_str(),
- pkg.c_str());
- std::string cacheFileLocation =
- StringPrintf("%s/%s", externalStorageCacheDir.c_str(), "External.jpg");
- std::string externalFileContentCommand =
- StringPrintf("dd if=/dev/zero of=%s bs=1M count=20", cacheFileLocation.c_str());
- system(externalFileContentCommand.c_str());
- // call the getAppSize again to get the new size of the external storage owning app
- service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
- externalStorageAppId, ceDataInodes, codePaths,
- &externalStorageSizeAfterAddingCacheFile);
- // check that the size of cache and data increases when cache file is added
- int64_t sizeDiffData = externalStorageSizeAfterAddingCacheFile[1] - externalStorageSize[1];
- int64_t sizeDiffCache = externalStorageSizeAfterAddingCacheFile[2] - externalStorageSize[2];
- ASSERT_TRUE(sizeDiffData == sizeDiffCache);
- // remove the external file
- std::string removeCommand = StringPrintf("rm -f %s", cacheFileLocation.c_str());
- system(removeCommand.c_str());
- // remove the setFirstBoot setting
- std::string removeCommand2 = "rm -f /data/misc/installd/using_project_ids";
- system(removeCommand2.c_str());
- // Do now without project id
- std::vector<int64_t> sizeWithUID, sizeWithUIDAfterAddingCacheFile;
- // call the getAppSize to get the current size of the external storage owning app
- service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
- externalStorageAppId, ceDataInodes, codePaths, &sizeWithUID);
- // add a file with 20MB size to the external storage
- system(externalFileContentCommand.c_str());
- // call the getAppSize again to get the new size of the external storage owning app
- service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
- externalStorageAppId, ceDataInodes, codePaths,
- &sizeWithUIDAfterAddingCacheFile);
- // check that the size of cache and data increases when cache file is added
- sizeDiffData = sizeWithUIDAfterAddingCacheFile[1] - sizeWithUID[1];
- sizeDiffCache = sizeWithUIDAfterAddingCacheFile[2] - sizeWithUID[2];
- ASSERT_TRUE(sizeDiffData == sizeDiffCache);
- // remove the external file
- system(removeCommand.c_str());
- // reset the using_project_id if it was initially set
- if (usingProjectIds) {
- service->setFirstBoot();
- }
- }
-}
+// TEST_F(ServiceTest, GetAppSizeProjectID_UID) {
+// struct stat s;
+// std::string externalPicDir =
+// StringPrintf("%s/Pictures", create_data_media_path(nullptr, 0).c_str());
+// if (stat(externalPicDir.c_str(), &s) == 0) {
+// // fetch the appId from the uid of the external storage owning app
+// int32_t externalStorageAppId = multiuser_get_app_id(s.st_uid);
+// // Fetch Package Name for the external storage owning app uid
+// std::string pkg = get_package_name(s.st_uid);
+//
+// std::vector<int64_t> externalStorageSize, externalStorageSizeAfterAddingCacheFile;
+// std::vector<int64_t> ceDataInodes;
+//
+// std::vector<std::string> codePaths;
+// std::vector<std::string> packageNames;
+// // set up parameters
+// packageNames.push_back(pkg);
+// ceDataInodes.push_back(0);
+// // initialise the mounts
+// service->invalidateMounts();
+// auto using_project_ids =
+// StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
+// bool usingProjectIds = access(using_project_ids.c_str(), F_OK) == 0;
+// if (!usingProjectIds) {
+// service->setFirstBoot();
+// }
+//
+// if (access(using_project_ids.c_str(), F_OK) != 0) {
+// // projectids is not used, so check that ioctl features should be absent
+// auto temp_path = StringPrintf("%smisc/installd/ioctl_check",
+// android_data_dir.c_str());
+//
+// if (access(temp_path.c_str(), F_OK) != 0) {
+// open(temp_path.c_str(), O_CREAT | O_TRUNC | O_RDWR | O_CLOEXEC, 0644);
+// bool result = set_quota_project_id(temp_path, 0, false) == 0;
+// // delete the temp file
+// // remove the external file
+// remove(temp_path.c_str());
+// // since using_project_ids file is not present, so ioctl settings should be
+// absent
+// // that is denoted by the result of setting project id flag as false
+// ASSERT_FALSE(result);
+// }
+// }
+// // call the getAppSize to get the current size of the external storage owning app
+// service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
+// externalStorageAppId, ceDataInodes, codePaths, &externalStorageSize);
+// // add a file with 20MB size to the external storage
+// std::string externalStorageCacheDir =
+// StringPrintf("%s/%s/cache", create_data_user_ce_path(nullptr, 0).c_str(),
+// pkg.c_str());
+// std::string cacheFileLocation =
+// StringPrintf("%s/%s", externalStorageCacheDir.c_str(), "External.jpg");
+// std::string externalFileContentCommand =
+// StringPrintf("dd if=/dev/zero of=%s bs=1M count=20", cacheFileLocation.c_str());
+// system(externalFileContentCommand.c_str());
+// // call the getAppSize again to get the new size of the external storage owning app
+// service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
+// externalStorageAppId, ceDataInodes, codePaths,
+// &externalStorageSizeAfterAddingCacheFile);
+// // check that the size of cache and data increases when cache file is added
+// int64_t sizeDiffData = externalStorageSizeAfterAddingCacheFile[1] -
+// externalStorageSize[1]; int64_t sizeDiffCache =
+// externalStorageSizeAfterAddingCacheFile[2] - externalStorageSize[2];
+// ASSERT_TRUE(sizeDiffData == sizeDiffCache);
+// // remove the external file
+// std::string removeCommand = StringPrintf("rm -f %s", cacheFileLocation.c_str());
+// system(removeCommand.c_str());
+// // remove the setFirstBoot setting
+// std::string removeCommand2 = "rm -f /data/misc/installd/using_project_ids";
+// system(removeCommand2.c_str());
+// // Do now without project id
+// std::vector<int64_t> sizeWithUID, sizeWithUIDAfterAddingCacheFile;
+// // call the getAppSize to get the current size of the external storage owning app
+// service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
+// externalStorageAppId, ceDataInodes, codePaths, &sizeWithUID);
+// // add a file with 20MB size to the external storage
+// system(externalFileContentCommand.c_str());
+// // call the getAppSize again to get the new size of the external storage owning app
+// service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
+// externalStorageAppId, ceDataInodes, codePaths,
+// &sizeWithUIDAfterAddingCacheFile);
+// // check that the size of cache and data increases when cache file is added
+// sizeDiffData = sizeWithUIDAfterAddingCacheFile[1] - sizeWithUID[1];
+// sizeDiffCache = sizeWithUIDAfterAddingCacheFile[2] - sizeWithUID[2];
+// ASSERT_TRUE(sizeDiffData == sizeDiffCache);
+// // remove the external file
+// system(removeCommand.c_str());
+// // reset the using_project_id if it was initially set
+// if (usingProjectIds) {
+// service->setFirstBoot();
+// }
+// }
+// }
TEST_F(ServiceTest, GetAppSizeWrongSizes) {
int32_t externalStorageAppId = -1;
std::vector<int64_t> externalStorageSize;
diff --git a/libs/binder/rust/src/proxy.rs b/libs/binder/rust/src/proxy.rs
index e3e4730..4df557b 100644
--- a/libs/binder/rust/src/proxy.rs
+++ b/libs/binder/rust/src/proxy.rs
@@ -575,6 +575,20 @@
cookie_decr_refcount: unsafe extern "C" fn(*mut c_void),
}
+/// # Safety
+///
+/// A `DeathRecipient` is a wrapper around `AIBinder_DeathRecipient` and a pointer
+/// to a `Fn` which is `Sync` and `Send` (the cookie field). As
+/// `AIBinder_DeathRecipient` is threadsafe, this structure is too.
+unsafe impl Send for DeathRecipient {}
+
+/// # Safety
+///
+/// A `DeathRecipient` is a wrapper around `AIBinder_DeathRecipient` and a pointer
+/// to a `Fn` which is `Sync` and `Send` (the cookie field). As
+/// `AIBinder_DeathRecipient` is threadsafe, this structure is too.
+unsafe impl Sync for DeathRecipient {}
+
impl DeathRecipient {
/// Create a new death recipient that will call the given callback when its
/// associated object dies.