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

Commit 939d0188 authored by Takamasa Kuramitsu's avatar Takamasa Kuramitsu Committed by Steve McKay
Browse files

Fix crash when DocumentsProviders using duplicate authority exist

Files app crashes when loading roots if it failed to get provider info
from authority. This could be happen in case there're different
DocumentsProviders using the same authority.

Bug: 72474325
Test: Manual
Test: Run instrumentation tests from com.android.documentsui.tests
Change-Id: I17443f6cb00e7e784384166bd807c7065d5ee61b
(cherry picked from commit b0087a45b34823b65bee5afe879a1643acdc8fa4)
parent 91fa769d
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -241,8 +241,13 @@ public class ProvidersCache implements ProvidersAccess {
        if (VERBOSE) Log.v(TAG, "Loading roots for " + authority);

        final ArrayList<RootInfo> roots = new ArrayList<>();
        ProviderInfo provider = mContext.getPackageManager().resolveContentProvider(
        final PackageManager pm = mContext.getPackageManager();
        ProviderInfo provider = pm.resolveContentProvider(
                authority, PackageManager.GET_META_DATA);
        if (provider == null) {
            Log.w(TAG, "Failed to get provider info for " + authority);
            return roots;
        }
        if (!provider.exported) {
            Log.w(TAG, "Provider is not exported. Failed to load roots for " + authority);
            return roots;
@@ -261,7 +266,6 @@ public class ProvidersCache implements ProvidersAccess {

        synchronized (mObservedAuthoritiesDetails) {
            if (!mObservedAuthoritiesDetails.containsKey(authority)) {
                PackageManager pm = mContext.getPackageManager();
                CharSequence appName = pm.getApplicationLabel(provider.applicationInfo);
                String packageName = provider.applicationInfo.packageName;

@@ -460,7 +464,10 @@ public class ProvidersCache implements ProvidersAccess {
            final Intent intent = new Intent(DocumentsContract.PROVIDER_INTERFACE);
            final List<ResolveInfo> providers = pm.queryIntentContentProviders(intent, 0);
            for (ResolveInfo info : providers) {
                handleDocumentsProvider(info.providerInfo);
                ProviderInfo providerInfo = info.providerInfo;
                if (providerInfo.authority != null) {
                    handleDocumentsProvider(providerInfo);
                }
            }

            final long delta = SystemClock.elapsedRealtime() - start;