Skip to content

Commit 9083018

Browse files
committed
Also trying to rewrite EXTRA_STREAM in copying shared data
1 parent 33dbba5 commit 9083018

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

app/src/main/java/org/thoughtcrime/securesms/ScreenLockActionBarActivity.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.os.Bundle
1010
import androidx.annotation.IdRes
1111
import androidx.core.content.ContextCompat
1212
import androidx.core.content.FileProvider
13+
import androidx.core.content.IntentCompat
1314
import androidx.fragment.app.Fragment
1415
import androidx.lifecycle.lifecycleScope
1516
import kotlinx.coroutines.Dispatchers
@@ -226,15 +227,17 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
226227

227228
// Clear original clipData
228229
rewrittenIntent.clipData = null
229-
230-
// If we couldn't find one then we have nothing to re-write and we'll just return the original intent
231-
if (!rewrittenIntent.hasExtra(Intent.EXTRA_STREAM)) {
232-
Log.i(TAG, "No stream to rewrite - returning original intent")
233-
return@withContext originalIntent
234-
}
230+
rewrittenIntent.removeExtra(Intent.EXTRA_STREAM)
235231

236232
// Grab and rewrite the original intent's clipData - adding it to our rewrittenIntent as we go
237233
val originalClipData = originalIntent.clipData
234+
?: IntentCompat.getParcelableExtra(originalIntent, Intent.EXTRA_STREAM, Uri::class.java)?.let { uri ->
235+
// If the original intent has a single Uri in the Intent.EXTRA_STREAM extra, we create a ClipData
236+
// with that Uri to mimic the original clipData structure.
237+
ClipData.newUri(contentResolver, "Shared data", uri)
238+
}
239+
240+
238241
originalClipData?.let { clipData ->
239242
var newClipData: ClipData? = null
240243
for (i in 0 until clipData.itemCount) {
@@ -267,10 +270,6 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
267270
Log.i(TAG, "Adding newClipData to rewrittenIntent.")
268271
rewrittenIntent.clipData = newClipData
269272
rewrittenIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
270-
} else {
271-
// If no newClipData was created, clear it to prevent referencing the old inaccessible URIs
272-
Log.i(TAG, "There was no newClipData - setting the clipData to null.")
273-
rewrittenIntent.clipData = null
274273
}
275274
}
276275

app/src/main/java/org/thoughtcrime/securesms/util/FilenameUtils.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ object FilenameUtils {
8484
@JvmStatic
8585
@JvmOverloads // Force creation of two versions of this method - one with and one without the mimeType param
8686
fun getFilenameFromUri(context: Context, uri: Uri?, mimeType: String? = null, attachment: Attachment? = null): String {
87-
Exception().printStackTrace()
88-
8987
var extractedFilename: String? = null
9088

9189
if (uri != null) {

0 commit comments

Comments
 (0)