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

Commit 3ba061af authored by Ashish Kumar's avatar Ashish Kumar Committed by Ashish Kumar Gaurav
Browse files

Setting callingAttributionSource in getType and getStreamType

Test: build

Bug: b/274595210
Change-Id: I31d6c7e9786ad187a92a02e707180410a3c875d6
Merged-In: I31d6c7e9786ad187a92a02e707180410a3c875d6
parent 709879dc
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -302,10 +302,11 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall

        @Override
        public String getType(AttributionSource attributionSource, Uri uri) {
            // getCallingPackage() isn't available in getType(), as the javadoc states.
            uri = validateIncomingUri(uri);
            uri = maybeGetUriWithoutUserId(uri);
            traceBegin(TRACE_TAG_DATABASE, "getType: ", uri.getAuthority());
            final AttributionSource original = setCallingAttributionSource(
                    attributionSource);
            try {
                if (checkGetTypePermission(attributionSource, uri)
                        == PermissionChecker.PERMISSION_GRANTED) {
@@ -346,6 +347,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
            } catch (RemoteException e) {
                throw e.rethrowAsRuntimeException();
            } finally {
                setCallingAttributionSource(original);
                Trace.traceEnd(TRACE_TAG_DATABASE);
            }
        }
@@ -405,16 +407,20 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall

        @Override
        public void getTypeAnonymousAsync(Uri uri, RemoteCallback callback) {
            // getCallingPackage() isn't available in getTypeAnonymous(), as the javadoc states.
            uri = validateIncomingUri(uri);
            uri = maybeGetUriWithoutUserId(uri);
            traceBegin(TRACE_TAG_DATABASE, "getTypeAnonymous: ", uri.getAuthority());
            final Bundle result = new Bundle();
            try {
                result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getTypeAnonymous(uri));
            } catch (Exception e) {
                result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
                        new ParcelableException(e));
            }
            } finally {
                callback.sendResult(result);
                Trace.traceEnd(TRACE_TAG_DATABASE);
            }
        }

        @Override
@@ -629,16 +635,19 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
        }

        @Override
        public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
            // getCallingPackage() isn't available in getType(), as the javadoc states.
        public String[] getStreamTypes(AttributionSource attributionSource,
                Uri uri, String mimeTypeFilter) {
            uri = validateIncomingUri(uri);
            uri = maybeGetUriWithoutUserId(uri);
            traceBegin(TRACE_TAG_DATABASE, "getStreamTypes: ", uri.getAuthority());
            final AttributionSource original = setCallingAttributionSource(
                    attributionSource);
            try {
                return mInterface.getStreamTypes(uri, mimeTypeFilter);
            } catch (RemoteException e) {
                throw e.rethrowAsRuntimeException();
            } finally {
                setCallingAttributionSource(original);
                Trace.traceEnd(TRACE_TAG_DATABASE);
            }
        }
@@ -1114,7 +1123,10 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
     * currently processing a request.
     * <p>
     * This will always return {@code null} when processing
     * {@link #getType(Uri)} or {@link #getStreamTypes(Uri, String)} requests.
     * {@link #getTypeAnonymous(Uri)} requests
     *
     * For {@link #getType(Uri)}  requests, this will be only available for cases, where
     * the caller can be identified. See {@link #getTypeAnonymous(Uri)}
     *
     * @see Binder#getCallingUid()
     * @see Context#grantUriPermission(String, Uri, int)
@@ -1154,7 +1166,10 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
     * a request of the request is for the default attribution.
     * <p>
     * This will always return {@code null} when processing
     * {@link #getType(Uri)} or {@link #getStreamTypes(Uri, String)} requests.
     * {@link #getTypeAnonymous(Uri)} requests
     *
     * For {@link #getType(Uri)}  requests, this will be only available for cases, where
     * the caller can be identified. See {@link #getTypeAnonymous(Uri)}
     *
     * @see #getCallingPackage
     */
@@ -1181,7 +1196,10 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
     * {@code null} if not currently processing a request.
     * <p>
     * This will always return {@code null} when processing
     * {@link #getType(Uri)} or {@link #getStreamTypes(Uri, String)} requests.
     * {@link #getTypeAnonymous(Uri)} requests
     *
     * For {@link #getType(Uri)}  requests, this will be only available for cases, where
     * the caller can be identified. See {@link #getTypeAnonymous(Uri)}
     *
     * @see Binder#getCallingUid()
     * @see Context#grantUriPermission(String, Uri, int)
+2 −2
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ public class ContentProviderClient implements ContentInterface, AutoCloseable {

        beforeRemote();
        try {
            return mContentProvider.getType(url);
            return mContentProvider.getType(mAttributionSource, url);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
@@ -237,7 +237,7 @@ public class ContentProviderClient implements ContentInterface, AutoCloseable {

        beforeRemote();
        try {
            return mContentProvider.getStreamTypes(url, mimeTypeFilter);
            return mContentProvider.getStreamTypes(mAttributionSource, url, mimeTypeFilter);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
+6 −2
Original line number Diff line number Diff line
@@ -315,9 +315,11 @@ abstract public class ContentProviderNative extends Binder implements IContentPr
                case GET_STREAM_TYPES_TRANSACTION:
                {
                    data.enforceInterface(IContentProvider.descriptor);
                    AttributionSource attributionSource = AttributionSource.CREATOR
                            .createFromParcel(data);
                    Uri url = Uri.CREATOR.createFromParcel(data);
                    String mimeTypeFilter = data.readString();
                    String[] types = getStreamTypes(url, mimeTypeFilter);
                    String[] types = getStreamTypes(attributionSource, url, mimeTypeFilter);
                    reply.writeNoException();
                    reply.writeStringArray(types);

@@ -769,12 +771,14 @@ final class ContentProviderProxy implements IContentProvider
    }

    @Override
    public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException
    public String[] getStreamTypes(AttributionSource attributionSource,
            Uri url, String mimeTypeFilter) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        try {
            data.writeInterfaceToken(IContentProvider.descriptor);
            attributionSource.writeToParcel(data, 0);

            url.writeToParcel(data, 0);
            data.writeString(mimeTypeFilter);
+1 −1
Original line number Diff line number Diff line
@@ -1069,7 +1069,7 @@ public abstract class ContentResolver implements ContentInterface {
        }

        try {
            return provider.getStreamTypes(url, mimeTypeFilter);
            return provider.getStreamTypes(mContext.getAttributionSource(), url, mimeTypeFilter);
        } catch (RemoteException e) {
            // Arbitrary and not worth documenting, as Activity
            // Manager will kill this process shortly anyway.
+12 −1
Original line number Diff line number Diff line
@@ -182,8 +182,19 @@ public interface IContentProvider extends IInterface {
    public boolean refresh(@NonNull AttributionSource attributionSource, Uri url,
            @Nullable Bundle extras, ICancellationSignal cancellationSignal) throws RemoteException;

    /**
     * @deprecated -- use getStreamTypes with AttributionSource
     */
    @Deprecated
    default String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
        return getStreamTypes(new AttributionSource(Binder.getCallingUid(),
                AppGlobals.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0],
                null), url, mimeTypeFilter);
    }

    // Data interchange.
    public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException;
    String[] getStreamTypes(AttributionSource attributionSource,
            Uri url, String mimeTypeFilter) throws RemoteException;

    public AssetFileDescriptor openTypedAssetFile(@NonNull AttributionSource attributionSource,
            Uri url, String mimeType, Bundle opts, ICancellationSignal signal)
Loading