diff options
author | 2021-03-31 22:19:42 -0700 | |
---|---|---|
committer | 2021-04-08 09:57:54 +0000 | |
commit | c144cc453a6206b259041e8976544b43a7bd6c02 (patch) | |
tree | 60aaf47ede4a021dc0c2c144103f4c781e887bca | |
parent | bcc5b4c1ff0c5ac8299df40c2fa146c3345e2c61 (diff) |
Installation hardening: reducing read timeout during installation.
And then restoring post-install.
Bug: 160635296
Test: atest PackageManagerShellCommandTest PackageManagerShellCommandIncrementalTest IncrementalServiceTest PackageManagerServiceTest ChecksumsTest
Change-Id: I0821458bf92db162518a2cbcb7499cd7544e64f2
11 files changed, 173 insertions, 58 deletions
diff --git a/core/java/android/os/incremental/IIncrementalService.aidl b/core/java/android/os/incremental/IIncrementalService.aidl index d7bb2262063e..ba6fc6e841b0 100644 --- a/core/java/android/os/incremental/IIncrementalService.aidl +++ b/core/java/android/os/incremental/IIncrementalService.aidl @@ -53,6 +53,11 @@ interface IIncrementalService { in PerUidReadTimeouts[] perUidReadTimeouts); /** + * PM/system is done with this storage, ok to increase timeouts. + */ + void onInstallationComplete(int storageId); + + /** * Bind-mounts a path under a storage to a full path. Can be permanent or temporary. */ const int BIND_TEMPORARY = 0; diff --git a/core/java/android/os/incremental/IncrementalFileStorages.java b/core/java/android/os/incremental/IncrementalFileStorages.java index 2a42b981ac26..6e25968192ae 100644 --- a/core/java/android/os/incremental/IncrementalFileStorages.java +++ b/core/java/android/os/incremental/IncrementalFileStorages.java @@ -205,16 +205,26 @@ public final class IncrementalFileStorages { /** * Resets the states and unbinds storage instances for an installation session. */ - public void cleanUp() { - if (mDefaultStorage == null) { - return; + public void cleanUpAndMarkComplete() { + IncrementalStorage defaultStorage = cleanUp(); + if (defaultStorage != null) { + defaultStorage.onInstallationComplete(); + } + } + + private IncrementalStorage cleanUp() { + IncrementalStorage defaultStorage = mDefaultStorage; + mInheritedStorage = null; + mDefaultStorage = null; + if (defaultStorage == null) { + return null; } try { mIncrementalManager.unregisterLoadingProgressCallbacks(mStageDir.getAbsolutePath()); - mDefaultStorage.unBind(mStageDir.getAbsolutePath()); + defaultStorage.unBind(mStageDir.getAbsolutePath()); } catch (IOException ignored) { } - mDefaultStorage = null; + return defaultStorage; } } diff --git a/core/java/android/os/incremental/IncrementalStorage.java b/core/java/android/os/incremental/IncrementalStorage.java index 7cf0144d71f7..c19e29f9cdd6 100644 --- a/core/java/android/os/incremental/IncrementalStorage.java +++ b/core/java/android/os/incremental/IncrementalStorage.java @@ -398,7 +398,7 @@ public final class IncrementalStorage { } /** - * Iinitializes and starts the DataLoader. + * Initializes and starts the DataLoader. * This makes sure all install-time parameters are applied. * Does not affect persistent DataLoader params. * @return True if start request was successfully queued. @@ -419,6 +419,18 @@ public final class IncrementalStorage { } } + /** + * Marks the completion of installation. + */ + public void onInstallationComplete() { + try { + mService.onInstallationComplete(mId); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + } + + private static final int UUID_BYTE_SIZE = 16; /** diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index a6d4ed932ad9..e532790589a3 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -4157,7 +4157,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { if (stageDir != null && !params.isStaged) { try { if (incrementalFileStorages != null) { - incrementalFileStorages.cleanUp(); + incrementalFileStorages.cleanUpAndMarkComplete(); } mPm.mInstaller.rmPackageDir(stageDir.getAbsolutePath()); } catch (InstallerException ignored) { @@ -4183,7 +4183,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } try { if (incrementalFileStorages != null) { - incrementalFileStorages.cleanUp(); + incrementalFileStorages.cleanUpAndMarkComplete(); } mPm.mInstaller.rmPackageDir(stageDir.getAbsolutePath()); } catch (InstallerException ignored) { diff --git a/services/incremental/BinderIncrementalService.cpp b/services/incremental/BinderIncrementalService.cpp index 63488f995865..f843ea44541e 100644 --- a/services/incremental/BinderIncrementalService.cpp +++ b/services/incremental/BinderIncrementalService.cpp @@ -150,6 +150,11 @@ binder::Status BinderIncrementalService::startLoading( return ok(); } +binder::Status BinderIncrementalService::onInstallationComplete(int32_t storageId) { + mImpl.onInstallationComplete(storageId); + return ok(); +} + binder::Status BinderIncrementalService::makeBindMount(int32_t storageId, const std::string& sourcePath, const std::string& targetFullPath, diff --git a/services/incremental/BinderIncrementalService.h b/services/incremental/BinderIncrementalService.h index ebb23dc25bac..5c8741bc1f9d 100644 --- a/services/incremental/BinderIncrementalService.h +++ b/services/incremental/BinderIncrementalService.h @@ -52,6 +52,8 @@ public: const ::android::sp<IStorageHealthListener>& healthListener, const ::std::vector<::android::os::incremental::PerUidReadTimeouts>& perUidReadTimeouts, bool* _aidl_return) final; + binder::Status onInstallationComplete(int32_t storageId) final; + binder::Status makeBindMount(int32_t storageId, const std::string& sourcePath, const std::string& targetFullPath, int32_t bindType, int32_t* _aidl_return) final; diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp index 6695ba841b67..388f9329829d 100644 --- a/services/incremental/IncrementalService.cpp +++ b/services/incremental/IncrementalService.cpp @@ -100,6 +100,12 @@ static bool isPageAligned(IncFsSize s) { return (s & (Constants::blockSize - 1)) == 0; } +static bool getAlwaysEnableReadTimeoutsForSystemDataLoaders() { + return android::base:: + GetBoolProperty("debug.incremental.always_enable_read_timeouts_for_system_dataloaders", + true); +} + static bool getEnforceReadLogsMaxIntervalForSystemDataLoaders() { return android::base::GetBoolProperty("debug.incremental.enforce_readlogs_max_interval_for_" "system_dataloaders", @@ -315,19 +321,11 @@ void IncrementalService::IncFsMount::cleanupFilesystem(std::string_view root) { ::rmdir(path::c_str(root)); } -void IncrementalService::IncFsMount::setReadLogsEnabled(bool value) { +void IncrementalService::IncFsMount::setFlag(StorageFlags flag, bool value) { if (value) { - flags |= StorageFlags::ReadLogsEnabled; + flags |= flag; } else { - flags &= ~StorageFlags::ReadLogsEnabled; - } -} - -void IncrementalService::IncFsMount::setReadLogsRequested(bool value) { - if (value) { - flags |= StorageFlags::ReadLogsRequested; - } else { - flags &= ~StorageFlags::ReadLogsRequested; + flags &= ~flag; } } @@ -728,10 +726,17 @@ bool IncrementalService::startLoading(StorageId storageId, LOG(INFO) << "Skipped data loader stub creation because it already exists"; return false; } + prepareDataLoaderLocked(*ifs, std::move(dataLoaderParams), std::move(statusListener), healthCheckParams, std::move(healthListener)); CHECK(ifs->dataLoaderStub); dataLoaderStub = ifs->dataLoaderStub; + + // Disable long read timeouts for non-system dataloaders. + // To be re-enabled after installation is complete. + ifs->setReadTimeoutsRequested(dataLoaderStub->isSystemDataLoader() && + getAlwaysEnableReadTimeoutsForSystemDataLoaders()); + applyStorageParamsLocked(*ifs); } if (dataLoaderStub->isSystemDataLoader() && @@ -765,6 +770,18 @@ bool IncrementalService::startLoading(StorageId storageId, return dataLoaderStub->requestStart(); } +void IncrementalService::onInstallationComplete(StorageId storage) { + IfsMountPtr ifs = getIfs(storage); + if (!ifs) { + return; + } + + // Always enable long read timeouts after installation is complete. + std::unique_lock l(ifs->lock); + ifs->setReadTimeoutsRequested(true); + applyStorageParamsLocked(*ifs); +} + IncrementalService::BindPathMap::const_iterator IncrementalService::findStorageLocked( std::string_view path) const { return findParentPath(mBindsByPath, path); @@ -868,7 +885,7 @@ int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLog if (!ifs->readLogsRequested()) { return 0; } - if (auto status = applyStorageParamsLocked(*ifs, /*enableReadLogs=*/true); status != 0) { + if (auto status = applyStorageParamsLocked(*ifs); status != 0) { return status; } } @@ -880,10 +897,10 @@ int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLog int IncrementalService::disableReadLogsLocked(IncFsMount& ifs) { ifs.setReadLogsRequested(false); - return applyStorageParamsLocked(ifs, /*enableReadLogs=*/false); + return applyStorageParamsLocked(ifs); } -int IncrementalService::applyStorageParamsLocked(IncFsMount& ifs, bool enableReadLogs) { +int IncrementalService::applyStorageParamsLocked(IncFsMount& ifs) { os::incremental::IncrementalFileSystemControlParcel control; control.cmd.reset(dup(ifs.control.cmd())); control.pendingReads.reset(dup(ifs.control.pendingReads())); @@ -892,11 +909,15 @@ int IncrementalService::applyStorageParamsLocked(IncFsMount& ifs, bool enableRea control.log.reset(dup(logsFd)); } + bool enableReadLogs = ifs.readLogsRequested(); + bool enableReadTimeouts = ifs.readTimeoutsRequested(); + std::lock_guard l(mMountOperationLock); - auto status = mVold->setIncFsMountOptions(control, enableReadLogs); + auto status = mVold->setIncFsMountOptions(control, enableReadLogs, enableReadTimeouts); if (status.isOk()) { - // Store enabled state. + // Store states. ifs.setReadLogsEnabled(enableReadLogs); + ifs.setReadTimeoutsEnabled(enableReadTimeouts); } else { LOG(ERROR) << "applyStorageParams failed: " << status.toString8(); } @@ -1271,7 +1292,7 @@ void IncrementalService::setUidReadTimeouts(StorageId storage, maxPendingTimeUs = std::max(maxPendingTimeUs, microseconds(timeouts.maxPendingTimeUs)); } if (maxPendingTimeUs < Constants::minPerUidTimeout) { - LOG(ERROR) << "Skip setting read timeouts (maxPendingTime < Constants::minPerUidTimeout): " + LOG(ERROR) << "Skip setting read timeouts (maxPendingTime < Constants::minPerUidTimeout): " << duration_cast<milliseconds>(maxPendingTimeUs).count() << "ms < " << Constants::minPerUidTimeout.count() << "ms"; return; @@ -2946,8 +2967,10 @@ BootClockTsUs IncrementalService::DataLoaderStub::getOldestPendingReadTs() { return result; } - LOG(DEBUG) << id() << ": pendingReads: " << control.pendingReads() << ", " - << mLastPendingReads.size() << ": " << mLastPendingReads.front().bootClockTsUs; + LOG(DEBUG) << id() << ": pendingReads: fd(" << control.pendingReads() << "), count(" + << mLastPendingReads.size() << "), block: " << mLastPendingReads.front().block + << ", time: " << mLastPendingReads.front().bootClockTsUs + << ", uid: " << mLastPendingReads.front().uid; return getOldestTsFromLastPendingReads(); } diff --git a/services/incremental/IncrementalService.h b/services/incremental/IncrementalService.h index fb6f56c9166e..e3b1e6fb6e48 100644 --- a/services/incremental/IncrementalService.h +++ b/services/incremental/IncrementalService.h @@ -118,6 +118,9 @@ public: ReadLogsAllowed = 1 << 0, ReadLogsEnabled = 1 << 1, ReadLogsRequested = 1 << 2, + + ReadTimeoutsEnabled = 1 << 3, + ReadTimeoutsRequested = 1 << 4, }; struct LoadingProgress { @@ -160,6 +163,7 @@ public: const StorageHealthCheckParams& healthCheckParams, StorageHealthListener healthListener, std::vector<PerUidReadTimeouts> perUidReadTimeouts); + void onInstallationComplete(StorageId storage); int bind(StorageId storage, std::string_view source, std::string_view target, BindKind kind); int unbind(StorageId storage, std::string_view target); @@ -316,7 +320,7 @@ private: } mHealthBase = {TimePoint::max(), kMaxBootClockTsUs}; StorageHealthCheckParams mHealthCheckParams; int mStreamStatus = content::pm::IDataLoaderStatusListener::STREAM_HEALTHY; - std::vector<incfs::ReadInfo> mLastPendingReads; + std::vector<incfs::ReadInfoWithUid> mLastPendingReads; }; using DataLoaderStubPtr = sp<DataLoaderStub>; @@ -364,13 +368,32 @@ private: void disallowReadLogs() { flags &= ~StorageFlags::ReadLogsAllowed; } int32_t readLogsAllowed() const { return (flags & StorageFlags::ReadLogsAllowed); } - void setReadLogsEnabled(bool value); + void setReadLogsEnabled(bool value) { + return setFlag(StorageFlags::ReadLogsEnabled, value); + } int32_t readLogsEnabled() const { return (flags & StorageFlags::ReadLogsEnabled); } - void setReadLogsRequested(bool value); + void setReadLogsRequested(bool value) { + return setFlag(StorageFlags::ReadLogsRequested, value); + } int32_t readLogsRequested() const { return (flags & StorageFlags::ReadLogsRequested); } + void setReadTimeoutsEnabled(bool value) { + return setFlag(StorageFlags::ReadTimeoutsEnabled, value); + } + int32_t readTimeoutsEnabled() const { return (flags & StorageFlags::ReadTimeoutsEnabled); } + + void setReadTimeoutsRequested(bool value) { + return setFlag(StorageFlags::ReadTimeoutsRequested, value); + } + int32_t readTimeoutsRequested() const { + return (flags & StorageFlags::ReadTimeoutsRequested); + } + static void cleanupFilesystem(std::string_view root); + + private: + void setFlag(StorageFlags flag, bool value); }; using IfsMountPtr = std::shared_ptr<IncFsMount>; @@ -422,7 +445,7 @@ private: int makeDirs(const IncFsMount& ifs, StorageId storageId, std::string_view path, int mode); int disableReadLogsLocked(IncFsMount& ifs); - int applyStorageParamsLocked(IncFsMount& ifs, bool enableReadLogs); + int applyStorageParamsLocked(IncFsMount& ifs); LoadingProgress getLoadingProgressFromPath(const IncFsMount& ifs, std::string_view path) const; diff --git a/services/incremental/ServiceWrappers.cpp b/services/incremental/ServiceWrappers.cpp index 8e416f36f49e..0755a22ab2ea 100644 --- a/services/incremental/ServiceWrappers.cpp +++ b/services/incremental/ServiceWrappers.cpp @@ -55,8 +55,8 @@ public: } binder::Status setIncFsMountOptions( const ::android::os::incremental::IncrementalFileSystemControlParcel& control, - bool enableReadLogs) const final { - return mInterface->setIncFsMountOptions(control, enableReadLogs); + bool enableReadLogs, bool enableReadTimeouts) const final { + return mInterface->setIncFsMountOptions(control, enableReadLogs, enableReadTimeouts); } private: @@ -233,8 +233,9 @@ public: ErrorCode reserveSpace(const Control& control, FileId id, IncFsSize size) const final { return incfs::reserveSpace(control, id, size); } - WaitResult waitForPendingReads(const Control& control, std::chrono::milliseconds timeout, - std::vector<incfs::ReadInfo>* pendingReadsBuffer) const final { + WaitResult waitForPendingReads( + const Control& control, std::chrono::milliseconds timeout, + std::vector<incfs::ReadInfoWithUid>* pendingReadsBuffer) const final { return incfs::waitForPendingReads(control, timeout, pendingReadsBuffer); } ErrorCode setUidReadTimeouts(const Control& control, diff --git a/services/incremental/ServiceWrappers.h b/services/incremental/ServiceWrappers.h index d4cdcbe9cac0..78e9589e63ff 100644 --- a/services/incremental/ServiceWrappers.h +++ b/services/incremental/ServiceWrappers.h @@ -56,8 +56,8 @@ public: virtual binder::Status bindMount(const std::string& sourceDir, const std::string& targetDir) const = 0; virtual binder::Status setIncFsMountOptions( - const os::incremental::IncrementalFileSystemControlParcel& control, - bool enableReadLogs) const = 0; + const os::incremental::IncrementalFileSystemControlParcel& control, bool enableReadLogs, + bool enableReadTimeouts) const = 0; }; class DataLoaderManagerWrapper { @@ -117,7 +117,7 @@ public: virtual ErrorCode reserveSpace(const Control& control, FileId id, IncFsSize size) const = 0; virtual WaitResult waitForPendingReads( const Control& control, std::chrono::milliseconds timeout, - std::vector<incfs::ReadInfo>* pendingReadsBuffer) const = 0; + std::vector<incfs::ReadInfoWithUid>* pendingReadsBuffer) const = 0; virtual ErrorCode setUidReadTimeouts( const Control& control, const std::vector<::android::os::incremental::PerUidReadTimeouts>& perUidReadTimeouts) diff --git a/services/incremental/test/IncrementalServiceTest.cpp b/services/incremental/test/IncrementalServiceTest.cpp index 1ec446dff6a3..14bcd4e7b9ba 100644 --- a/services/incremental/test/IncrementalServiceTest.cpp +++ b/services/incremental/test/IncrementalServiceTest.cpp @@ -56,10 +56,10 @@ public: MOCK_CONST_METHOD1(unmountIncFs, binder::Status(const std::string& dir)); MOCK_CONST_METHOD2(bindMount, binder::Status(const std::string& sourceDir, const std::string& argetDir)); - MOCK_CONST_METHOD2( + MOCK_CONST_METHOD3( setIncFsMountOptions, binder::Status(const ::android::os::incremental::IncrementalFileSystemControlParcel&, - bool)); + bool, bool)); void mountIncFsFails() { ON_CALL(*this, mountIncFs(_, _, _, _)) @@ -83,12 +83,13 @@ public: ON_CALL(*this, bindMount(_, _)).WillByDefault(Return(binder::Status::ok())); } void setIncFsMountOptionsFails() const { - ON_CALL(*this, setIncFsMountOptions(_, _)) + ON_CALL(*this, setIncFsMountOptions(_, _, _)) .WillByDefault(Return( binder::Status::fromExceptionCode(1, String8("failed to set options")))); } void setIncFsMountOptionsSuccess() { - ON_CALL(*this, setIncFsMountOptions(_, _)).WillByDefault(Return(binder::Status::ok())); + ON_CALL(*this, setIncFsMountOptions(_, _, _)) + .WillByDefault(Invoke(this, &MockVoldService::setIncFsMountOptionsOk)); } binder::Status getInvalidControlParcel(const std::string& imagePath, const std::string& targetDir, int32_t flags, @@ -103,10 +104,23 @@ public: _aidl_return->log.reset(base::unique_fd(dup(STDIN_FILENO))); return binder::Status::ok(); } + binder::Status setIncFsMountOptionsOk( + const ::android::os::incremental::IncrementalFileSystemControlParcel& control, + bool enableReadLogs, bool enableReadTimeouts) { + mReadLogsEnabled = enableReadLogs; + mReadTimeoutsEnabled = enableReadTimeouts; + return binder::Status::ok(); + } + + bool readLogsEnabled() const { return mReadLogsEnabled; } + bool readTimeoutsEnabled() const { return mReadTimeoutsEnabled; } private: TemporaryFile cmdFile; TemporaryFile logFile; + + bool mReadLogsEnabled = false; + bool mReadTimeoutsEnabled = true; }; class MockDataLoader : public IDataLoader { @@ -395,7 +409,7 @@ public: MOCK_CONST_METHOD3(reserveSpace, ErrorCode(const Control& control, FileId id, IncFsSize size)); MOCK_CONST_METHOD3(waitForPendingReads, WaitResult(const Control& control, std::chrono::milliseconds timeout, - std::vector<incfs::ReadInfo>* pendingReadsBuffer)); + std::vector<incfs::ReadInfoWithUid>* pendingReadsBuffer)); MOCK_CONST_METHOD2(setUidReadTimeouts, ErrorCode(const Control& control, const std::vector<PerUidReadTimeouts>& perUidReadTimeouts)); @@ -435,7 +449,7 @@ public: ON_CALL(*this, waitForPendingReads(_, _, _)) .WillByDefault( Invoke([ts](const Control& control, std::chrono::milliseconds timeout, - std::vector<incfs::ReadInfo>* pendingReadsBuffer) { + std::vector<incfs::ReadInfoWithUid>* pendingReadsBuffer) { pendingReadsBuffer->push_back({.bootClockTsUs = ts}); return android::incfs::WaitResult::HaveData; })); @@ -1302,8 +1316,10 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccess) { EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); + // on startLoading + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(1); // We are calling setIncFsMountOptions(true). - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(1); // After setIncFsMountOptions succeeded expecting to start watching. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); // Not expecting callback removal. @@ -1325,8 +1341,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndDisabled) { EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // Enabling and then disabling readlogs. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); - EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(2); // After setIncFsMountOptions succeeded expecting to start watching. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); // Not expecting callback removal. @@ -1353,8 +1369,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndTimedOut) { EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // Enabling and then disabling readlogs. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(2); - EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(2); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(2); // After setIncFsMountOptions succeeded expecting to start watching. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); // Not expecting callback removal. @@ -1394,8 +1410,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndNoTimedOutForSy EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // Enabling and then disabling readlogs. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(3); - EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(0); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(3); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(1); // After setIncFsMountOptions succeeded expecting to start watching. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); // Not expecting callback removal. @@ -1435,8 +1451,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndNewInstall) { EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(2); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // Enabling and then disabling readlogs. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(3); - EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(5); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(3); // After setIncFsMountOptions succeeded expecting to start watching. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); // Not expecting callback removal. @@ -1448,9 +1464,14 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndNewInstall) { IncrementalService::CreateOptions::CreateNew); ASSERT_GE(storageId, 0); + // Before install - long timeouts. + ASSERT_TRUE(mVold->readTimeoutsEnabled()); + auto dataLoaderParcel = mDataLoaderParcel; ASSERT_TRUE(mIncrementalService->startLoading(storageId, std::move(dataLoaderParcel), {}, {}, {}, {})); + // During install - short timeouts. + ASSERT_FALSE(mVold->readTimeoutsEnabled()); // Disable readlogs callback present. ASSERT_EQ(storageId, mTimedQueue->mId); @@ -1463,9 +1484,15 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndNewInstall) { mClock->advance(90min); ASSERT_GE(mDataLoader->setStorageParams(true), 0); + mIncrementalService->onInstallationComplete(storageId); + // After install - long timeouts. + ASSERT_TRUE(mVold->readTimeoutsEnabled()); + // New installation. ASSERT_TRUE(mIncrementalService->startLoading(storageId, std::move(mDataLoaderParcel), {}, {}, {}, {})); + // New installation - short timeouts. + ASSERT_FALSE(mVold->readTimeoutsEnabled()); // New callback present. ASSERT_EQ(storageId, mTimedQueue->mId); @@ -1485,6 +1512,10 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndNewInstall) { // And timeout. mClock->advance(90min); ASSERT_EQ(mDataLoader->setStorageParams(true), -EPERM); + + mIncrementalService->onInstallationComplete(storageId); + // After install - long timeouts. + ASSERT_TRUE(mVold->readTimeoutsEnabled()); } TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndPermissionChanged) { @@ -1495,9 +1526,9 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndPermissionChang EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // We are calling setIncFsMountOptions(true). - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(1); // setIncFsMountOptions(false) is called on the callback. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(2); // After setIncFsMountOptions succeeded expecting to start watching. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); // After callback is called, disable read logs and remove callback. @@ -1520,7 +1551,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsCheckPermissionFails) { EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // checkPermission fails, no calls to set opitions, start or stop WatchingMode. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(0); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(0); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(1); EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0); EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0); TemporaryDir tempDir; @@ -1539,7 +1571,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsCheckPermissionNoCrossUse EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // checkPermission fails, no calls to set opitions, start or stop WatchingMode. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(0); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(0); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(1); EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0); EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0); TemporaryDir tempDir; @@ -1559,7 +1592,8 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsFails) { EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); // We are calling setIncFsMountOptions. - EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, true, _)).Times(1); + EXPECT_CALL(*mVold, setIncFsMountOptions(_, false, _)).Times(1); // setIncFsMountOptions fails, no calls to start or stop WatchingMode. EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0); EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0); |