diff options
author | 2020-08-20 08:40:29 -0700 | |
---|---|---|
committer | 2020-08-22 04:17:02 +0000 | |
commit | 374f7654dfb00692f6b3c2f6c68997e3ca54092a (patch) | |
tree | 209eec3efa43e43f1795f95905ae61eec575e3a7 /services/incremental/ServiceWrappers.cpp | |
parent | 1581527cbd46ac3411fdf0c7068f40c04a9926fd (diff) |
[IncrementalService] getLoadingProgress (v1)
This is to unblock Launcher's work on progress ring. Currently it uses
incfs getFilledBlocks(). Will switch to the new incfs progress reporting
API once it is ready.
Test: unit test
Test: adb shell dumpsys incremental
BUG: 165799231
Change-Id: Icd68124806454f888826294da36f109bca9771ac
Diffstat (limited to 'services/incremental/ServiceWrappers.cpp')
-rw-r--r-- | services/incremental/ServiceWrappers.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/services/incremental/ServiceWrappers.cpp b/services/incremental/ServiceWrappers.cpp index 99a35adb5074..1ed46c49c5e1 100644 --- a/services/incremental/ServiceWrappers.cpp +++ b/services/incremental/ServiceWrappers.cpp @@ -25,6 +25,7 @@ #include <binder/AppOpsManager.h> #include <utils/String16.h> +#include <filesystem> #include <thread> #include "IncrementalServiceValidation.h" @@ -165,6 +166,29 @@ public: FileId getFileId(const Control& control, std::string_view path) const final { return incfs::getFileId(control, path); } + std::pair<IncFsBlockIndex, IncFsBlockIndex> countFilledBlocks( + const Control& control, std::string_view path) const final { + const auto fileId = incfs::getFileId(control, path); + const auto fd = incfs::openForSpecialOps(control, fileId); + int res = fd.get(); + if (!fd.ok()) { + return {res, res}; + } + const auto ranges = incfs::getFilledRanges(res); + res = ranges.first; + if (res) { + return {res, res}; + } + const auto totalBlocksCount = ranges.second.internalRawRanges().endIndex; + int filledBlockCount = 0; + for (const auto& dataRange : ranges.second.dataRanges()) { + filledBlockCount += dataRange.size(); + } + for (const auto& hashRange : ranges.second.hashRanges()) { + filledBlockCount += hashRange.size(); + } + return {filledBlockCount, totalBlocksCount}; + } ErrorCode link(const Control& control, std::string_view from, std::string_view to) const final { return incfs::link(control, from, to); } @@ -265,6 +289,23 @@ private: std::thread mThread; }; +class RealFsWrapper : public FsWrapper { +public: + RealFsWrapper() = default; + ~RealFsWrapper() = default; + + std::vector<std::string> listFilesRecursive(std::string_view directoryPath) const final { + std::vector<std::string> files; + for (const auto& entry : std::filesystem::recursive_directory_iterator(directoryPath)) { + if (!entry.is_regular_file()) { + continue; + } + files.push_back(entry.path().c_str()); + } + return files; + } +}; + RealServiceManager::RealServiceManager(sp<IServiceManager> serviceManager, JNIEnv* env) : mServiceManager(std::move(serviceManager)), mJvm(RealJniWrapper::getJvm(env)) {} @@ -316,6 +357,10 @@ std::unique_ptr<TimedQueueWrapper> RealServiceManager::getTimedQueue() { return std::make_unique<RealTimedQueueWrapper>(mJvm); } +std::unique_ptr<FsWrapper> RealServiceManager::getFs() { + return std::make_unique<RealFsWrapper>(); +} + static JavaVM* getJavaVm(JNIEnv* env) { CHECK(env); JavaVM* jvm = nullptr; |