Loading services/core/java/com/android/server/integrity/IntegrityFileManager.java +4 −0 Original line number Diff line number Diff line Loading @@ -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(); } } } Loading services/tests/servicestests/src/com/android/server/integrity/IntegrityFileManagerTest.java +38 −25 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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) Loading @@ -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(); } } Loading
services/core/java/com/android/server/integrity/IntegrityFileManager.java +4 −0 Original line number Diff line number Diff line Loading @@ -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(); } } } Loading
services/tests/servicestests/src/com/android/server/integrity/IntegrityFileManagerTest.java +38 −25 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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) Loading @@ -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(); } }