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
|
@Override
|
||||||
public String getType(AttributionSource attributionSource, Uri uri) {
|
public String getType(AttributionSource attributionSource, Uri uri) {
|
||||||
// getCallingPackage() isn't available in getType(), as the javadoc states.
|
|
||||||
uri = validateIncomingUri(uri);
|
uri = validateIncomingUri(uri);
|
||||||
uri = maybeGetUriWithoutUserId(uri);
|
uri = maybeGetUriWithoutUserId(uri);
|
||||||
traceBegin(TRACE_TAG_DATABASE, "getType: ", uri.getAuthority());
|
traceBegin(TRACE_TAG_DATABASE, "getType: ", uri.getAuthority());
|
||||||
|
final AttributionSource original = setCallingAttributionSource(
|
||||||
|
attributionSource);
|
||||||
try {
|
try {
|
||||||
if (checkGetTypePermission(attributionSource, uri)
|
if (checkGetTypePermission(attributionSource, uri)
|
||||||
== PermissionChecker.PERMISSION_GRANTED) {
|
== PermissionChecker.PERMISSION_GRANTED) {
|
||||||
@@ -346,6 +347,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
|||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowAsRuntimeException();
|
throw e.rethrowAsRuntimeException();
|
||||||
} finally {
|
} finally {
|
||||||
|
setCallingAttributionSource(original);
|
||||||
Trace.traceEnd(TRACE_TAG_DATABASE);
|
Trace.traceEnd(TRACE_TAG_DATABASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,16 +407,20 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getTypeAnonymousAsync(Uri uri, RemoteCallback callback) {
|
public void getTypeAnonymousAsync(Uri uri, RemoteCallback callback) {
|
||||||
|
// getCallingPackage() isn't available in getTypeAnonymous(), as the javadoc states.
|
||||||
uri = validateIncomingUri(uri);
|
uri = validateIncomingUri(uri);
|
||||||
uri = maybeGetUriWithoutUserId(uri);
|
uri = maybeGetUriWithoutUserId(uri);
|
||||||
|
traceBegin(TRACE_TAG_DATABASE, "getTypeAnonymous: ", uri.getAuthority());
|
||||||
final Bundle result = new Bundle();
|
final Bundle result = new Bundle();
|
||||||
try {
|
try {
|
||||||
result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getTypeAnonymous(uri));
|
result.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getTypeAnonymous(uri));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
|
result.putParcelable(ContentResolver.REMOTE_CALLBACK_ERROR,
|
||||||
new ParcelableException(e));
|
new ParcelableException(e));
|
||||||
|
} finally {
|
||||||
|
callback.sendResult(result);
|
||||||
|
Trace.traceEnd(TRACE_TAG_DATABASE);
|
||||||
}
|
}
|
||||||
callback.sendResult(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -629,16 +635,19 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
|
public String[] getStreamTypes(AttributionSource attributionSource,
|
||||||
// getCallingPackage() isn't available in getType(), as the javadoc states.
|
Uri uri, String mimeTypeFilter) {
|
||||||
uri = validateIncomingUri(uri);
|
uri = validateIncomingUri(uri);
|
||||||
uri = maybeGetUriWithoutUserId(uri);
|
uri = maybeGetUriWithoutUserId(uri);
|
||||||
traceBegin(TRACE_TAG_DATABASE, "getStreamTypes: ", uri.getAuthority());
|
traceBegin(TRACE_TAG_DATABASE, "getStreamTypes: ", uri.getAuthority());
|
||||||
|
final AttributionSource original = setCallingAttributionSource(
|
||||||
|
attributionSource);
|
||||||
try {
|
try {
|
||||||
return mInterface.getStreamTypes(uri, mimeTypeFilter);
|
return mInterface.getStreamTypes(uri, mimeTypeFilter);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowAsRuntimeException();
|
throw e.rethrowAsRuntimeException();
|
||||||
} finally {
|
} finally {
|
||||||
|
setCallingAttributionSource(original);
|
||||||
Trace.traceEnd(TRACE_TAG_DATABASE);
|
Trace.traceEnd(TRACE_TAG_DATABASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1114,7 +1123,10 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
|||||||
* currently processing a request.
|
* currently processing a request.
|
||||||
* <p>
|
* <p>
|
||||||
* This will always return {@code null} when processing
|
* 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 Binder#getCallingUid()
|
||||||
* @see Context#grantUriPermission(String, Uri, int)
|
* @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.
|
* a request of the request is for the default attribution.
|
||||||
* <p>
|
* <p>
|
||||||
* This will always return {@code null} when processing
|
* 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
|
* @see #getCallingPackage
|
||||||
*/
|
*/
|
||||||
@@ -1181,7 +1196,10 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
|
|||||||
* {@code null} if not currently processing a request.
|
* {@code null} if not currently processing a request.
|
||||||
* <p>
|
* <p>
|
||||||
* This will always return {@code null} when processing
|
* 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 Binder#getCallingUid()
|
||||||
* @see Context#grantUriPermission(String, Uri, int)
|
* @see Context#grantUriPermission(String, Uri, int)
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ public class ContentProviderClient implements ContentInterface, AutoCloseable {
|
|||||||
|
|
||||||
beforeRemote();
|
beforeRemote();
|
||||||
try {
|
try {
|
||||||
return mContentProvider.getType(url);
|
return mContentProvider.getType(mAttributionSource, url);
|
||||||
} catch (DeadObjectException e) {
|
} catch (DeadObjectException e) {
|
||||||
if (!mStable) {
|
if (!mStable) {
|
||||||
mContentResolver.unstableProviderDied(mContentProvider);
|
mContentResolver.unstableProviderDied(mContentProvider);
|
||||||
@@ -237,7 +237,7 @@ public class ContentProviderClient implements ContentInterface, AutoCloseable {
|
|||||||
|
|
||||||
beforeRemote();
|
beforeRemote();
|
||||||
try {
|
try {
|
||||||
return mContentProvider.getStreamTypes(url, mimeTypeFilter);
|
return mContentProvider.getStreamTypes(mAttributionSource, url, mimeTypeFilter);
|
||||||
} catch (DeadObjectException e) {
|
} catch (DeadObjectException e) {
|
||||||
if (!mStable) {
|
if (!mStable) {
|
||||||
mContentResolver.unstableProviderDied(mContentProvider);
|
mContentResolver.unstableProviderDied(mContentProvider);
|
||||||
|
|||||||
@@ -315,9 +315,11 @@ abstract public class ContentProviderNative extends Binder implements IContentPr
|
|||||||
case GET_STREAM_TYPES_TRANSACTION:
|
case GET_STREAM_TYPES_TRANSACTION:
|
||||||
{
|
{
|
||||||
data.enforceInterface(IContentProvider.descriptor);
|
data.enforceInterface(IContentProvider.descriptor);
|
||||||
|
AttributionSource attributionSource = AttributionSource.CREATOR
|
||||||
|
.createFromParcel(data);
|
||||||
Uri url = Uri.CREATOR.createFromParcel(data);
|
Uri url = Uri.CREATOR.createFromParcel(data);
|
||||||
String mimeTypeFilter = data.readString();
|
String mimeTypeFilter = data.readString();
|
||||||
String[] types = getStreamTypes(url, mimeTypeFilter);
|
String[] types = getStreamTypes(attributionSource, url, mimeTypeFilter);
|
||||||
reply.writeNoException();
|
reply.writeNoException();
|
||||||
reply.writeStringArray(types);
|
reply.writeStringArray(types);
|
||||||
|
|
||||||
@@ -769,12 +771,14 @@ final class ContentProviderProxy implements IContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 data = Parcel.obtain();
|
||||||
Parcel reply = Parcel.obtain();
|
Parcel reply = Parcel.obtain();
|
||||||
try {
|
try {
|
||||||
data.writeInterfaceToken(IContentProvider.descriptor);
|
data.writeInterfaceToken(IContentProvider.descriptor);
|
||||||
|
attributionSource.writeToParcel(data, 0);
|
||||||
|
|
||||||
url.writeToParcel(data, 0);
|
url.writeToParcel(data, 0);
|
||||||
data.writeString(mimeTypeFilter);
|
data.writeString(mimeTypeFilter);
|
||||||
|
|||||||
@@ -1069,7 +1069,7 @@ public abstract class ContentResolver implements ContentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return provider.getStreamTypes(url, mimeTypeFilter);
|
return provider.getStreamTypes(mContext.getAttributionSource(), url, mimeTypeFilter);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// Arbitrary and not worth documenting, as Activity
|
// Arbitrary and not worth documenting, as Activity
|
||||||
// Manager will kill this process shortly anyway.
|
// Manager will kill this process shortly anyway.
|
||||||
|
|||||||
@@ -182,8 +182,19 @@ public interface IContentProvider extends IInterface {
|
|||||||
public boolean refresh(@NonNull AttributionSource attributionSource, Uri url,
|
public boolean refresh(@NonNull AttributionSource attributionSource, Uri url,
|
||||||
@Nullable Bundle extras, ICancellationSignal cancellationSignal) throws RemoteException;
|
@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.
|
// 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,
|
public AssetFileDescriptor openTypedAssetFile(@NonNull AttributionSource attributionSource,
|
||||||
Uri url, String mimeType, Bundle opts, ICancellationSignal signal)
|
Uri url, String mimeType, Bundle opts, ICancellationSignal signal)
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ public class MockContentProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return MockContentProvider.this.getStreamTypes(url, mimeTypeFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ public class MockIContentProvider implements IContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
throw new UnsupportedOperationException("unimplemented mock method");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user