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

Commit ed18d9b9 authored by Calin Juravle's avatar Calin Juravle Committed by android-build-merger
Browse files

Allow public profile compilation for primary apks

am: 5bd1c725

Change-Id: I697aa3fba2576444a79a8cadd90674fb8d636bd3
parents 38e04ae7 5bd1c725
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -1327,9 +1327,21 @@ unique_fd maybe_open_dexopt_swap_file(const char* out_oat_path) {
Dex2oatFileWrapper maybe_open_reference_profile(const std::string& pkgname,
Dex2oatFileWrapper maybe_open_reference_profile(const std::string& pkgname,
        const std::string& dex_path, const char* profile_name, bool profile_guided,
        const std::string& dex_path, const char* profile_name, bool profile_guided,
        bool is_public, int uid, bool is_secondary_dex) {
        bool is_public, int uid, bool is_secondary_dex) {
    // Public apps should not be compiled with profile information ever. Same goes for the special
    // If we are not profile guided compilation, or we are compiling system server
    // package '*' used for the system server.
    // do not bother to open the profiles; we won't be using them.
    if (!profile_guided || is_public || (pkgname[0] == '*')) {
    if (!profile_guided || (pkgname[0] == '*')) {
        return Dex2oatFileWrapper();
    }

    // If this is a secondary dex path which is public do not open the profile.
    // We cannot compile public secondary dex paths with profiles. That's because
    // it will expose how the dex files are used by their owner.
    //
    // Note that the PackageManager is responsible to set the is_public flag for
    // primary apks and we do not check it here. In some cases, e.g. when
    // compiling with a public profile from the .dm file the PackageManager will
    // set is_public toghether with the profile guided compilation.
    if (is_secondary_dex && is_public) {
        return Dex2oatFileWrapper();
        return Dex2oatFileWrapper();
    }
    }


+18 −19
Original line number Original line Diff line number Diff line
@@ -405,15 +405,14 @@ protected:
        std::string vdex = GetPrimaryDexArtifact(oat_dir, apk_path_, "vdex");
        std::string vdex = GetPrimaryDexArtifact(oat_dir, apk_path_, "vdex");
        std::string art = GetPrimaryDexArtifact(oat_dir, apk_path_, "art");
        std::string art = GetPrimaryDexArtifact(oat_dir, apk_path_, "art");


        mode_t mode = S_IFREG | (compiler_filter == "speed-profile" ? 0640 : 0644);
        bool is_public = (dex_flags & DEXOPT_PUBLIC) != 0;
        mode_t mode = S_IFREG | (is_public ? 0644 : 0640);
        CheckFileAccess(odex, kSystemUid, uid, mode);
        CheckFileAccess(odex, kSystemUid, uid, mode);
        CheckFileAccess(vdex, kSystemUid, uid, mode);
        CheckFileAccess(vdex, kSystemUid, uid, mode);
        CheckFileAccess(odex, kSystemUid, uid, mode);


        // empty profiles do not generate an image.
        if (compiler_filter == "speed-profile") {
        // todo: add tests with non-empty profiles.
            CheckFileAccess(art, kSystemUid, uid, mode);
        struct stat st;
        }
        ASSERT_EQ(-1, stat(art.c_str(), &st));
    }
    }


    std::string GetPrimaryDexArtifact(const char* oat_dir,
    std::string GetPrimaryDexArtifact(const char* oat_dir,
@@ -490,10 +489,19 @@ TEST_F(DexoptTest, DexoptPrimaryPublic) {
                        DEX2OAT_FROM_SCRATCH);
                        DEX2OAT_FROM_SCRATCH);
}
}


TEST_F(DexoptTest, DexoptPrimaryFailedInvalidFilter) {
    LOG(INFO) << "DexoptPrimaryFailedInvalidFilter";
    CompilePrimaryDexFail("awesome-filter",
                          DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PUBLIC,
                          app_oat_dir_.c_str(),
                          kTestAppGid,
                          DEX2OAT_FROM_SCRATCH);
}

TEST_F(DexoptTest, DexoptPrimaryProfileNonPublic) {
TEST_F(DexoptTest, DexoptPrimaryProfileNonPublic) {
    LOG(INFO) << "DexoptPrimaryProfileNonPublic";
    LOG(INFO) << "DexoptPrimaryProfileNonPublic";
    CompilePrimaryDexOk("speed-profile",
    CompilePrimaryDexOk("speed-profile",
                        DEXOPT_BOOTCOMPLETE,
                        DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED,
                        app_oat_dir_.c_str(),
                        app_oat_dir_.c_str(),
                        kTestAppGid,
                        kTestAppGid,
                        DEX2OAT_FROM_SCRATCH);
                        DEX2OAT_FROM_SCRATCH);
@@ -501,8 +509,8 @@ TEST_F(DexoptTest, DexoptPrimaryProfileNonPublic) {


TEST_F(DexoptTest, DexoptPrimaryProfilePublic) {
TEST_F(DexoptTest, DexoptPrimaryProfilePublic) {
    LOG(INFO) << "DexoptPrimaryProfilePublic";
    LOG(INFO) << "DexoptPrimaryProfilePublic";
    CompilePrimaryDexOk("verify",
    CompilePrimaryDexOk("speed-profile",
                        DEXOPT_BOOTCOMPLETE | DEXOPT_PUBLIC,
                        DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_PUBLIC,
                        app_oat_dir_.c_str(),
                        app_oat_dir_.c_str(),
                        kTestAppGid,
                        kTestAppGid,
                        DEX2OAT_FROM_SCRATCH);
                        DEX2OAT_FROM_SCRATCH);
@@ -511,16 +519,7 @@ TEST_F(DexoptTest, DexoptPrimaryProfilePublic) {
TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) {
TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) {
    LOG(INFO) << "DexoptPrimaryBackgroundOk";
    LOG(INFO) << "DexoptPrimaryBackgroundOk";
    CompilePrimaryDexOk("speed-profile",
    CompilePrimaryDexOk("speed-profile",
                        DEXOPT_IDLE_BACKGROUND_JOB,
                        DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PROFILE_GUIDED,
                        app_oat_dir_.c_str(),
                        kTestAppGid,
                        DEX2OAT_FROM_SCRATCH);
}

TEST_F(DexoptTest, DexoptPrimaryFailedInvalidFilter) {
    LOG(INFO) << "DexoptPrimaryFailedInvalidFilter";
    CompilePrimaryDexFail("awesome-filter",
                          DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PUBLIC,
                        app_oat_dir_.c_str(),
                        app_oat_dir_.c_str(),
                        kTestAppGid,
                        kTestAppGid,
                        DEX2OAT_FROM_SCRATCH);
                        DEX2OAT_FROM_SCRATCH);