Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06a6184d authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Fix profile disk space accounting bugs.

Profile data is only stored on internal storage (it doesn't move to
adoptable devices), so only count it when asking about internal
storage (which has a null UUID).

Also fix bug where "current" profile data was being double-counted
for apps.

Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java
Bug: 36102172, 36101738
Change-Id: I22b82e8cfb3bf1be1155fb827a538c21f09d88eb
parent 11c1acc3
Loading
Loading
Loading
Loading
+48 −36
Original line number Diff line number Diff line
@@ -1395,12 +1395,16 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri
            collectManualStats(dePath, &stats);
            ATRACE_END();

            if (!uuid) {
                ATRACE_BEGIN("profiles");
            auto userProfilePath = create_primary_current_profile_package_dir_path(userId, pkgname);
            calculate_tree_size(userProfilePath, &stats.dataSize);
            auto refProfilePath = create_primary_reference_profile_package_dir_path(pkgname);
            calculate_tree_size(refProfilePath, &stats.codeSize);
                calculate_tree_size(
                        create_primary_current_profile_package_dir_path(userId, pkgname),
                        &stats.dataSize);
                calculate_tree_size(
                        create_primary_reference_profile_package_dir_path(pkgname),
                        &stats.codeSize);
                ATRACE_END();
            }

            ATRACE_BEGIN("external");
            auto extPath = create_data_media_package_path(uuid_, userId, "data", pkgname);
@@ -1410,16 +1414,16 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri
            ATRACE_END();
        }

        if (!uuid) {
            ATRACE_BEGIN("dalvik");
            int32_t sharedGid = multiuser_get_shared_gid(userId, appId);
            if (sharedGid != -1) {
                calculate_tree_size(create_data_dalvik_cache_path(), &stats.codeSize,
                        sharedGid, -1);
            }
        calculate_tree_size(create_primary_cur_profile_dir_path(userId), &stats.dataSize,
                multiuser_get_uid(userId, appId), -1);
            ATRACE_END();
        }
    }

    std::vector<int64_t> ret;
    ret.push_back(stats.codeSize);
@@ -1496,12 +1500,14 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr<std::str
        collectManualStatsForUser(dePath, &stats, true);
        ATRACE_END();

        if (!uuid) {
            ATRACE_BEGIN("profile");
            auto userProfilePath = create_primary_cur_profile_dir_path(userId);
            calculate_tree_size(userProfilePath, &stats.dataSize, -1, -1, true);
            auto refProfilePath = create_primary_ref_profile_dir_path();
            calculate_tree_size(refProfilePath, &stats.codeSize, -1, -1, true);
            ATRACE_END();
        }

        ATRACE_BEGIN("external");
        uid_t uid = multiuser_get_uid(userId, AID_MEDIA_RW);
@@ -1518,12 +1524,14 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr<std::str
        }
        ATRACE_END();

        if (!uuid) {
            ATRACE_BEGIN("dalvik");
            calculate_tree_size(create_data_dalvik_cache_path(), &stats.codeSize,
                    -1, -1, true);
            calculate_tree_size(create_primary_cur_profile_dir_path(userId), &stats.dataSize,
                    -1, -1, true);
            ATRACE_END();
        }

        ATRACE_BEGIN("quota");
        for (auto appId : appIds) {
@@ -1554,12 +1562,14 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr<std::str
        collectManualStatsForUser(dePath, &stats);
        ATRACE_END();

        if (!uuid) {
            ATRACE_BEGIN("profile");
            auto userProfilePath = create_primary_cur_profile_dir_path(userId);
            calculate_tree_size(userProfilePath, &stats.dataSize);
            auto refProfilePath = create_primary_ref_profile_dir_path();
            calculate_tree_size(refProfilePath, &stats.codeSize);
            ATRACE_END();
        }

        ATRACE_BEGIN("external");
        auto dataMediaPath = create_data_media_path(uuid_, userId);
@@ -1570,11 +1580,13 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr<std::str
#endif
        ATRACE_END();

        if (!uuid) {
            ATRACE_BEGIN("dalvik");
            calculate_tree_size(create_data_dalvik_cache_path(), &stats.codeSize);
            calculate_tree_size(create_primary_cur_profile_dir_path(userId), &stats.dataSize);
            ATRACE_END();
        }
    }

    std::vector<int64_t> ret;
    ret.push_back(stats.codeSize);