Loading cmds/installd/InstalldNativeService.cpp +1 −7 Original line number Diff line number Diff line Loading @@ -1455,7 +1455,7 @@ binder::Status InstalldNativeService::destroyUserData(const std::optional<std::s } binder::Status InstalldNativeService::freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags) { int64_t targetFreeBytes, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); Loading Loading @@ -1558,12 +1558,6 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string> break; } // Only keep clearing when we haven't pushed into reserved area if (cacheReservedBytes > 0 && cleared >= (cacheTotal - cacheReservedBytes)) { LOG(DEBUG) << "Refusing to clear cached data in reserved space"; break; } // Find the best tracker to work with; this might involve swapping // if the active tracker is no longer the most over quota bool nextBetter = active && !queue.empty() Loading cmds/installd/InstalldNativeService.h +1 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ public: binder::Status rmPackageDir(const std::string& packageDir); binder::Status freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags); int32_t flags); binder::Status linkNativeLibraryDirectory(const std::optional<std::string>& uuid, const std::string& packageName, const std::string& nativeLibPath32, int32_t userId); binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet); Loading cmds/installd/binder/android/os/IInstalld.aidl +1 −2 Original line number Diff line number Diff line Loading @@ -86,8 +86,7 @@ interface IInstalld { void destroyProfileSnapshot(@utf8InCpp String packageName, @utf8InCpp String profileName); void rmPackageDir(@utf8InCpp String packageDir); void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes, long cacheReservedBytes, int flags); void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes, int flags); void linkNativeLibraryDirectory(@nullable @utf8InCpp String uuid, @utf8InCpp String packageName, @utf8InCpp String nativeLibPath32, int userId); void createOatDir(@utf8InCpp String oatDir, @utf8InCpp String instructionSet); Loading cmds/installd/tests/installd_cache_test.cpp +35 −8 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ TEST_F(CacheTest, FreeCache_All) { EXPECT_EQ(0, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, kTbInBytes, 0, service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(0, exists("com.example/normal")); Loading @@ -153,6 +153,33 @@ TEST_F(CacheTest, FreeCache_All) { EXPECT_EQ(-1, exists("com.example/cache/foo/two")); } TEST_F(CacheTest, FreeCache_NonAggressive) { LOG(INFO) << "FreeCache_NonAggressive"; mkdir("com.example"); touch("com.example/normal", 1 * kMbInBytes, 60); mkdir("com.example/cache"); mkdir("com.example/cache/foo"); touch("com.example/cache/foo/one", 65 * kMbInBytes, 60); touch("com.example/cache/foo/two", 2 * kMbInBytes, 120); EXPECT_EQ(0, exists("com.example/normal")); EXPECT_EQ(0, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2); EXPECT_EQ(0, exists("com.example/normal")); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2); EXPECT_EQ(0, exists("com.example/normal")); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); } TEST_F(CacheTest, FreeCache_Age) { LOG(INFO) << "FreeCache_Age"; Loading @@ -162,13 +189,13 @@ TEST_F(CacheTest, FreeCache_Age) { touch("com.example/cache/foo/one", kMbInBytes, 60); touch("com.example/cache/foo/two", kMbInBytes, 120); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); Loading Loading @@ -196,7 +223,7 @@ TEST_F(CacheTest, FreeCache_Tombstone) { EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar1")); EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar2")); service->freeCache(testUuid, kTbInBytes, 0, service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/foo1")); Loading @@ -218,7 +245,7 @@ TEST_F(CacheTest, FreeCache_Group) { setxattr("com.example/cache/foo", "user.cache_group"); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/foo1")); Loading Loading @@ -263,7 +290,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) { setxattr("com.example/cache/tomb", "user.cache_tombstone"); setxattr("com.example/cache/tomb/group", "user.cache_group"); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(kMbInBytes, size("com.example/cache/group/file1")); Loading @@ -284,7 +311,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) { EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1")); EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2")); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, size("com.example/cache/group/file1")); Loading @@ -305,7 +332,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) { EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1")); EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2")); service->freeCache(testUuid, kTbInBytes, 0, service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, size("com.example/cache/group/file1")); Loading Loading
cmds/installd/InstalldNativeService.cpp +1 −7 Original line number Diff line number Diff line Loading @@ -1455,7 +1455,7 @@ binder::Status InstalldNativeService::destroyUserData(const std::optional<std::s } binder::Status InstalldNativeService::freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags) { int64_t targetFreeBytes, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); Loading Loading @@ -1558,12 +1558,6 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string> break; } // Only keep clearing when we haven't pushed into reserved area if (cacheReservedBytes > 0 && cleared >= (cacheTotal - cacheReservedBytes)) { LOG(DEBUG) << "Refusing to clear cached data in reserved space"; break; } // Find the best tracker to work with; this might involve swapping // if the active tracker is no longer the most over quota bool nextBetter = active && !queue.empty() Loading
cmds/installd/InstalldNativeService.h +1 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ public: binder::Status rmPackageDir(const std::string& packageDir); binder::Status freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags); int32_t flags); binder::Status linkNativeLibraryDirectory(const std::optional<std::string>& uuid, const std::string& packageName, const std::string& nativeLibPath32, int32_t userId); binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet); Loading
cmds/installd/binder/android/os/IInstalld.aidl +1 −2 Original line number Diff line number Diff line Loading @@ -86,8 +86,7 @@ interface IInstalld { void destroyProfileSnapshot(@utf8InCpp String packageName, @utf8InCpp String profileName); void rmPackageDir(@utf8InCpp String packageDir); void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes, long cacheReservedBytes, int flags); void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes, int flags); void linkNativeLibraryDirectory(@nullable @utf8InCpp String uuid, @utf8InCpp String packageName, @utf8InCpp String nativeLibPath32, int userId); void createOatDir(@utf8InCpp String oatDir, @utf8InCpp String instructionSet); Loading
cmds/installd/tests/installd_cache_test.cpp +35 −8 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ TEST_F(CacheTest, FreeCache_All) { EXPECT_EQ(0, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, kTbInBytes, 0, service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(0, exists("com.example/normal")); Loading @@ -153,6 +153,33 @@ TEST_F(CacheTest, FreeCache_All) { EXPECT_EQ(-1, exists("com.example/cache/foo/two")); } TEST_F(CacheTest, FreeCache_NonAggressive) { LOG(INFO) << "FreeCache_NonAggressive"; mkdir("com.example"); touch("com.example/normal", 1 * kMbInBytes, 60); mkdir("com.example/cache"); mkdir("com.example/cache/foo"); touch("com.example/cache/foo/one", 65 * kMbInBytes, 60); touch("com.example/cache/foo/two", 2 * kMbInBytes, 120); EXPECT_EQ(0, exists("com.example/normal")); EXPECT_EQ(0, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2); EXPECT_EQ(0, exists("com.example/normal")); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2); EXPECT_EQ(0, exists("com.example/normal")); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); } TEST_F(CacheTest, FreeCache_Age) { LOG(INFO) << "FreeCache_Age"; Loading @@ -162,13 +189,13 @@ TEST_F(CacheTest, FreeCache_Age) { touch("com.example/cache/foo/one", kMbInBytes, 60); touch("com.example/cache/foo/two", kMbInBytes, 120); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); EXPECT_EQ(0, exists("com.example/cache/foo/two")); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/one")); Loading Loading @@ -196,7 +223,7 @@ TEST_F(CacheTest, FreeCache_Tombstone) { EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar1")); EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar2")); service->freeCache(testUuid, kTbInBytes, 0, service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/foo1")); Loading @@ -218,7 +245,7 @@ TEST_F(CacheTest, FreeCache_Group) { setxattr("com.example/cache/foo", "user.cache_group"); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, exists("com.example/cache/foo/foo1")); Loading Loading @@ -263,7 +290,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) { setxattr("com.example/cache/tomb", "user.cache_tombstone"); setxattr("com.example/cache/tomb/group", "user.cache_group"); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(kMbInBytes, size("com.example/cache/group/file1")); Loading @@ -284,7 +311,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) { EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1")); EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2")); service->freeCache(testUuid, free() + kKbInBytes, 0, service->freeCache(testUuid, free() + kKbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, size("com.example/cache/group/file1")); Loading @@ -305,7 +332,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) { EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1")); EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2")); service->freeCache(testUuid, kTbInBytes, 0, service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA); EXPECT_EQ(-1, size("com.example/cache/group/file1")); Loading