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

Commit 541a7710 authored by Song Pan's avatar Song Pan
Browse files

Fail early if we don't have any rules file on disk.

This saves the time for parsing the APK file when there are no rules. This
probably doesn't matter much in normal use cases but in test environments (e.g.,
see bug linked), where package verifier is disabled, this avoids the
performance (install time) regression introduced by integrity check.

BUG:146874731
Test: manual comparison of install latency through inspecting logcat.
Change-Id: I3d687486f34214ac61058908401649939560b4fb
parent 56dc6a4b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -196,6 +196,15 @@ public class AppIntegrityManagerServiceImpl extends IAppIntegrityManager.Stub {

    private void handleIntegrityVerification(Intent intent) {
        int verificationId = intent.getIntExtra(EXTRA_VERIFICATION_ID, -1);

        // Fail early if we don't have any rules at all.
        if (!mIntegrityFileManager.initialized()) {
            Slog.i(TAG, "Rules not initialized. Skipping integrity check.");
            mPackageManagerInternal.setIntegrityVerificationResult(
                    verificationId, PackageManagerInternal.INTEGRITY_VERIFICATION_ALLOW);
            return;
        }

        try {
            Slog.i(TAG, "Received integrity verification intent " + intent.toString());
            Slog.i(TAG, "Extras " + intent.getExtras());
+11 −4
Original line number Diff line number Diff line
@@ -74,10 +74,7 @@ public class IntegrityFileManager {
    }

    private IntegrityFileManager() {
        this(
                new RuleXmlParser(),
                new RuleXmlSerializer(),
                Environment.getDataSystemDirectory());
        this(new RuleXmlParser(), new RuleXmlSerializer(), Environment.getDataSystemDirectory());
    }

    @VisibleForTesting
@@ -103,6 +100,16 @@ public class IntegrityFileManager {
        }
    }

    /**
     * Returns if the rules have been initialized.
     *
     * <p>Used to fail early if there are no rules (so we don't need to parse the apk at all).
     */
    public boolean initialized() {
        return new File(mRulesDir, RULES_FILE).exists()
                && new File(mRulesDir, METADATA_FILE).exists();
    }

    /** Write rules to persistent storage. */
    public void writeRules(String version, String ruleProvider, List<Rule> rules)
            throws IOException, RuleSerializeException {