summaryrefslogtreecommitdiff
path: root/java/src/com
diff options
context:
space:
mode:
author Miranda Kephart <mkephart@google.com> 2024-10-21 09:52:59 -0400
committer Miranda Kephart <mkephart@google.com> 2024-11-08 11:43:52 -0500
commit83b40ed1e7031f59f57f20fbaca6561404118df3 (patch)
treecefdbb3cd07d2502f4a45894ec78c2190aef162a /java/src/com
parente8ac318c3273346b1e97b529a91c075624cc4036 (diff)
Send content URI from sharesheet
Leaving out the content URIs means that the quick actions component is no longer able to match sharesheet actions with the screenshots that were taking, breaking screenshot quickshare functionality. Method used is the same as in the old version of the sharesheet. Bug: 340867497 Test: manual (verify that quick share option shows up in screenshots) Flag: EXEMPT (minor change, restoring previous functionality) Change-Id: Id0e6b0e02071aa8c6e0c969d3e5bd81bbc200552
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/intentresolver/ui/viewmodel/ChooserRequestReader.kt12
-rw-r--r--java/src/com/android/intentresolver/ui/viewmodel/IntentExt.kt58
2 files changed, 59 insertions, 11 deletions
diff --git a/java/src/com/android/intentresolver/ui/viewmodel/ChooserRequestReader.kt b/java/src/com/android/intentresolver/ui/viewmodel/ChooserRequestReader.kt
index 1644e409..13de84b2 100644
--- a/java/src/com/android/intentresolver/ui/viewmodel/ChooserRequestReader.kt
+++ b/java/src/com/android/intentresolver/ui/viewmodel/ChooserRequestReader.kt
@@ -36,7 +36,6 @@ import android.content.Intent.EXTRA_TEXT
import android.content.Intent.EXTRA_TITLE
import android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK
import android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT
-import android.content.IntentFilter
import android.content.IntentSender
import android.net.Uri
import android.os.Bundle
@@ -164,7 +163,7 @@ fun readChooserRequest(
refinementIntentSender = refinementIntentSender,
sharedText = sharedText,
sharedTextTitle = sharedTextTitle,
- shareTargetFilter = targetIntent.toShareTargetFilter(),
+ shareTargetFilter = targetIntent.createIntentFilter(),
additionalContentUri = additionalContentUri,
focusedItemPosition = focusedItemPos,
contentTypeHint = contentTypeHint,
@@ -180,12 +179,3 @@ fun Validation.readChooserActions(): List<ChooserAction>? =
optional(array<ChooserAction>(EXTRA_CHOOSER_CUSTOM_ACTIONS))
?.filter { hasValidIcon(it) }
?.take(MAX_CHOOSER_ACTIONS)
-
-private fun Intent.toShareTargetFilter(): IntentFilter? {
- return type?.let {
- IntentFilter().apply {
- action?.also { addAction(it) }
- addDataType(it)
- }
- }
-}
diff --git a/java/src/com/android/intentresolver/ui/viewmodel/IntentExt.kt b/java/src/com/android/intentresolver/ui/viewmodel/IntentExt.kt
new file mode 100644
index 00000000..30f16d20
--- /dev/null
+++ b/java/src/com/android/intentresolver/ui/viewmodel/IntentExt.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.intentresolver.ui.viewmodel
+
+import android.content.Intent
+import android.content.IntentFilter
+import android.content.IntentFilter.MalformedMimeTypeException
+import android.net.Uri
+import android.os.PatternMatcher
+
+/** Collects Uris from standard locations within the Intent. */
+fun Intent.collectUris(): Set<Uri> = buildSet {
+ data?.also { add(it) }
+ @Suppress("DEPRECATION")
+ when (val stream = extras?.get(Intent.EXTRA_STREAM)) {
+ is Uri -> add(stream)
+ is ArrayList<*> -> addAll(stream.mapNotNull { it as? Uri })
+ else -> Unit
+ }
+ clipData?.apply { (0..<itemCount).mapNotNull { getItemAt(it).uri }.forEach(::add) }
+}
+
+fun IntentFilter.addUri(uri: Uri) {
+ uri.scheme?.also { addDataScheme(it) }
+ uri.host?.also { addDataAuthority(it, null) }
+ uri.path?.also { addDataPath(it, PatternMatcher.PATTERN_LITERAL) }
+}
+
+fun Intent.createIntentFilter(): IntentFilter? {
+ val uris = collectUris()
+ if (action == null && uris.isEmpty()) {
+ // at least one is required to be meaningful
+ return null
+ }
+ return IntentFilter().also { filter ->
+ type?.also {
+ try {
+ filter.addDataType(it)
+ } catch (_: MalformedMimeTypeException) { // ignore malformed type
+ }
+ }
+ action?.also { filter.addAction(it) }
+ uris.forEach(filter::addUri)
+ }
+}