More robust createAppData() batching.
The perf team noticed that createAppData() is pretty slow, holding up
typical device boot timings because it loops over all installed apps
twice (once for DE, once for CE storage), making blocking installd
calls for each individual app.
There was a createAppDataBatched() method added awhile back, but it
was only wired up for multi-user initialization, and it was fragile
because any failure in the batch would leave the device in a
non-deterministic state.
This change rewrites the installd batch call to return a unique
result object for each request, allowing us to share both detailed
success (returning CE inode values) and detailed error messages,
instead of failing the entire batch request.
On the framework side, we use CompletableFuture to collect multiple
requests for batching, while also allowing "chaining" of follow-up
work, which PackageManagerService heavily relies upon. (For example,
when a specific package fails, we might want to try destroying and
recreating its data directories.)
Bug: 163861619
Test: atest FrameworksServicesTests:com.android.server.pm
Test: atest android.appsecurity.cts.DirectBootHostTest
Change-Id: Ib903dbbbe98fa453c8a3500338824064ae64f80f
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index e7014c8..eb1bbd9 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -420,33 +420,6 @@
return true;
}
-binder::Status InstalldNativeService::createAppDataBatched(
- const std::optional<std::vector<std::optional<std::string>>>& uuids,
- const std::optional<std::vector<std::optional<std::string>>>& packageNames,
- int32_t userId, int32_t flags, const std::vector<int32_t>& appIds,
- const std::vector<std::string>& seInfos, const std::vector<int32_t>& targetSdkVersions,
- int64_t* _aidl_return) {
- ENFORCE_UID(AID_SYSTEM);
- std::lock_guard<std::recursive_mutex> lock(mLock);
-
- ATRACE_BEGIN("createAppDataBatched");
- binder::Status ret;
- for (size_t i = 0; i < uuids->size(); i++) {
- std::optional<std::string> packageName = packageNames->at(i);
- if (!packageName) {
- continue;
- }
- ret = createAppData(uuids->at(i), *packageName, userId, flags, appIds[i],
- seInfos[i], targetSdkVersions[i], _aidl_return);
- if (!ret.isOk()) {
- ATRACE_END();
- return ret;
- }
- }
- ATRACE_END();
- return ok();
-}
-
binder::Status InstalldNativeService::createAppData(const std::optional<std::string>& uuid,
const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return) {
@@ -528,6 +501,38 @@
return ok();
}
+
+binder::Status InstalldNativeService::createAppData(
+ const android::os::CreateAppDataArgs& args,
+ android::os::CreateAppDataResult* _aidl_return) {
+ ENFORCE_UID(AID_SYSTEM);
+ std::lock_guard<std::recursive_mutex> lock(mLock);
+
+ int64_t ceDataInode = -1;
+ auto status = createAppData(args.uuid, args.packageName, args.userId, args.flags, args.appId,
+ args.seInfo, args.targetSdkVersion, &ceDataInode);
+ _aidl_return->ceDataInode = ceDataInode;
+ _aidl_return->exceptionCode = status.exceptionCode();
+ _aidl_return->exceptionMessage = status.exceptionMessage();
+ return ok();
+}
+
+binder::Status InstalldNativeService::createAppDataBatched(
+ const std::vector<android::os::CreateAppDataArgs>& args,
+ std::vector<android::os::CreateAppDataResult>* _aidl_return) {
+ ENFORCE_UID(AID_SYSTEM);
+ std::lock_guard<std::recursive_mutex> lock(mLock);
+
+ std::vector<android::os::CreateAppDataResult> results;
+ for (auto arg : args) {
+ android::os::CreateAppDataResult result;
+ createAppData(arg, &result);
+ results.push_back(result);
+ }
+ *_aidl_return = results;
+ return ok();
+}
+
binder::Status InstalldNativeService::migrateAppData(const std::optional<std::string>& uuid,
const std::string& packageName, int32_t userId, int32_t flags) {
ENFORCE_UID(AID_SYSTEM);