summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kelvin Kwan <kelvinkwan@google.com> 2020-03-27 17:52:01 +0000
committer Kelvin Kwan <kelvinkwan@google.com> 2020-03-30 11:28:20 +0100
commitafdd634944095adcc1bc407a3c6b483a9b5fc5f8 (patch)
treed5b4278bed60a8a767bdd63567ba12e9d9333d23
parentb7046c1f6f3fe59fb32a52a354d340f7851fa270 (diff)
Returns a correct cross profile uri for CREATE_DOCUMENT
This is a preparation to enable cross-profile intent handling for CREATE_DOCUMENT Bug: 149771504 Test: atest DocumentsUIGoogleTests Change-Id: Ibc60b5179d3f9a29544bed77cb323f59ae7326b0
-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: