Merge "Setting callingAttributionSource in getType and getStreamType" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9b39adf62e
@@ -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);
|
||||
}
|
||||
callback.sendResult(result);
|
||||
}
|
||||
|
||||
@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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -140,7 +140,8 @@ public class MockContentProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
|
||||
public String[] getStreamTypes(AttributionSource attributionSource,
|
||||
Uri url, String mimeTypeFilter) throws RemoteException {
|
||||
return MockContentProvider.this.getStreamTypes(url, mimeTypeFilter);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ public class MockIContentProvider implements IContentProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
|
||||
public String[] getStreamTypes(@NonNull AttributionSource attributionSource,
|
||||
Uri url, String mimeTypeFilter) throws RemoteException {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user