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

Commit d77145bd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Delete the staging directory after rule push finishes."

parents d26218b6 95de69d7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -185,6 +185,10 @@ public class IntegrityFileManager {
                    && tmpDir.renameTo(mStagingDir))) {
                throw new IOException("Error switching staging/rules directory");
            }

            for (File file : mStagingDir.listFiles()) {
                file.delete();
            }
        }
    }

+38 −25
Original line number Diff line number Diff line
@@ -135,7 +135,8 @@ public class IntegrityFileManagerTest {
                Arrays.asList(packageNameRule, packageCertRule, versionCodeRule, randomRule);
        mIntegrityFileManager.writeRules(VERSION, RULE_PROVIDER, rules);

        AppInstallMetadata appInstallMetadata = new AppInstallMetadata.Builder()
        AppInstallMetadata appInstallMetadata =
                new AppInstallMetadata.Builder()
                        .setPackageName(packageName)
                        .setAppCertificate(packageCert)
                        .setVersionCode(version)
@@ -174,7 +175,8 @@ public class IntegrityFileManagerTest {
        // Read the rules for a specific rule.
        String installedPackageName = String.format("%s%04d", packageName, 264);
        String installedAppCertificate = String.format("%s%04d", appCertificate, 1264);
        AppInstallMetadata appInstallMetadata = new AppInstallMetadata.Builder()
        AppInstallMetadata appInstallMetadata =
                new AppInstallMetadata.Builder()
                        .setPackageName(installedPackageName)
                        .setAppCertificate(installedAppCertificate)
                        .setVersionCode(250)
@@ -195,27 +197,38 @@ public class IntegrityFileManagerTest {
    private Rule getPackageNameIndexedRule(String packageName) {
        return new Rule(
                new StringAtomicFormula(
                        AtomicFormula.PACKAGE_NAME,
                        packageName,
                        /* isHashedValue= */ false),
                        AtomicFormula.PACKAGE_NAME, packageName, /* isHashedValue= */ false),
                Rule.DENY);
    }

    private Rule getAppCertificateIndexedRule(String appCertificate) {
        return new Rule(
                new StringAtomicFormula(
                        AtomicFormula.APP_CERTIFICATE,
                        appCertificate,
                        /* isHashedValue= */ false),
                        AtomicFormula.APP_CERTIFICATE, appCertificate, /* isHashedValue= */ false),
                Rule.DENY);
    }

    private Rule getInstallerCertificateRule(String installerCert) {
        return new Rule(
                new StringAtomicFormula(
                        AtomicFormula.INSTALLER_NAME,
                        installerCert,
                        /* isHashedValue= */ false),
                        AtomicFormula.INSTALLER_NAME, installerCert, /* isHashedValue= */ false),
                Rule.DENY);
    }

    @Test
    public void testStagingDirectoryCleared() throws Exception {
        // We must push rules two times to ensure that staging directory is empty because we cleared
        // it, rather than because original rules directory is empty.
        mIntegrityFileManager.writeRules(VERSION, RULE_PROVIDER, Collections.EMPTY_LIST);
        mIntegrityFileManager.writeRules(VERSION, RULE_PROVIDER, Collections.EMPTY_LIST);

        assertStagingDirectoryCleared();
    }

    private void assertStagingDirectoryCleared() {
        File stagingDir = new File(mTmpDir, "integrity_staging");
        assertThat(stagingDir.exists()).isTrue();
        assertThat(stagingDir.isDirectory()).isTrue();
        assertThat(stagingDir.listFiles()).isEmpty();
    }
}