diff options
author | Yurii Zubrytskyi <zyy@google.com> | 2020-04-09 19:22:30 -0700 |
---|---|---|
committer | Yurii Zubrytskyi <zyy@google.com> | 2020-04-10 13:47:54 -0700 |
commit | 86321400385172e6bb938d53ce733f1fd7984b20 (patch) | |
tree | bffa46708212f84d6e0e0d2abf5c78c7273cf708 /services/incremental/IncrementalService.cpp | |
parent | da208016d65c331218ed3a1acd2f45d5ca4ce006 (diff) |
[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
Diffstat (limited to 'services/incremental/IncrementalService.cpp')
-rw-r--r-- | services/incremental/IncrementalService.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp index 400388e93262..2c6bf0a80fe0 100644 --- a/services/incremental/IncrementalService.cpp +++ b/services/incremental/IncrementalService.cpp @@ -237,6 +237,7 @@ IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_v 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 @@ IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_v } mJobQueue.reserve(16); - mJobProcessor = std::thread([this]() { runJobProcessing(); }); + mJobProcessor = std::thread([this]() { + mJni->initializeForCurrentThread(); + runJobProcessing(); + }); mountExistingImages(); } @@ -1248,9 +1252,10 @@ bool IncrementalService::configureNativeBinaries(StorageId storage, std::string_ 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 @@ void IncrementalService::extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle 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(); |