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

Commit 2160e0fd authored by Winson's avatar Winson
Browse files

Return to direct mutation for Provider authority

The EffectiveProvider wrapper is incorrect. The fact that ComponentResolver
mutates the Provider instance is a required behavior, otherwise the authority
doesn't get propagated.

This causes queries to fail because the EffectiveProvider thinks the authority
should be null. This change reverts to the original behavior pre-refactor,
directly mutating the ParsedProvider instance.

Fixing this mutation will have to wait for a followup, unfortunately.

Bug: 146072648

Test: run test in linked bug that queries content providers
Test: manual verified failing case

Change-Id: Ief960bec3692d60e823a60734c2196ee6caeff7a
parent 703c18b1
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -768,6 +768,10 @@ public class ComponentParseUtils {
        protected PatternMatcher[] uriPermissionPatterns;
        protected PathPermission[] pathPermissions;

        public ParsedProvider(ParsedProvider other) {
            this.setFrom(other);
        }

        protected void setFrom(ParsedProvider other) {
            super.setFrom(other);
            this.exported = other.exported;
@@ -823,6 +827,10 @@ public class ComponentParseUtils {
            return authority;
        }

        public void setSyncable(boolean isSyncable) {
            this.isSyncable = isSyncable;
        }

        public boolean isSyncable() {
            return isSyncable;
        }
+8 −37
Original line number Diff line number Diff line
@@ -627,11 +627,13 @@ public class ComponentResolver {
        final int providersSize = ArrayUtils.size(pkg.getProviders());
        StringBuilder r = null;
        for (int i = 0; i < providersSize; i++) {
            EffectiveProvider p = new EffectiveProvider(pkg.getProviders().get(i));
            ParsedProvider p = pkg.getProviders().get(i);
            mProviders.addProvider(p);
            if (p.getAuthority() != null) {
                String[] names = p.getAuthority().split(";");
                p.setEffectiveAuthority(null);

                // TODO(b/135203078): Remove this mutation
                p.setAuthority(null);
                for (int j = 0; j < names.length; j++) {
                    if (j == 1 && p.isSyncable()) {
                        // We only want the first authority for a provider to possibly be
@@ -641,15 +643,15 @@ public class ComponentResolver {
                        // to a provider that we don't want to change.
                        // Only do this for the second authority since the resulting provider
                        // object can be the same for all future authorities for this provider.
                        p = new EffectiveProvider(p);
                        p.setEffectiveSyncable(false);
                        p = new ParsedProvider(p);
                        p.setSyncable(false);
                    }
                    if (!mProvidersByAuthority.containsKey(names[j])) {
                        mProvidersByAuthority.put(names[j], p);
                        if (p.getAuthority() == null) {
                            p.setEffectiveAuthority(names[j]);
                            p.setAuthority(names[j]);
                        } else {
                            p.setEffectiveAuthority(p.getAuthority() + ";" + names[j]);
                            p.setAuthority(p.getAuthority() + ";" + names[j]);
                        }
                        if (DEBUG_PACKAGE_SCANNING && chatty) {
                            Log.d(TAG, "Registered content provider: " + names[j]
@@ -2113,35 +2115,4 @@ public class ComponentResolver {
            return info.authoritiesIterator();
        }
    }

    // TODO(b/135203078): Document or remove this if possible.
    class EffectiveProvider extends ParsedProvider {

        private String mEffectiveAuthority;
        private boolean mEffectiveSyncable;

        public EffectiveProvider(ParsedProvider parsedProvider) {
            this.setFrom(parsedProvider);
            this.mEffectiveAuthority = parsedProvider.getAuthority();
            this.mEffectiveSyncable = parsedProvider.isSyncable();
        }

        public void setEffectiveAuthority(String authority) {
            this.mEffectiveAuthority = authority;
        }

        public void setEffectiveSyncable(boolean syncable) {
            this.mEffectiveSyncable = syncable;
        }

        @Override
        public String getAuthority() {
            return mEffectiveAuthority;
        }

        @Override
        public boolean isSyncable() {
            return mEffectiveSyncable;
        }
    }
}