package m5;

import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;

/* loaded from: classes.dex */
public abstract class a {

    /* JADX INFO: Access modifiers changed from: private */
    /* renamed from: m5.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static class C0643a implements AutoCloseable {

        /* renamed from: p, reason: collision with root package name */
        final ContentProviderClient f28652p;

        C0643a(ContentProviderClient contentProviderClient) {
            this.f28652p = contentProviderClient;
        }

        @Override // java.lang.AutoCloseable
        public void close() {
            ContentProviderClient contentProviderClient = this.f28652p;
            if (contentProviderClient == null) {
                return;
            }
            contentProviderClient.close();
        }
    }

    private static C0643a a(ContentResolver contentResolver, Uri uri) {
        ContentProviderClient acquireUnstableContentProviderClient = contentResolver.acquireUnstableContentProviderClient(uri);
        if (acquireUnstableContentProviderClient != null) {
            return new C0643a(acquireUnstableContentProviderClient);
        }
        throw new IllegalArgumentException("No provider found for " + uri);
    }

    public static void b(Context context, String str, String str2, Uri uri) {
        try {
            C0643a a10 = a(context.getContentResolver(), uri);
            try {
                Bundle bundle = new Bundle();
                bundle.putParcelable("slice_uri", uri);
                bundle.putString("provider_pkg", str);
                bundle.putString("pkg", str2);
                a10.f28652p.call("grant_perms", "supports_versioned_parcelable", bundle);
                a10.close();
            } finally {
            }
        } catch (RemoteException e10) {
            Log.e("SliceProviderCompat", "Unable to get slice descendants", e10);
        }
    }
}
