[incfs] Fix a crash in worker thread calling JNI
Worker thread has to initialize JNI separately to be able
to call into managed binders implemented in the same
system_server process, e.g. DataLoaderManager
Bug: 153513507
Test: adb install megacity.nov4.apk; adb install megacity.v4.apk
Change-Id: I668e8664361cd2fb3353ec50efd689c7d613658f
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index 400388e..2c6bf0a 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -237,6 +237,7 @@
mDataLoaderManager(sm.getDataLoaderManager()),
mIncFs(sm.getIncFs()),
mAppOpsManager(sm.getAppOpsManager()),
+ mJni(sm.getJni()),
mIncrementalDir(rootDir) {
if (!mVold) {
LOG(FATAL) << "Vold service is unavailable";
@@ -249,7 +250,10 @@
}
mJobQueue.reserve(16);
- mJobProcessor = std::thread([this]() { runJobProcessing(); });
+ mJobProcessor = std::thread([this]() {
+ mJni->initializeForCurrentThread();
+ runJobProcessing();
+ });
mountExistingImages();
}
@@ -1248,9 +1252,10 @@
continue;
}
- jobQueue.emplace_back([this, zipFile, entry, ifs, libFileId,
- libPath = std::move(targetLibPath), makeFileTs]() mutable {
- extractZipFile(ifs, zipFile.get(), entry, libFileId, libPath, makeFileTs);
+ jobQueue.emplace_back([this, zipFile, entry, ifs = std::weak_ptr<IncFsMount>(ifs),
+ libFileId, libPath = std::move(targetLibPath),
+ makeFileTs]() mutable {
+ extractZipFile(ifs.lock(), zipFile.get(), entry, libFileId, libPath, makeFileTs);
});
if (sEnablePerfLogging) {
@@ -1296,6 +1301,11 @@
ZipEntry& entry, const incfs::FileId& libFileId,
std::string_view targetLibPath,
Clock::time_point scheduledTs) {
+ if (!ifs) {
+ LOG(INFO) << "Skipping zip file " << targetLibPath << " extraction for an expired mount";
+ return;
+ }
+
auto libName = path::basename(targetLibPath);
auto startedTs = Clock::now();