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

Commit 7d1977d1 authored by Jared Duke's avatar Jared Duke
Browse files

Optimize SystemConfig feature parsing

A number of system features are dependent on global system properties,
as opposed to the usual XML feature sources. Currently, these are read
and applied redundantly for every different XML permission source. This
is unnecessary.

Instead, simply read and apply these features once, after all other
permissions have been parsed. This saves ~10ms on a recent phone
and up to ~100ms on more resource-constrained devices (e.g., Wear).


Flag: EXEMPT refactor
Test: presubmit
Bug: 203143243
Change-Id: I76ba9626e9fb67a4822aacb438277f7fd708907d
parent b1071dc6
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -670,6 +670,17 @@ public class SystemConfig {
    }

    private void readAllPermissions() {
        readAllPermissionsFromXml();
        readAllPermissionsFromEnvironment();

        // Apply global feature removal last, after all features have been read.
        // This only needs to happen once.
        for (String featureName : mUnavailableFeatures) {
            removeFeature(featureName);
        }
    }

    private void readAllPermissionsFromXml() {
        final XmlPullParser parser = Xml.newPullParser();

        // Read configuration from system
@@ -1732,7 +1743,13 @@ public class SystemConfig {
        } finally {
            IoUtils.closeQuietly(permReader);
        }
    }

    // Add features or permission dependent on global system properties (as
    // opposed to XML permission files).
    // This only needs to be called once after all features have been parsed
    // from various partition/apex sources.
    private void readAllPermissionsFromEnvironment() {
        // Some devices can be field-converted to FBE, so offer to splice in
        // those features if not already defined by the static config
        if (StorageManager.isFileEncrypted()) {
@@ -1773,10 +1790,6 @@ public class SystemConfig {
                addFeature(PackageManager.FEATURE_EROFS_LEGACY, 0);
            }
        }

        for (String featureName : mUnavailableFeatures) {
            removeFeature(featureName);
        }
    }

    private @Nullable SignedPackage parseEnhancedConfirmationTrustedPackage(XmlPullParser parser,