summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/documentsui/DocumentsAccess.java18
-rw-r--r--src/com/android/documentsui/picker/ActionHandler.java2
-rw-r--r--src/com/android/documentsui/picker/ConfirmFragment.java2
3 files changed, 18 insertions, 4 deletions
diff --git a/src/com/android/documentsui/DocumentsAccess.java b/src/com/android/documentsui/DocumentsAccess.java
index c10f9abef..e3b6abde3 100644
--- a/src/com/android/documentsui/DocumentsAccess.java
+++ b/src/com/android/documentsui/DocumentsAccess.java
@@ -153,13 +153,27 @@ public interface DocumentsAccess {
public Uri createDocument(DocumentInfo parentDoc, String mimeType, String displayName) {
final ContentResolver resolver = parentDoc.userId.getContentResolver(mContext);
try (ContentProviderClient client = DocumentsApplication.acquireUnstableProviderOrThrow(
- resolver, parentDoc.derivedUri.getAuthority())) {
- return DocumentsContract.createDocument(
+ resolver, parentDoc.derivedUri.getAuthority())) {
+ Uri createUri = DocumentsContract.createDocument(
wrap(client), parentDoc.derivedUri, mimeType, displayName);
+ // If the document info's user is the current user, we can simply return the uri.
+ // Otherwise, we need to create document with the content resolver from the other
+ // user. The uri returned from that content resolver does not contain the user
+ // info. Hence we need to append the other user info to the uri otherwise an app
+ // will think the uri is from the current user.
+ // The way to append a userInfo is to use the authority which contains user info
+ // obtained from the parentDoc.getDocumentUri().
+ return UserId.CURRENT_USER.equals(parentDoc.userId)
+ ? createUri : appendEncodedParentAuthority(parentDoc, createUri);
} catch (Exception e) {
Log.w(TAG, "Failed to create document", e);
return null;
}
}
+
+ private Uri appendEncodedParentAuthority(DocumentInfo parentDoc, Uri uri) {
+ return uri.buildUpon().encodedAuthority(
+ parentDoc.getDocumentUri().getAuthority()).build();
+ }
}
}
diff --git a/src/com/android/documentsui/picker/ActionHandler.java b/src/com/android/documentsui/picker/ActionHandler.java
index 871793a71..ab05bed21 100644
--- a/src/com/android/documentsui/picker/ActionHandler.java
+++ b/src/com/android/documentsui/picker/ActionHandler.java
@@ -419,7 +419,7 @@ class ActionHandler<T extends FragmentActivity & Addons> extends AbstractActionH
if (mFeatures.isOverwriteConfirmationEnabled()) {
mInjector.dialogs.confirmAction(fm, replaceTarget, ConfirmFragment.TYPE_OVERWRITE);
} else {
- finishPicking(replaceTarget.derivedUri);
+ finishPicking(replaceTarget.getDocumentUri());
}
}
diff --git a/src/com/android/documentsui/picker/ConfirmFragment.java b/src/com/android/documentsui/picker/ConfirmFragment.java
index bc89719cc..94015e930 100644
--- a/src/com/android/documentsui/picker/ConfirmFragment.java
+++ b/src/com/android/documentsui/picker/ConfirmFragment.java
@@ -76,7 +76,7 @@ public class ConfirmFragment extends DialogFragment {
android.R.string.ok,
(DialogInterface dialog, int id) -> {
pickResult.increaseActionCount();
- mActions.finishPicking(mTarget.derivedUri);
+ mActions.finishPicking(mTarget.getDocumentUri());
});
break;
case TYPE_OEPN_TREE: