[incfs] Use the new libincfs API for file status checking
libincfs got a new set of functions for checking the file loaded
status, which works more efficiently than getting filled ranges.
Bug: 183067554
Test: atest IncrementalServiceTest
Change-Id: I3b96bf409f1778c5a89e4802e2005197f70ce0cb
diff --git a/services/incremental/BinderIncrementalService.cpp b/services/incremental/BinderIncrementalService.cpp
index 8f12b2e..9869b07 100644
--- a/services/incremental/BinderIncrementalService.cpp
+++ b/services/incremental/BinderIncrementalService.cpp
@@ -255,13 +255,12 @@
binder::Status BinderIncrementalService::isFileFullyLoaded(int32_t storageId,
const std::string& path,
int32_t* _aidl_return) {
- *_aidl_return = mImpl.isFileFullyLoaded(storageId, path);
+ *_aidl_return = (int)mImpl.isFileFullyLoaded(storageId, path);
return ok();
}
binder::Status BinderIncrementalService::isFullyLoaded(int32_t storageId, int32_t* _aidl_return) {
- *_aidl_return = mImpl.getLoadingProgress(storageId, /*stopOnFirstIncomplete=*/true)
- .blocksRemainingOrError();
+ *_aidl_return = (int)mImpl.isMountFullyLoaded(storageId);
return ok();
}
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index db70d44..ebfcc32 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -1980,35 +1980,30 @@
return 0;
}
-int IncrementalService::isFileFullyLoaded(StorageId storage, std::string_view filePath) const {
+incfs::LoadingState IncrementalService::isFileFullyLoaded(StorageId storage,
+ std::string_view filePath) const {
std::unique_lock l(mLock);
const auto ifs = getIfsLocked(storage);
if (!ifs) {
LOG(ERROR) << "isFileFullyLoaded failed, invalid storageId: " << storage;
- return -EINVAL;
+ return incfs::LoadingState(-EINVAL);
}
const auto storageInfo = ifs->storages.find(storage);
if (storageInfo == ifs->storages.end()) {
LOG(ERROR) << "isFileFullyLoaded failed, no storage: " << storage;
- return -EINVAL;
+ return incfs::LoadingState(-EINVAL);
}
l.unlock();
- return isFileFullyLoadedFromPath(*ifs, filePath);
+ return mIncFs->isFileFullyLoaded(ifs->control, filePath);
}
-int IncrementalService::isFileFullyLoadedFromPath(const IncFsMount& ifs,
- std::string_view filePath) const {
- const auto [filledBlocks, totalBlocks] = mIncFs->countFilledBlocks(ifs.control, filePath);
- if (filledBlocks < 0) {
- LOG(ERROR) << "isFileFullyLoadedFromPath failed to get filled blocks count for: "
- << filePath << " errno: " << filledBlocks;
- return filledBlocks;
+incfs::LoadingState IncrementalService::isMountFullyLoaded(StorageId storage) const {
+ const auto ifs = getIfs(storage);
+ if (!ifs) {
+ LOG(ERROR) << "isMountFullyLoaded failed, invalid storageId: " << storage;
+ return incfs::LoadingState(-EINVAL);
}
- if (totalBlocks < filledBlocks) {
- LOG(ERROR) << "isFileFullyLoadedFromPath failed to get total num of blocks";
- return -EINVAL;
- }
- return totalBlocks - filledBlocks;
+ return mIncFs->isEverythingFullyLoaded(ifs->control);
}
IncrementalService::LoadingProgress IncrementalService::getLoadingProgress(
diff --git a/services/incremental/IncrementalService.h b/services/incremental/IncrementalService.h
index bc441c7..aa80bd4 100644
--- a/services/incremental/IncrementalService.h
+++ b/services/incremental/IncrementalService.h
@@ -164,7 +164,8 @@
std::string_view newPath);
int unlink(StorageId storage, std::string_view path);
- int isFileFullyLoaded(StorageId storage, std::string_view filePath) const;
+ incfs::LoadingState isFileFullyLoaded(StorageId storage, std::string_view filePath) const;
+ incfs::LoadingState isMountFullyLoaded(StorageId storage) const;
LoadingProgress getLoadingProgress(StorageId storage, bool stopOnFirstIncomplete) const;
@@ -412,7 +413,6 @@
int setStorageParams(IncFsMount& ifs, StorageId storageId, bool enableReadLogs);
binder::Status applyStorageParams(IncFsMount& ifs, bool enableReadLogs);
- int isFileFullyLoadedFromPath(const IncFsMount& ifs, std::string_view filePath) const;
LoadingProgress getLoadingProgressFromPath(const IncFsMount& ifs, std::string_view path,
bool stopOnFirstIncomplete) const;
diff --git a/services/incremental/ServiceWrappers.cpp b/services/incremental/ServiceWrappers.cpp
index 2a06122..eb204c5 100644
--- a/services/incremental/ServiceWrappers.cpp
+++ b/services/incremental/ServiceWrappers.cpp
@@ -197,6 +197,13 @@
}
return {filledBlockCount, totalBlocksCount};
}
+ incfs::LoadingState isFileFullyLoaded(const Control& control,
+ std::string_view path) const final {
+ return incfs::isFullyLoaded(control, path);
+ }
+ incfs::LoadingState isEverythingFullyLoaded(const Control& control) const final {
+ return incfs::isEverythingFullyLoaded(control);
+ }
ErrorCode link(const Control& control, std::string_view from, std::string_view to) const final {
return incfs::link(control, from, to);
}
diff --git a/services/incremental/ServiceWrappers.h b/services/incremental/ServiceWrappers.h
index 231b76f..2f3eb24 100644
--- a/services/incremental/ServiceWrappers.h
+++ b/services/incremental/ServiceWrappers.h
@@ -102,6 +102,9 @@
virtual std::string toString(FileId fileId) const = 0;
virtual std::pair<IncFsBlockIndex, IncFsBlockIndex> countFilledBlocks(
const Control& control, std::string_view path) const = 0;
+ virtual incfs::LoadingState isFileFullyLoaded(const Control& control,
+ std::string_view path) const = 0;
+ virtual incfs::LoadingState isEverythingFullyLoaded(const Control& control) const = 0;
virtual ErrorCode link(const Control& control, std::string_view from,
std::string_view to) const = 0;
virtual ErrorCode unlink(const Control& control, std::string_view path) const = 0;
diff --git a/services/incremental/test/IncrementalServiceTest.cpp b/services/incremental/test/IncrementalServiceTest.cpp
index 45b796b..50d1e36 100644
--- a/services/incremental/test/IncrementalServiceTest.cpp
+++ b/services/incremental/test/IncrementalServiceTest.cpp
@@ -366,6 +366,9 @@
MOCK_CONST_METHOD2(countFilledBlocks,
std::pair<IncFsBlockIndex, IncFsBlockIndex>(const Control& control,
std::string_view path));
+ MOCK_CONST_METHOD2(isFileFullyLoaded,
+ incfs::LoadingState(const Control& control, std::string_view path));
+ MOCK_CONST_METHOD1(isEverythingFullyLoaded, incfs::LoadingState(const Control& control));
MOCK_CONST_METHOD3(link,
ErrorCode(const Control& control, std::string_view from,
std::string_view to));
@@ -1563,51 +1566,37 @@
ASSERT_EQ(res, 0);
}
-TEST_F(IncrementalServiceTest, testIsFileFullyLoadedFailsWithNoFile) {
- mIncFs->countFilledBlocksFails();
- mFs->hasNoFile();
-
+TEST_F(IncrementalServiceTest, testIsFileFullyLoadedNoData) {
TemporaryDir tempDir;
int storageId =
mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel,
IncrementalService::CreateOptions::CreateNew);
- ASSERT_EQ(-1, mIncrementalService->isFileFullyLoaded(storageId, "base.apk"));
+ EXPECT_CALL(*mIncFs, isFileFullyLoaded(_, _))
+ .Times(1)
+ .WillOnce(Return(incfs::LoadingState::MissingBlocks));
+ ASSERT_GT((int)mIncrementalService->isFileFullyLoaded(storageId, "base.apk"), 0);
}
-TEST_F(IncrementalServiceTest, testIsFileFullyLoadedFailsWithFailedRanges) {
- mIncFs->countFilledBlocksFails();
- mFs->hasFiles();
-
+TEST_F(IncrementalServiceTest, testIsFileFullyLoadedError) {
TemporaryDir tempDir;
int storageId =
mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel,
IncrementalService::CreateOptions::CreateNew);
- EXPECT_CALL(*mIncFs, countFilledBlocks(_, _)).Times(1);
- ASSERT_EQ(-1, mIncrementalService->isFileFullyLoaded(storageId, "base.apk"));
-}
-
-TEST_F(IncrementalServiceTest, testIsFileFullyLoadedSuccessWithEmptyRanges) {
- mIncFs->countFilledBlocksEmpty();
- mFs->hasFiles();
-
- TemporaryDir tempDir;
- int storageId =
- mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel,
- IncrementalService::CreateOptions::CreateNew);
- EXPECT_CALL(*mIncFs, countFilledBlocks(_, _)).Times(1);
- ASSERT_EQ(0, mIncrementalService->isFileFullyLoaded(storageId, "base.apk"));
+ EXPECT_CALL(*mIncFs, isFileFullyLoaded(_, _))
+ .Times(1)
+ .WillOnce(Return(incfs::LoadingState(-1)));
+ ASSERT_LT((int)mIncrementalService->isFileFullyLoaded(storageId, "base.apk"), 0);
}
TEST_F(IncrementalServiceTest, testIsFileFullyLoadedSuccess) {
- mIncFs->countFilledBlocksFullyLoaded();
- mFs->hasFiles();
-
TemporaryDir tempDir;
int storageId =
mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel,
IncrementalService::CreateOptions::CreateNew);
- EXPECT_CALL(*mIncFs, countFilledBlocks(_, _)).Times(1);
- ASSERT_EQ(0, mIncrementalService->isFileFullyLoaded(storageId, "base.apk"));
+ EXPECT_CALL(*mIncFs, isFileFullyLoaded(_, _))
+ .Times(1)
+ .WillOnce(Return(incfs::LoadingState::Full));
+ ASSERT_EQ(0, (int)mIncrementalService->isFileFullyLoaded(storageId, "base.apk"));
}
TEST_F(IncrementalServiceTest, testGetLoadingProgressSuccessWithNoFile) {