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

Commit 07bf36ad authored by Shikha Malhotra's avatar Shikha Malhotra Committed by Automerger Merge Worker
Browse files

Merge "Reverting the test as it might be failing other tests" am: a77b0791

parents ca77e2a7 a77b0791
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -474,7 +474,8 @@ static bool internal_storage_has_project_id() {
                StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
                StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
        sUsingProjectIdsFlag = access(using_project_ids.c_str(), F_OK) == 0;
        sUsingProjectIdsFlag = access(using_project_ids.c_str(), F_OK) == 0;
    });
    });
    return sUsingProjectIdsFlag;
    //    return sUsingProjectIdsFlag;
    return false;
}
}


static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t uid, gid_t gid,
static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t uid, gid_t gid,
+94 −91
Original line number Original line Diff line number Diff line
@@ -509,97 +509,100 @@ TEST_F(ServiceTest, GetAppSizeManualForMedia) {
        system(removeCommand.c_str());
        system(removeCommand.c_str());
    }
    }
}
}
TEST_F(ServiceTest, GetAppSizeProjectID_UID) {
// TEST_F(ServiceTest, GetAppSizeProjectID_UID) {
    struct stat s;
//     struct stat s;
    std::string externalPicDir =
//     std::string externalPicDir =
            StringPrintf("%s/Pictures", create_data_media_path(nullptr, 0).c_str());
//             StringPrintf("%s/Pictures", create_data_media_path(nullptr, 0).c_str());
    if (stat(externalPicDir.c_str(), &s) == 0) {
//     if (stat(externalPicDir.c_str(), &s) == 0) {
        // fetch the appId from the uid of the external storage owning app
//         // fetch the appId from the uid of the external storage owning app
        int32_t externalStorageAppId = multiuser_get_app_id(s.st_uid);
//         int32_t externalStorageAppId = multiuser_get_app_id(s.st_uid);
        // Fetch Package Name for the external storage owning app uid
//         // Fetch Package Name for the external storage owning app uid
        std::string pkg = get_package_name(s.st_uid);
//         std::string pkg = get_package_name(s.st_uid);

//
        std::vector<int64_t> externalStorageSize, externalStorageSizeAfterAddingCacheFile;
//         std::vector<int64_t> externalStorageSize, externalStorageSizeAfterAddingCacheFile;
        std::vector<int64_t> ceDataInodes;
//         std::vector<int64_t> ceDataInodes;

//
        std::vector<std::string> codePaths;
//         std::vector<std::string> codePaths;
        std::vector<std::string> packageNames;
//         std::vector<std::string> packageNames;
        // set up parameters
//         // set up parameters
        packageNames.push_back(pkg);
//         packageNames.push_back(pkg);
        ceDataInodes.push_back(0);
//         ceDataInodes.push_back(0);
        // initialise the mounts
//         // initialise the mounts
        service->invalidateMounts();
//         service->invalidateMounts();
        auto using_project_ids =
//         auto using_project_ids =
                StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
//                 StringPrintf("%smisc/installd/using_project_ids", android_data_dir.c_str());
        bool usingProjectIds = access(using_project_ids.c_str(), F_OK) == 0;
//         bool usingProjectIds = access(using_project_ids.c_str(), F_OK) == 0;
        if (!usingProjectIds) {
//         if (!usingProjectIds) {
            service->setFirstBoot();
//             service->setFirstBoot();
        }
//         }

//
        if (access(using_project_ids.c_str(), F_OK) != 0) {
//         if (access(using_project_ids.c_str(), F_OK) != 0) {
            // projectids is not used, so check that ioctl features should be absent
//             // projectids is not used, so check that ioctl features should be absent
            auto temp_path = StringPrintf("%smisc/installd/ioctl_check", android_data_dir.c_str());
//             auto temp_path = StringPrintf("%smisc/installd/ioctl_check",

//             android_data_dir.c_str());
            if (access(temp_path.c_str(), F_OK) != 0) {
//
                open(temp_path.c_str(), O_CREAT | O_TRUNC | O_RDWR | O_CLOEXEC, 0644);
//             if (access(temp_path.c_str(), F_OK) != 0) {
                bool result = set_quota_project_id(temp_path, 0, false) == 0;
//                 open(temp_path.c_str(), O_CREAT | O_TRUNC | O_RDWR | O_CLOEXEC, 0644);
                // delete the temp file
//                 bool result = set_quota_project_id(temp_path, 0, false) == 0;
                // remove the external file
//                 // delete the temp file
                remove(temp_path.c_str());
//                 // remove the external file
                // since using_project_ids file is not present, so ioctl settings should be absent
//                 remove(temp_path.c_str());
                //  that is denoted by the result of setting project id flag as false
//                 // since using_project_ids file is not present, so ioctl settings should be
                ASSERT_FALSE(result);
//                 absent
            }
//                 //  that is denoted by the result of setting project id flag as false
        }
//                 ASSERT_FALSE(result);
        // call the getAppSize to get the current size of the external storage owning app
//             }
        service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
//         }
                            externalStorageAppId, ceDataInodes, codePaths, &externalStorageSize);
//         // call the getAppSize to get the current size of the external storage owning app
        // add a file with 20MB size to the external storage
//         service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
        std::string externalStorageCacheDir =
//                             externalStorageAppId, ceDataInodes, codePaths, &externalStorageSize);
                StringPrintf("%s/%s/cache", create_data_user_ce_path(nullptr, 0).c_str(),
//         // add a file with 20MB size to the external storage
                             pkg.c_str());
//         std::string externalStorageCacheDir =
        std::string cacheFileLocation =
//                 StringPrintf("%s/%s/cache", create_data_user_ce_path(nullptr, 0).c_str(),
                StringPrintf("%s/%s", externalStorageCacheDir.c_str(), "External.jpg");
//                              pkg.c_str());
        std::string externalFileContentCommand =
//         std::string cacheFileLocation =
                StringPrintf("dd if=/dev/zero of=%s bs=1M count=20", cacheFileLocation.c_str());
//                 StringPrintf("%s/%s", externalStorageCacheDir.c_str(), "External.jpg");
        system(externalFileContentCommand.c_str());
//         std::string externalFileContentCommand =
        // call the getAppSize again to get the new size of the external storage owning app
//                 StringPrintf("dd if=/dev/zero of=%s bs=1M count=20", cacheFileLocation.c_str());
        service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
//         system(externalFileContentCommand.c_str());
                            externalStorageAppId, ceDataInodes, codePaths,
//         // call the getAppSize again to get the new size of the external storage owning app
                            &externalStorageSizeAfterAddingCacheFile);
//         service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
        // check that the size of cache and data increases when cache file is added
//                             externalStorageAppId, ceDataInodes, codePaths,
        int64_t sizeDiffData = externalStorageSizeAfterAddingCacheFile[1] - externalStorageSize[1];
//                             &externalStorageSizeAfterAddingCacheFile);
        int64_t sizeDiffCache = externalStorageSizeAfterAddingCacheFile[2] - externalStorageSize[2];
//         // check that the size of cache and data increases when cache file is added
        ASSERT_TRUE(sizeDiffData == sizeDiffCache);
//         int64_t sizeDiffData = externalStorageSizeAfterAddingCacheFile[1] -
        // remove the external file
//         externalStorageSize[1]; int64_t sizeDiffCache =
        std::string removeCommand = StringPrintf("rm -f %s", cacheFileLocation.c_str());
//         externalStorageSizeAfterAddingCacheFile[2] - externalStorageSize[2];
        system(removeCommand.c_str());
//         ASSERT_TRUE(sizeDiffData == sizeDiffCache);
        // remove the setFirstBoot setting
//         // remove the external file
        std::string removeCommand2 = "rm -f /data/misc/installd/using_project_ids";
//         std::string removeCommand = StringPrintf("rm -f %s", cacheFileLocation.c_str());
        system(removeCommand2.c_str());
//         system(removeCommand.c_str());
        // Do now without project id
//         // remove the setFirstBoot setting
        std::vector<int64_t> sizeWithUID, sizeWithUIDAfterAddingCacheFile;
//         std::string removeCommand2 = "rm -f /data/misc/installd/using_project_ids";
        // call the getAppSize to get the current size of the external storage owning app
//         system(removeCommand2.c_str());
        service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
//         // Do now without project id
                            externalStorageAppId, ceDataInodes, codePaths, &sizeWithUID);
//         std::vector<int64_t> sizeWithUID, sizeWithUIDAfterAddingCacheFile;
        // add a file with 20MB size to the external storage
//         // call the getAppSize to get the current size of the external storage owning app
        system(externalFileContentCommand.c_str());
//         service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
        // call the getAppSize again to get the new size of the external storage owning app
//                             externalStorageAppId, ceDataInodes, codePaths, &sizeWithUID);
        service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
//         // add a file with 20MB size to the external storage
                            externalStorageAppId, ceDataInodes, codePaths,
//         system(externalFileContentCommand.c_str());
                            &sizeWithUIDAfterAddingCacheFile);
//         // call the getAppSize again to get the new size of the external storage owning app
        // check that the size of cache and data increases when cache file is added
//         service->getAppSize(std::nullopt, packageNames, 0, InstalldNativeService::FLAG_USE_QUOTA,
        sizeDiffData = sizeWithUIDAfterAddingCacheFile[1] - sizeWithUID[1];
//                             externalStorageAppId, ceDataInodes, codePaths,
        sizeDiffCache = sizeWithUIDAfterAddingCacheFile[2] - sizeWithUID[2];
//                             &sizeWithUIDAfterAddingCacheFile);
        ASSERT_TRUE(sizeDiffData == sizeDiffCache);
//         // check that the size of cache and data increases when cache file is added
        // remove the external file
//         sizeDiffData = sizeWithUIDAfterAddingCacheFile[1] - sizeWithUID[1];
        system(removeCommand.c_str());
//         sizeDiffCache = sizeWithUIDAfterAddingCacheFile[2] - sizeWithUID[2];
        // reset the using_project_id if it was initially set
//         ASSERT_TRUE(sizeDiffData == sizeDiffCache);
        if (usingProjectIds) {
//         // remove the external file
            service->setFirstBoot();
//         system(removeCommand.c_str());
        }
//         // reset the using_project_id if it was initially set
    }
//         if (usingProjectIds) {
}
//             service->setFirstBoot();
//         }
//     }
// }
TEST_F(ServiceTest, GetAppSizeWrongSizes) {
TEST_F(ServiceTest, GetAppSizeWrongSizes) {
    int32_t externalStorageAppId = -1;
    int32_t externalStorageAppId = -1;
    std::vector<int64_t> externalStorageSize;
    std::vector<int64_t> externalStorageSize;